Skip to content

Commit 44ae7a3

Browse files
authored
Merge branch 'main' into add-config-files
2 parents d23d194 + 8f14485 commit 44ae7a3

5 files changed

Lines changed: 241 additions & 9 deletions

File tree

.github/workflows/example-workflow-01.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ name: Example Workflow 01
22

33
on:
44
push:
5-
branches:
6-
- main
7-
- getting-started
85

96
jobs:
107
example-app:

.github/workflows/example-workflow-02.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ name: Example Workflow 02
22

33
on:
44
push:
5-
branches:
6-
- main
7-
- getting-started
85

96
jobs:
107
example-app:

.github/workflows/example-workflow-03.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ name: Example Workflow 03
22

33
on:
44
push:
5-
branches:
6-
- main
7-
- getting-started
85

96
jobs:
107
example-app:
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
name: Validate Action Output
2+
# Reusable workflow for testing the GitHub Action with OpenTelemetry collector validation
3+
# This workflow can be used to test different trigger events (push, workflow_run, etc.)
4+
#
5+
# To update test data for any workflow using this reusable workflow:
6+
# 1. Run the calling workflow (by pushing changes, creating PR, or triggering workflow_run)
7+
# 2. After workflow completion, download the artifact from the GitHub Actions run page
8+
# 3. Extract the artifact and copy traces.json and metrics.json to the appropriate .github/test-data/ directory
9+
# 4. Commit and push the updated test data files
10+
11+
on:
12+
workflow_call:
13+
inputs:
14+
test-data-directory:
15+
description:
16+
'Directory name under .github/test-data/ for expected test data'
17+
required: true
18+
type: string
19+
artifact-name:
20+
description: 'Name for the collector logs artifact'
21+
required: false
22+
type: string
23+
default: 'collector-logs'
24+
retention-days:
25+
description: 'Number of days to retain the artifact'
26+
required: false
27+
type: number
28+
default: 5
29+
30+
jobs:
31+
test-action:
32+
name: GitHub Actions Test
33+
runs-on: ubuntu-latest
34+
35+
steps:
36+
- name: Checkout
37+
id: checkout
38+
uses: actions/checkout@v4
39+
40+
# Create directory with proper permissions
41+
- name: Create log directory with proper permissions
42+
run: |
43+
mkdir -p collector-logs
44+
chmod 777 collector-logs
45+
46+
# Start OpenTelemetry Collector manually after checkout
47+
- name: Start OpenTelemetry Collector
48+
# port 13133 is used for health checks, 4318 for OTLP HTTP endpoint
49+
run: |
50+
echo "Starting OpenTelemetry Collector with custom configuration..."
51+
docker run -d \
52+
--name otel-collector \
53+
-p 13133:13133 \
54+
-p 4318:4318 \
55+
-v ${{ github.workspace }}/.github/configs/otel-collector-config.yaml:/etc/otelcol-contrib/config.yaml:ro \
56+
-v ${{ github.workspace }}/collector-logs:/collector-logs \
57+
--health-cmd "wget --no-verbose --tries=1 --spider http://localhost:13133/ || exit 1" \
58+
--health-interval 10s \
59+
--health-timeout 5s \
60+
--health-retries 3 \
61+
otel/opentelemetry-collector-contrib:0.115.1
62+
63+
# Wait for collector to be healthy and ready
64+
- name: Wait for collector to be ready
65+
run: |
66+
echo "Waiting for OpenTelemetry Collector to be ready..."
67+
timeout 60s bash -c 'until docker ps | grep -q "healthy.*otel-collector"; do sleep 2; echo "Waiting for collector health check..."; done'
68+
echo "Collector is ready"
69+
70+
# Define JQ filters for normalization (setting dynamic fields to fixed values)
71+
- name: Set JQ filters for normalization
72+
id: set-jq-filters
73+
run: |
74+
# JQ filter for trace normalization
75+
cat > /tmp/normalize-traces.jq << 'EOF'
76+
.resourceSpans[]?.scopeSpans[]?.spans[]? |= (
77+
.traceId = "00000000000000000000000000000000" |
78+
.spanId = "0000000000000000" |
79+
.parentSpanId = "0000000000000000" |
80+
.startTimeUnixNano = "0000000000000000000" |
81+
.endTimeUnixNano = "0000000000000000000"
82+
) |
83+
.resourceSpans[]?.scopeSpans[]?.spans[]?.attributes[]? |= (
84+
if .key == "run_id" then .value = {"intValue": "0"}
85+
elif .key == "job.id" then .value = {"intValue": "0"}
86+
elif .key == "url" then .value = {"stringValue": "https://example.com/actions/runs/0"}
87+
elif .key == "runner.name" then .value = {"stringValue": "GitHub Actions 0"}
88+
else .
89+
end
90+
)
91+
EOF
92+
93+
# JQ filter for metrics normalization
94+
cat > /tmp/normalize-metrics.jq << 'EOF'
95+
.resourceMetrics[]?.scopeMetrics[]?.metrics[]?.gauge?.dataPoints[]? |= (
96+
.startTimeUnixNano = "0000000000000000000" |
97+
.timeUnixNano = "0000000000000000000" |
98+
.asDouble = 0
99+
)
100+
EOF
101+
102+
# Execute the GitHub Action which sends telemetry data to the collector
103+
- name: Test Local Action
104+
id: test-action
105+
uses: ./
106+
env:
107+
OTEL_SERVICE_NAME: github-actions-opentelemetry
108+
# Point to local collector service (not external endpoint)
109+
OTEL_EXPORTER_OTLP_ENDPOINT: http://localhost:4318
110+
with:
111+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
112+
113+
# Upload collector logs as GitHub artifact for debugging
114+
- name: Upload collector logs as artifact
115+
if: always()
116+
uses: actions/upload-artifact@v4
117+
with:
118+
name: ${{ inputs.artifact-name }}
119+
path: collector-logs/
120+
retention-days: ${{ inputs.retention-days }}
121+
122+
# Validate that collector generated the expected JSON log files with correct content
123+
- name: Validate collector logs (Traces)
124+
run: |
125+
echo "=== Validating traces data ==="
126+
if [ -f "collector-logs/traces.json" ]; then
127+
echo "✓ Traces file found"
128+
echo "Traces content preview (first 5 lines):"
129+
head -5 collector-logs/traces.json
130+
131+
# Check if traces file has content
132+
if [ -s "collector-logs/traces.json" ]; then
133+
echo "✓ Traces data received"
134+
135+
# Validate traces structure matches expected format by comparing with test data
136+
echo "=== Validating trace structure ==="
137+
if [ -f ".github/test-data/${{ inputs.test-data-directory }}/traces.json" ]; then
138+
# Apply jq transformation to remove dynamic fields from collected traces
139+
jq -f /tmp/normalize-traces.jq collector-logs/traces.json > collector-logs/traces-normalized.json
140+
141+
# Apply same transformation to expected test data
142+
jq -f /tmp/normalize-traces.jq .github/test-data/${{ inputs.test-data-directory }}/traces.json > collector-logs/traces-expected.json
143+
144+
# Compare normalized traces
145+
if diff collector-logs/traces-normalized.json collector-logs/traces-expected.json > /dev/null; then
146+
echo "✓ Trace structure matches expected format"
147+
else
148+
echo "✗ Trace structure differs from expected format"
149+
echo "=== Differences ==="
150+
diff collector-logs/traces-normalized.json collector-logs/traces-expected.json || true
151+
exit 1
152+
fi
153+
else
154+
echo "⚠ Test data file not found, skipping structure validation"
155+
fi
156+
else
157+
echo "⚠ Traces file is empty"
158+
fi
159+
else
160+
echo "⚠ Traces file not found (no trace data received)"
161+
fi
162+
163+
- name: Validate collector logs (Metrics)
164+
run: |
165+
echo "=== Validating metrics data ==="
166+
if [ -f "collector-logs/metrics.json" ]; then
167+
echo "✓ Metrics file found"
168+
echo "Metrics content preview (first 5 lines):"
169+
head -5 collector-logs/metrics.json
170+
171+
# Check if metrics file has content
172+
if [ -s "collector-logs/metrics.json" ]; then
173+
echo "✓ Metrics data received"
174+
175+
# Validate metrics structure matches expected format by comparing with test data
176+
echo "=== Validating metrics structure ==="
177+
if [ -f ".github/test-data/${{ inputs.test-data-directory }}/metrics.json" ]; then
178+
# Apply jq transformation to remove dynamic fields from collected metrics
179+
jq -f /tmp/normalize-metrics.jq collector-logs/metrics.json > collector-logs/metrics-normalized.json
180+
181+
# Apply same transformation to expected test data
182+
jq -f /tmp/normalize-metrics.jq .github/test-data/${{ inputs.test-data-directory }}/metrics.json > collector-logs/metrics-expected.json
183+
184+
# Compare normalized metrics
185+
if diff collector-logs/metrics-normalized.json collector-logs/metrics-expected.json > /dev/null; then
186+
echo "✓ Metrics structure matches expected format"
187+
else
188+
echo "✗ Metrics structure differs from expected format"
189+
echo "=== Differences ==="
190+
diff collector-logs/metrics-normalized.json collector-logs/metrics-expected.json || true
191+
exit 1
192+
fi
193+
else
194+
echo "⚠ Test data file not found, skipping structure validation"
195+
fi
196+
else
197+
echo "⚠ Metrics file is empty"
198+
fi
199+
else
200+
echo "⚠ Metrics file not found (no metrics data received)"
201+
fi
202+
203+
# Show final collector status and logs for debugging
204+
- name: Show collector debug info
205+
if: always()
206+
run: |
207+
echo "=== Final collector status ==="
208+
docker ps -a | grep otel-collector || echo "Collector container not found"
209+
210+
echo "=== Complete collector logs ==="
211+
docker logs otel-collector || echo "Could not retrieve collector logs"
212+
213+
echo "=== All generated files ==="
214+
find collector-logs -type f -exec echo "File: {}" \; -exec head -10 {} \; -exec echo "---" \; 2>/dev/null || echo "No files found"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Workflow Run Tests
2+
# This workflow tests the GitHub Action when triggered by workflow_run events
3+
# It validates that the action works correctly when processing completed workflows
4+
5+
on:
6+
workflow_run:
7+
workflows:
8+
- Example Workflow 01
9+
- Example Workflow 02
10+
- Example Workflow 03
11+
types:
12+
- completed
13+
14+
permissions:
15+
contents: read
16+
actions: read
17+
18+
jobs:
19+
# Test the action for workflow_run events using the reusable workflow
20+
test-action-workflow-run:
21+
name: Test Action (Workflow Run Events)
22+
uses: ./.github/workflows/validate-action-output.yml
23+
with:
24+
test-data-directory: workflow-run-tests
25+
artifact-name: collector-logs-workflow-run
26+
retention-days: 5
27+
secrets: inherit

0 commit comments

Comments
 (0)