Skip to content

Commit 5760230

Browse files
committed
chore: test pushing gha-results to grafana
1 parent 07ac410 commit 5760230

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: fake-e2e-metrics-demo
2+
3+
on:
4+
push:
5+
branches: [gha_grafana_metrics]
6+
workflow_dispatch:
7+
8+
jobs:
9+
run-and-push:
10+
runs-on: ubuntu-latest
11+
env:
12+
PUSH_URL: ${{ secrets.GRAFANA_PUSH_URL }} # e.g., https://prometheus-us-central1.grafana.net/api/prom/push
13+
PUSH_USER: ${{ secrets.GRAFANA_USERNAME }} # e.g., 767754
14+
PUSH_PASS: ${{ secrets.GRAFANA_PASSWORD }} # e.g., eyJrIjoxxxxxxxxxxxxxxyMX0=
15+
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
20+
- name: Simulate e2e run & emit JSON metrics
21+
id: fake
22+
run: |
23+
cat >cpu.json <<EOF
24+
{
25+
"total": $((RANDOM % 200 + 800)),
26+
"user": $((RANDOM % 600 + 400)),
27+
"system": $((RANDOM % 200 + 100)),
28+
"rss_mb": $((RANDOM % 200 + 300))
29+
}
30+
EOF
31+
cat cpu.json
32+
33+
- name: Convert to Prometheus text
34+
run: |
35+
jq -r '
36+
"# TYPE e2e_cpu_seconds_total gauge\n" +
37+
"e2e_cpu_seconds_total{job=\"github-fake-e2e\",instance=\"${{ github.run_id }}\"} " + (.total |tostring) + "\n" +
38+
"# TYPE e2e_cpu_seconds_user gauge\n" +
39+
"e2e_cpu_seconds_user{job=\"github-fake-e2e\",instance=\"${{ github.run_id }}\"} " + (.user |tostring) + "\n" +
40+
"# TYPE e2e_cpu_seconds_sys gauge\n" +
41+
"e2e_cpu_seconds_sys{job=\"github-fake-e2e\",instance=\"${{ github.run_id }}\"} " + (.system|tostring) + "\n" +
42+
"# TYPE e2e_memory_rss_bytes gauge\n" +
43+
"e2e_memory_rss_bytes{job=\"github-fake-e2e\",instance=\"${{ github.run_id }}\"} " + ((.rss_mb*1024*1024)|tostring)
44+
' cpu.json > metrics.txt
45+
cat metrics.txt
46+
47+
- name: Create Prometheus config
48+
run: |
49+
cat >prometheus.yml <<EOF
50+
global:
51+
scrape_interval: 15s
52+
scrape_configs:
53+
- job_name: 'fake-e2e-metrics'
54+
static_configs:
55+
- targets: ['http-server:8000']
56+
metrics_path: '/metrics.txt'
57+
remote_write:
58+
- url: "$PUSH_URL"
59+
basic_auth:
60+
username: "$PUSH_USER"
61+
password: "$PUSH_PASS"
62+
EOF
63+
cat prometheus.yml
64+
65+
- name: Start Python HTTP server
66+
run: |
67+
docker run -d --name http-server -v $(pwd):/app -w /app -p 8000:8000 python:3.11-slim python -m http.server 8000 > http.log 2>&1
68+
69+
- name: Run Prometheus
70+
run: |
71+
docker run -d --name prometheus -v $(pwd):/etc/prometheus -p 9090:9090 --link http-server prom/prometheus:latest --config.file=/etc/prometheus/prometheus.yml --web.listen-address=:9090 > prom.log 2>&1
72+
sleep 60
73+
curl http://localhost:9090/api/v1/query?query=e2e_cpu_seconds_total
74+
75+
- name: Upload logs
76+
if: always()
77+
uses: actions/upload-artifact@v4
78+
with:
79+
name: logs
80+
path: |
81+
prom.log
82+
http.log

0 commit comments

Comments
 (0)