Skip to content

Commit 0ca4a44

Browse files
committed
chore: set up grafana alloy
1 parent 3a19c68 commit 0ca4a44

File tree

1 file changed

+114
-52
lines changed

1 file changed

+114
-52
lines changed

.github/workflows/e2e-tests-linux-split.yml

Lines changed: 114 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -269,60 +269,122 @@ jobs:
269269
name: performance-metrics
270270
path: ./artifacts/metrics
271271

272-
- name: Create Prometheus config
273-
env:
274-
PUSH_URL: ${{ secrets.GRAFANA_PUSH_URL }} # e.g., https://prometheus-us-central1.grafana.net/api/prom/push
275-
PUSH_USER: ${{ secrets.GRAFANA_USERNAME }} # e.g., 787878
276-
PUSH_PASS: ${{ secrets.GRAFANA_PASSWORD }} # e.g., eyJrIjoxxxxxxxxxxxxxxyMX0=
272+
- name: Serve metrics file locally
277273
run: |
278-
cat >prometheus.yml <<EOF
279-
global:
280-
scrape_interval: 5s
281-
scrape_configs:
282-
- job_name: 'e2e-perf-metrics'
283-
static_configs:
284-
- targets: ['pushgateway:9091']
285-
remote_write:
286-
- url: "$PUSH_URL"
287-
basic_auth:
288-
username: "$PUSH_USER"
289-
password: "$PUSH_PASS"
290-
EOF
291-
pwd
292-
ls -al ./artifacts/metrics/prometheus.txt
293-
head ./artifacts/metrics/prometheus.txt
294-
295-
- name: Start pushgateway server
274+
cat <<'PY' > serve_metrics.py
275+
import http.server, socketserver, pathlib, sys
276+
FILE = pathlib.Path('./artifacts/metrics/prometheus.txt')
277+
class H(http.server.SimpleHTTPRequestHandler):
278+
def do_GET(self):
279+
if self.path == './artifacts/metrics':
280+
content = FILE.read_bytes() if FILE.exists() else b'# metrics not ready\n'
281+
self.send_response(200)
282+
self.end_headers()
283+
self.wfile.write(content)
284+
else:
285+
self.send_error(404)
286+
with socketserver.TCPServer(('0.0.0.0', 9101), H) as s:
287+
print('Serving metrics on :9101/metrics', file=sys.stderr)
288+
s.serve_forever()
289+
PY
290+
python serve_metrics.py &
291+
292+
# ------------------------------------------------------------------------
293+
# 3) Write Alloy (River) config — scrape localhost:9101 and remote_write
294+
# ------------------------------------------------------------------------
295+
- name: Generate alloy.river
296+
env:
297+
GRAFANA_CLOUD_USERNAME: ${{ secrets.GRAFANA_ALLOY_USERNAME }}
298+
GRAFANA_CLOUD_API_KEY: ${{ secrets.GRAFANA_ALLOY_API_KEY }}
296299
run: |
297-
docker run -d --name pushgateway -p 9091:9091 prom/pushgateway
298-
cat ./artifacts/metrics/prometheus.txt | curl --data-binary @- http://localhost:9091/metrics/job/e2e-perf
299-
#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
300-
printf '\n*****************\n'
301-
echo 'This is my current directory:'
302-
pwd
303-
printf '\n*****************\n'
304-
echo 'This is ls -al in that directory'
305-
ls -al
306-
printf '\n*****************\n'
307-
308-
- name: Run Prometheus
300+
mkdir -p alloy
301+
cat > alloy/alloy.river <<RIVER
302+
prometheus.remote_write "gc" {
303+
endpoint {
304+
url = "https://prometheus-us-central1.grafana.net/api/prom/push"
305+
basic_auth {
306+
username = env("GRAFANA_CLOUD_USERNAME")
307+
password = env("GRAFANA_CLOUD_API_KEY")
308+
}
309+
}
310+
}
311+
312+
prometheus.scrape "e2e" {
313+
targets = [{
314+
__address__ = "127.0.0.1:9101",
315+
}]
316+
forward_to = [prometheus.remote_write.gc.receiver]
317+
}
318+
RIVER
319+
320+
# ------------------------------------------------------------------------
321+
# 4) Launch Alloy for ~45 s to scrape + push the data, then shut it down.
322+
# ------------------------------------------------------------------------
323+
- name: Run Alloy and push metrics
309324
run: |
310-
# Enable logs for debugging
311-
#docker run --name prometheus -v $(pwd):/etc/prometheus -p 9090:9090 --link pushgateway:pushgateway prom/prometheus:latest --config.file=/etc/prometheus/prometheus.yml --web.listen-address=:9090 --log.level=debug
312-
docker run -d --name prometheus -v $(pwd):/etc/prometheus -p 9090:9090 --link pushgateway:pushgateway prom/prometheus:latest --config.file=/etc/prometheus/prometheus.yml --web.listen-address=:9090 > prom.log 2>&1
313-
sleep 60
314-
# Uncomment for troubleshooting.
315-
printf '\n*****************\n'
316-
printf '\n curl e2e_cpu_seconds_total \n'
317-
curl http://localhost:9090/api/v1/query?query=e2e_cpu_seconds_total_v1
318-
printf '\n*****************\n'
319-
printf '\n cat prom.log \n'
320-
cat prom.log
321-
#printf '\n*****************\n'
322-
#printf '\n send_failures_total \n'
323-
#curl 'http://localhost:9090/api/v1/query?query=prometheus_remote_storage_queue_send_failures_total'
324-
#printf '\n*****************\n'
325-
#printf '\n storage_retries_total \n'
326-
#curl 'http://localhost:9090/api/v1/query?query=prometheus_remote_storage_retries_total'
325+
docker run --rm \
326+
-e ALLOY_CONFIG=/etc/alloy.river \
327+
-v "$PWD/alloy/alloy.river:/etc/alloy.river:ro" \
328+
grafana/alloy:latest run /etc/alloy.river &
329+
ALLOY_PID=$!
330+
# wait for two scrape cycles + remote write
331+
sleep 45
332+
kill "$ALLOY_PID" || true
333+
334+
# - name: Create Prometheus config
335+
# env:
336+
# PUSH_URL: ${{ secrets.GRAFANA_PUSH_URL }} # e.g., https://prometheus-us-central1.grafana.net/api/prom/push
337+
# PUSH_USER: ${{ secrets.GRAFANA_USERNAME }} # e.g., 787878
338+
# PUSH_PASS: ${{ secrets.GRAFANA_PASSWORD }} # e.g., eyJrIjoxxxxxxxxxxxxxxyMX0=
339+
# run: |
340+
# cat >prometheus.yml <<EOF
341+
# global:
342+
# scrape_interval: 5s
343+
# scrape_configs:
344+
# - job_name: 'e2e-perf-metrics'
345+
# static_configs:
346+
# - targets: ['pushgateway:9091']
347+
# remote_write:
348+
# - url: "$PUSH_URL"
349+
# basic_auth:
350+
# username: "$PUSH_USER"
351+
# password: "$PUSH_PASS"
352+
# EOF
353+
# pwd
354+
# ls -al ./artifacts/metrics/prometheus.txt
355+
# head ./artifacts/metrics/prometheus.txt
356+
#
357+
# - name: Start pushgateway server
358+
# run: |
359+
# docker run -d --name pushgateway -p 9091:9091 prom/pushgateway
360+
# cat ./artifacts/metrics/prometheus.txt | curl --data-binary @- http://localhost:9091/metrics/job/e2e-perf
361+
# #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
362+
# printf '\n*****************\n'
363+
# echo 'This is my current directory:'
364+
# pwd
365+
# printf '\n*****************\n'
366+
# echo 'This is ls -al in that directory'
367+
# ls -al
368+
# printf '\n*****************\n'
369+
#
370+
# - name: Run Prometheus
371+
# run: |
372+
# # Enable logs for debugging
373+
# #docker run --name prometheus -v $(pwd):/etc/prometheus -p 9090:9090 --link pushgateway:pushgateway prom/prometheus:latest --config.file=/etc/prometheus/prometheus.yml --web.listen-address=:9090 --log.level=debug
374+
# docker run -d --name prometheus -v $(pwd):/etc/prometheus -p 9090:9090 --link pushgateway:pushgateway prom/prometheus:latest --config.file=/etc/prometheus/prometheus.yml --web.listen-address=:9090 > prom.log 2>&1
375+
# sleep 60
376+
# # Uncomment for troubleshooting.
377+
# printf '\n*****************\n'
378+
# printf '\n curl e2e_cpu_seconds_total \n'
379+
# curl http://localhost:9090/api/v1/query?query=e2e_cpu_seconds_total_v1
380+
# printf '\n*****************\n'
381+
# printf '\n cat prom.log \n'
382+
# cat prom.log
383+
# #printf '\n*****************\n'
384+
# #printf '\n send_failures_total \n'
385+
# #curl 'http://localhost:9090/api/v1/query?query=prometheus_remote_storage_queue_send_failures_total'
386+
# #printf '\n*****************\n'
387+
# #printf '\n storage_retries_total \n'
388+
# #curl 'http://localhost:9090/api/v1/query?query=prometheus_remote_storage_retries_total'
327389

328390

0 commit comments

Comments
 (0)