Skip to content

Commit 5191d61

Browse files
tmshortclaude
andcommitted
✨ Add Prometheus alerts tracking to memory profiling
Enhance memory profiling plugin to capture and analyze Prometheus alerts during e2e test execution: 1. Set E2E_SUMMARY_OUTPUT environment variable during test runs - Captures prometheus alerts, test failures, and other metrics - Saved to e2e-summary.json in the profile directory 2. Updated analyze-profiles.sh to extract and display alerts - Parses e2e-summary.json using jq (if available) - Shows alert names, severities, and descriptions - Includes test failures in the analysis report 3. Updated compare-profiles.sh to compare alerts between runs - Shows alert counts for both tests - Lists alerts detected in each test - Helps identify if optimizations introduced new alerts This allows correlating memory usage with system health metrics, making it easier to identify if memory optimizations have any negative side effects on system stability. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 9f1b033 commit 5191d61

File tree

3 files changed

+139
-1
lines changed

3 files changed

+139
-1
lines changed

hack/tools/memory-profiling/analyze-profiles.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,61 @@ EOF
208208
EOF
209209
fi
210210

211+
# Prometheus Alerts Analysis
212+
if [ -f "${OUTPUT_DIR}/e2e-summary.json" ]; then
213+
log_info "Analyzing Prometheus alerts..."
214+
cat >> "${REPORT_FILE}" << 'EOF'
215+
216+
## Prometheus Alerts
217+
218+
EOF
219+
220+
# Check if jq is available for JSON parsing
221+
if command -v jq >/dev/null 2>&1; then
222+
# Extract alerts from e2e-summary.json
223+
ALERTS=$(jq -r '.prometheusAlerts // [] | .[] | "- **\(.labels.alertname)** (Severity: \(.labels.severity // "unknown"))\n - \(.annotations.description // .annotations.message // "No description")"' "${OUTPUT_DIR}/e2e-summary.json" 2>/dev/null || echo "")
224+
225+
if [ -n "${ALERTS}" ]; then
226+
cat >> "${REPORT_FILE}" << EOF
227+
### Alerts Detected
228+
229+
${ALERTS}
230+
231+
EOF
232+
else
233+
cat >> "${REPORT_FILE}" << 'EOF'
234+
No Prometheus alerts detected during test execution.
235+
236+
EOF
237+
fi
238+
239+
# Extract test failures if any
240+
TEST_FAILURES=$(jq -r '.testFailures // [] | .[] | "- \(.test): \(.message)"' "${OUTPUT_DIR}/e2e-summary.json" 2>/dev/null || echo "")
241+
242+
if [ -n "${TEST_FAILURES}" ]; then
243+
cat >> "${REPORT_FILE}" << EOF
244+
### Test Failures
245+
246+
${TEST_FAILURES}
247+
248+
EOF
249+
fi
250+
else
251+
cat >> "${REPORT_FILE}" << 'EOF'
252+
E2E summary available at `e2e-summary.json` (install `jq` for detailed alert parsing)
253+
254+
EOF
255+
fi
256+
else
257+
cat >> "${REPORT_FILE}" << 'EOF'
258+
259+
## Prometheus Alerts
260+
261+
E2E summary not available. Set `E2E_SUMMARY_OUTPUT` environment variable when running tests to capture alerts.
262+
263+
EOF
264+
fi
265+
211266
# Recommendations
212267
cat >> "${REPORT_FILE}" << 'EOF'
213268

