Skip to content

CORE-529: add workflow for Ruby community agent releases #13

CORE-529: add workflow for Ruby community agent releases

CORE-529: add workflow for Ruby community agent releases #13

Workflow file for this run

name: OpenTelemetry Ruby Agent Tests
on: pull_request
env:
OTEL_COLLECTOR_GRPC_PORT: 4317
OTEL_COLLECTOR_HTTP_PORT: 4318
jobs:
e2e-tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- ruby-version: '3.1'
rails-version: '7.1'
- ruby-version: '3.2'
rails-version: '7.1'
- ruby-version: '3.3'
rails-version: '7.1'
- ruby-version: '3.4'
rails-version: '7.1'
env:
ARCHITECTURE: 'amd64' # having trouble getting a runner with arm64, so no matrix for 'arch' at the moment
SERVICE_NAME: 'rails-app-${{ matrix.ruby-version }}'
SERVICE_TEST_ROUTE: 'test'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Ruby ${{ matrix.ruby-version }}
uses: ruby/setup-ruby@v1
with:
ruby-version: '${{ matrix.ruby-version }}'
bundler-cache: true
- name: Setup Docker
run: |
sudo systemctl start docker
sudo systemctl status docker || (echo "⚠️ Docker is not running" && exit 1)
- name: Setup OpenTelemetry Collector
run: |
cat > collector-config.yaml << 'EOF'
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318
processors:
batch:
exporters:
debug:
verbosity: detailed
service:
pipelines:
traces:
receivers: [otlp]
processors: [batch]
exporters: [debug]
EOF
- name: Start OpenTelemetry Collector
run: |
docker run -d \
--name otel-collector \
-p 4317:4317 \
-p 4318:4318 \
-v $(pwd)/collector-config.yaml:/etc/otelcol/config.yaml \
otel/opentelemetry-collector:latest \
--config /etc/otelcol/config.yaml
- name: Verify OpenTelemetry Collector is running
run: |
echo "Checking if collector is running..."
for i in {1..30}; do
if docker ps | grep -q otel-collector && netstat -tlnp 2>/dev/null | grep -q ":4317\|:4318"; then
echo "✅ Collector is running"
break
fi
if [ "$i" = 30 ]; then
echo "❌ Collector is not running after 30 attempts"
exit 1
fi
echo "Attempt $i/30: Waiting for collector..."
sleep 2
done
- name: Verify OpenTelemetry Collector is ready
run: |
echo "Checking collector logs for readiness..."
for i in {1..30}; do
COLLECTOR_LOGS=$(docker logs otel-collector 2>&1 || (echo "⚠️ Docker logs failed" && exit 1))
if echo "$COLLECTOR_LOGS" | grep -q "Starting GRPC server" && \
echo "$COLLECTOR_LOGS" | grep -q "Starting HTTP server" && \
echo "$COLLECTOR_LOGS" | grep -q "Everything is ready"; then
echo "✅ Collector is ready"
break
fi
if [ "$i" = 30 ]; then
echo "❌ Collector is not ready after 30 attempts"
exit 1
fi
echo "Attempt $i/30: Waiting for readiness..."
sleep 2
done
- name: Create Application
run: |
# Create new Rails app
gem install rails -v ${{ matrix.rails-version }}
rails new ${{ env.SERVICE_NAME }} --skip-git --skip-test --skip-system-test --skip-javascript
cd ${{ env.SERVICE_NAME }}
# Add a simple controller for testing
rails generate controller Test index
# Update the route
sed -i 's|# Defines the root path route ("/")|get "/${{ env.SERVICE_TEST_ROUTE }}", to: "${{ env.SERVICE_TEST_ROUTE }}#index"|' config/routes.rb
# Update the controller
cat > app/controllers/test_controller.rb << 'EOF'
class TestController < ApplicationController
def index
render json: {
message: "Hello from Ruby ${{ matrix.ruby-version }}!",
timestamp: Time.current.to_i
}
end
end
EOF
# Install dependencies
bundle install
- name: Configure Agent
run: |
# Move architecture files
mv ${{ matrix.ruby-version }}/${{ env.ARCHITECTURE }}/* ${{ matrix.ruby-version }}/
cp Gemfile ${{ matrix.ruby-version }}/Gemfile
cp index.rb ${{ matrix.ruby-version }}/index.rb
rm -rf ${{ matrix.ruby-version }}/amd64
rm -rf ${{ matrix.ruby-version }}/arm64
# Set environment variables
echo "RUBYOPT=-r$(pwd)/${{ matrix.ruby-version }}/index.rb" >> $GITHUB_ENV
echo "ODIGOS_GEM_PATH=$(pwd)/${{ matrix.ruby-version }}/bundle" >> $GITHUB_ENV
echo "OTEL_SERVICE_NAME=${{ env.SERVICE_NAME }}" >> $GITHUB_ENV
echo "OTEL_TRACES_EXPORTER=otlp" >> $GITHUB_ENV
echo "OTEL_METRICS_EXPORTER=none" >> $GITHUB_ENV
echo "OTEL_LOGS_EXPORTER=none" >> $GITHUB_ENV
echo "OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:${{ env.OTEL_COLLECTOR_HTTP_PORT }}" >> $GITHUB_ENV
echo "OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf" >> $GITHUB_ENV
- name: Start Application
run: |
cd ${{ env.SERVICE_NAME }}
rails server -p 8000 -e development &
RAILS_PID=$!
echo $RAILS_PID > rails.pid
echo "🔍 Config/routes.rb:"
cat config/routes.rb
echo "🔍 App/controllers/test_controller.rb:"
cat app/controllers/test_controller.rb
echo "🔍 Available routes for the Rails application:"
rails routes
echo ""
echo "📋 Route details:"
rails routes --format expanded
- name: Generate Traffic
run: |
cd ${{ env.SERVICE_NAME }}
echo "Generating traffic..."
for i in {1..30}; do
if curl -f http://localhost:8000/${{ env.SERVICE_TEST_ROUTE }} > /dev/null 2>&1; then
echo "✅ Server is ready, traffic generated"
break
fi
if [ "$i" = 30 ]; then
echo "❌ Server is not ready after 30 attempts"
exit 1
fi
echo "Attempt $i/30: Server not ready yet..."
sleep 2
done
# Wait a bit for trace processing
sleep 5
- name: Verify Trace Generation
run: |
echo "Verifying trace generation..."
COLLECTOR_LOGS=$(docker logs otel-collector 2>&1 || (echo "⚠️ Docker logs failed" && exit 1))
SPAN_ATTRIBUTE="service.name: Str(${{ env.SERVICE_NAME }})"
if echo "$COLLECTOR_LOGS" | grep -q "$SPAN_ATTRIBUTE"; then
echo "✅ Traces detected in collector logs"
echo "$COLLECTOR_LOGS" | grep -i "$SPAN_ATTRIBUTE"
else
echo "❌ No traces found in collector logs"
echo "Collector logs:"
echo "$COLLECTOR_LOGS"
exit 1
fi