-
Notifications
You must be signed in to change notification settings - Fork 0
213 lines (187 loc) · 7.18 KB
/
tests.yaml
File metadata and controls
213 lines (187 loc) · 7.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
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