Skip to content

Commit 0c1b5b0

Browse files
committed
chore: add ci metrics to working test-datadog
1 parent 916a36e commit 0c1b5b0

File tree

1 file changed

+102
-1
lines changed

1 file changed

+102
-1
lines changed

.github/workflows/test-datadog.yml

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
if [ -n "${{ secrets.DATADOG_API_KEY }}" ]; then
2828
echo "✅ API Key is set, proceeding with test..."
2929
30-
# Prepare the JSON payload (v2 API format)
30+
# Prepare the JSON payload (v2 API format) - Testing CI metrics
3131
json_payload="{
3232
\"series\": [{
3333
\"metric\": \"test.datadog.integration\",
@@ -37,6 +37,14 @@ jobs:
3737
\"metric\": \"test.datadog.simple\",
3838
\"points\": [{\"timestamp\": $(date +%s), \"value\": 100}],
3939
\"tags\": [\"service:lace-wallet\", \"env:test\", \"workflow:test-datadog\"]
40+
}, {
41+
\"metric\": \"github.ci.pipeline.duration\",
42+
\"points\": [{\"timestamp\": $(date +%s), \"value\": 120}],
43+
\"tags\": [\"service:lace-wallet\", \"env:test\", \"workflow:test-datadog\", \"job:test-datadog\"]
44+
}, {
45+
\"metric\": \"github.ci.pipeline.status\",
46+
\"points\": [{\"timestamp\": $(date +%s), \"value\": 1}],
47+
\"tags\": [\"service:lace-wallet\", \"env:test\", \"workflow:test-datadog\", \"status:success\"]
4048
}]
4149
}"
4250
@@ -86,12 +94,105 @@ jobs:
8694
echo " 4. Ensure you're looking at us5.datadoghq.com"
8795
fi
8896
97+
# Test CI Events functionality
98+
echo ""
99+
echo "📝 Testing CI Events..."
100+
event_payload="{
101+
\"title\": \"Test Datadog CI Event: ${{ github.workflow }}\",
102+
\"text\": \"Test workflow ${{ github.workflow }} completed successfully\\nRepository: ${{ github.repository }}\\nBranch: ${{ github.ref_name }}\\nCommit: ${{ github.sha }}\",
103+
\"tags\": [\"service:lace-wallet\", \"env:test\", \"workflow:test-datadog\", \"status:success\", \"repo:${{ github.repository }}\"],
104+
\"alert_type\": \"info\",
105+
\"source_type_name\": \"github\"
106+
}"
107+
108+
echo "📤 Sending CI event payload:"
109+
echo "$event_payload"
110+
echo ""
111+
echo "🔍 JSON validation for event:"
112+
echo "$event_payload" | jq '.' 2>/dev/null && echo "✅ Event JSON is valid" || echo "❌ Event JSON is invalid"
113+
echo ""
114+
115+
event_response=$(curl -s -w "\nHTTP_STATUS_CODE:%{http_code}\nTOTAL_TIME:%{time_total}s\n" \
116+
-X POST "https://api.us5.datadoghq.com/api/v1/events" \
117+
-H "Content-Type: application/json" \
118+
-H "DD-API-KEY: ${{ secrets.DATADOG_API_KEY }}" \
119+
-d "$event_payload")
120+
121+
echo "📥 Raw event response:"
122+
echo "$event_response"
123+
echo ""
124+
125+
event_http_code=$(echo "$event_response" | grep "HTTP_STATUS_CODE:" | cut -d: -f2)
126+
event_total_time=$(echo "$event_response" | grep "TOTAL_TIME:" | cut -d: -f2)
127+
event_response_body=$(echo "$event_response" | sed '/HTTP_STATUS_CODE:/d' | sed '/TOTAL_TIME:/d')
128+
129+
echo "📊 Event Response Analysis:"
130+
echo " HTTP Status Code: $event_http_code"
131+
echo " Response Time: ${event_total_time}s"
132+
echo " Response Body: $event_response_body"
133+
echo ""
134+
135+
if [ "$event_http_code" = "202" ]; then
136+
echo "✅ SUCCESS: CI Event sent successfully to Datadog!"
137+
echo " Status: $event_http_code"
138+
echo " Time: ${event_total_time}s"
139+
else
140+
echo "❌ ERROR: Failed to send CI Event to Datadog"
141+
echo " Status: $event_http_code"
142+
echo " Error: $event_response_body"
143+
echo ""
144+
echo "🔍 Event troubleshooting tips:"
145+
echo " 1. Check if API key has 'Events Write' permission"
146+
echo " 2. Verify the event payload format"
147+
echo " 3. Check Datadog v1 events API documentation"
148+
echo " 4. Ensure you're using the correct endpoint"
149+
fi
150+
151+
# Try alternative event format if first one failed
152+
if [ "$event_http_code" != "202" ]; then
153+
echo ""
154+
echo "🔄 Trying alternative event format..."
155+
simple_event_payload="{
156+
\"title\": \"Test CI Event\",
157+
\"text\": \"Simple test event from GitHub Actions\",
158+
\"tags\": [\"service:lace-wallet\", \"env:test\"],
159+
\"alert_type\": \"info\"
160+
}"
161+
162+
echo "📤 Sending simple event payload:"
163+
echo "$simple_event_payload"
164+
echo ""
165+
166+
simple_event_response=$(curl -s -w "\nHTTP_STATUS_CODE:%{http_code}\nTOTAL_TIME:%{time_total}s\n" \
167+
-X POST "https://api.us5.datadoghq.com/api/v1/events" \
168+
-H "Content-Type: application/json" \
169+
-H "DD-API-KEY: ${{ secrets.DATADOG_API_KEY }}" \
170+
-d "$simple_event_payload")
171+
172+
simple_event_http_code=$(echo "$simple_event_response" | grep "HTTP_STATUS_CODE:" | cut -d: -f2)
173+
simple_event_response_body=$(echo "$simple_event_response" | sed '/HTTP_STATUS_CODE:/d' | sed '/TOTAL_TIME:/d')
174+
175+
if [ "$simple_event_http_code" = "202" ]; then
176+
echo "✅ SUCCESS: Simple CI Event sent successfully to Datadog!"
177+
else
178+
echo "❌ ERROR: Simple CI Event also failed"
179+
echo " Status: $simple_event_http_code"
180+
echo " Error: $simple_event_response_body"
181+
fi
182+
fi
183+
89184
echo ""
90185
echo "🔍 To verify in Datadog UI:"
91186
echo " 1. Go to Metrics Explorer"
92187
echo " 2. Search for: test.datadog.integration"
93188
echo " 3. Set time range to 'Last 1 hour'"
94189
echo " 4. Look for metrics with tags: service:lace-wallet, env:test"
190+
echo ""
191+
echo "📊 Also check for CI metrics:"
192+
echo " 5. Search for: github.ci.pipeline.duration"
193+
echo " 6. Search for: github.ci.pipeline.status"
194+
echo " 7. Check Events tab for CI events"
195+
echo " 8. Look for event titled: 'Test Datadog CI Event: test-datadog'"
95196
96197
else
97198
echo "❌ ERROR: DATADOG_API_KEY secret is not set"

0 commit comments

Comments
 (0)