Skip to content

Commit 51ddbcf

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

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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: Set up Nix
21+
uses: cachix/install-nix-action@v27
22+
with:
23+
nix_version: latest
24+
25+
- name: Simulate e2e run & emit JSON metrics
26+
id: fake
27+
run: |
28+
cat >cpu.json <<EOF
29+
{
30+
"total": $((RANDOM % 200 + 800)),
31+
"user": $((RANDOM % 600 + 400)),
32+
"system": $((RANDOM % 200 + 100)),
33+
"rss_mb": $((RANDOM % 200 + 300))
34+
}
35+
EOF
36+
cat cpu.json
37+
38+
- name: Convert to Prometheus text
39+
run: |
40+
jq -r '
41+
"# TYPE e2e_cpu_seconds_total gauge\n" +
42+
"e2e_cpu_seconds_total{job=\"github-fake-e2e\",instance=\"${{ github.run_id }}\"} " + (.total |tostring) + "\n" +
43+
"# TYPE e2e_cpu_seconds_user gauge\n" +
44+
"e2e_cpu_seconds_user{job=\"github-fake-e2e\",instance=\"${{ github.run_id }}\"} " + (.user |tostring) + "\n" +
45+
"# TYPE e2e_cpu_seconds_sys gauge\n" +
46+
"e2e_cpu_seconds_sys{job=\"github-fake-e2e\",instance=\"${{ github.run_id }}\"} " + (.system|tostring) + "\n" +
47+
"# TYPE e2e_memory_rss_bytes gauge\n" +
48+
"e2e_memory_rss_bytes{job=\"github-fake-e2e\",instance=\"${{ github.run_id }}\"} " + ((.rss_mb*1024*1024)|tostring)
49+
' cpu.json > metrics.txt
50+
cat metrics.txt
51+
52+
- name: Create Prometheus config
53+
run: |
54+
cat >prometheus.yml <<EOF
55+
global:
56+
scrape_interval: 15s
57+
scrape_configs:
58+
- job_name: 'fake-e2e-metrics'
59+
static_configs:
60+
- targets: ['localhost:8000']
61+
metrics_path: '/metrics.txt'
62+
remote_write:
63+
- url: "$PUSH_URL"
64+
basic_auth:
65+
username: "$PUSH_USER"
66+
password: "$PUSH_PASS"
67+
EOF
68+
cat prometheus.yml
69+
70+
- name: Run HTTP server and Prometheus
71+
run: |
72+
nix-shell -p prometheus python311 --run "
73+
python -m http.server 8000 --directory . > http.log 2>&1 &
74+
prometheus --config.file=prometheus.yml --web.listen-address=:9090 > prom.log 2>&1 &
75+
sleep 60 &&
76+
curl http://localhost:9090/api/v1/query?query=e2e_cpu_seconds_total
77+
"
78+
79+
- name: Upload logs
80+
if: always()
81+
uses: actions/upload-artifact@v4
82+
with:
83+
name: logs
84+
path: |
85+
prom.log
86+
http.log

0 commit comments

Comments
 (0)