hack/tools/memory-profiling/compare-profiles.sh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,88 @@ cat >> "${REPORT_FILE}" << 'EOF'
281281
282282
---
283283
284+
## Prometheus Alerts Comparison
285+
286+
EOF
287+
288+
# Compare prometheus alerts if available
289+
if [ -f "${TEST1_DIR}/e2e-summary.json" ] || [ -f "${TEST2_DIR}/e2e-summary.json" ]; then
290+
if command -v jq >/dev/null 2>&1; then
291+
# Test 1 alerts
292+
if [ -f "${TEST1_DIR}/e2e-summary.json" ]; then
293+
ALERTS1=$(jq -r '.prometheusAlerts // [] | length' "${TEST1_DIR}/e2e-summary.json" 2>/dev/null || echo "0")
294+
ALERTS1_NAMES=$(jq -r '.prometheusAlerts // [] | .[].labels.alertname' "${TEST1_DIR}/e2e-summary.json" 2>/dev/null | sort | uniq || echo "")
295+
else
296+
ALERTS1="N/A"
297+
ALERTS1_NAMES=""
298+
fi
299+
300+
# Test 2 alerts
301+
if [ -f "${TEST2_DIR}/e2e-summary.json" ]; then
302+
ALERTS2=$(jq -r '.prometheusAlerts // [] | length' "${TEST2_DIR}/e2e-summary.json" 2>/dev/null || echo "0")
303+
ALERTS2_NAMES=$(jq -r '.prometheusAlerts // [] | .[].labels.alertname' "${TEST2_DIR}/e2e-summary.json" 2>/dev/null | sort | uniq || echo "")
304+
else
305+
ALERTS2="N/A"
306+
ALERTS2_NAMES=""
307+
fi
308+
309+
cat >> "${REPORT_FILE}" << EOF
310+
### Alert Summary
311+
312+
| Metric | ${TEST1} | ${TEST2} |
313+
|--------|----------|----------|
314+
| Alert Count | ${ALERTS1} | ${ALERTS2} |
315+
316+
EOF
317+
318+
if [ -n "${ALERTS1_NAMES}" ] || [ -n "${ALERTS2_NAMES}" ]; then
319+
cat >> "${REPORT_FILE}" << 'EOF'
320+
### Alerts by Test
321+
322+
EOF
323+
324+
if [ -n "${ALERTS1_NAMES}" ]; then
325+
cat >> "${REPORT_FILE}" << EOF
326+
**${TEST1}:**
327+
EOF
328+
echo "${ALERTS1_NAMES}" | while read -r alert; do
329+
[ -n "${alert}" ] && echo "- ${alert}" >> "${REPORT_FILE}"
330+
done
331+
echo "" >> "${REPORT_FILE}"
332+
fi
333+
334+
if [ -n "${ALERTS2_NAMES}" ]; then
335+
cat >> "${REPORT_FILE}" << EOF
336+
**${TEST2}:**
337+
EOF
338+
echo "${ALERTS2_NAMES}" | while read -r alert; do
339+
[ -n "${alert}" ] && echo "- ${alert}" >> "${REPORT_FILE}"
340+
done
341+
echo "" >> "${REPORT_FILE}"
342+
fi
343+
else
344+
cat >> "${REPORT_FILE}" << 'EOF'
345+
No alerts detected in either test.
346+
347+
EOF
348+
fi
349+
else
350+
cat >> "${REPORT_FILE}" << 'EOF'
351+
E2E summaries available but `jq` not installed for parsing.
352+
353+
EOF
354+
fi
355+
else
356+
cat >> "${REPORT_FILE}" << 'EOF'
357+
E2E summary not available for comparison.
358+
359+
EOF
360+
fi
361+
362+
cat >> "${REPORT_FILE}" << 'EOF'
363+
364+
---
365+
284366
## Key Findings
285367
286368
**Memory Impact:**

hack/tools/memory-profiling/run-profiled-test.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ log_info "Output directory: ${OUTPUT_DIR}"
8282

8383
# Start the e2e test
8484
log_info "Starting e2e test (${TEST_TARGET})..."
85-
make "${TEST_TARGET}" > "${OUTPUT_DIR}/test.log" 2>&1 &
85+
# Set E2E_SUMMARY_OUTPUT to capture prometheus alerts and other test metrics
86+
E2E_SUMMARY_OUTPUT="${OUTPUT_DIR}/e2e-summary.json" make "${TEST_TARGET}" > "${OUTPUT_DIR}/test.log" 2>&1 &
8687
TEST_PID=$!
8788
log_info "Test started (PID: ${TEST_PID})"
8889

0 commit comments

Comments
 (0)