From 0fb04c68de837deb945e201062ccbb67e657fe90 Mon Sep 17 00:00:00 2001 From: Sebastian <15335529+Sobeston@users.noreply.github.com> Date: Tue, 7 Jan 2025 18:57:09 +0000 Subject: [PATCH] add continuous profiling support (#482) --- build.zig | 6 ++++++ metrics/README.md | 1 + metrics/alloy/config.alloy | 15 +++++++++++++++ metrics/docker-compose.yml | 15 +++++++++++++++ metrics/grafana/datasources/datasource.yml | 4 ++++ 5 files changed, 41 insertions(+) diff --git a/build.zig b/build.zig index 118407b18..4c7c697a3 100644 --- a/build.zig +++ b/build.zig @@ -85,6 +85,12 @@ pub fn build(b: *Build) void { .optimize = optimize, .sanitize_thread = enable_tsan, }); + + // make sure pyroscope's got enough info to profile + sig_exe.build_id = .fast; + sig_exe.root_module.omit_frame_pointer = false; + sig_exe.root_module.strip = false; + b.installArtifact(sig_exe); sig_exe.root_module.addImport("base58-zig", base58_module); sig_exe.root_module.addImport("curl", curl_mod); diff --git a/metrics/README.md b/metrics/README.md index 56b83235d..ac1d8e7a1 100644 --- a/metrics/README.md +++ b/metrics/README.md @@ -18,6 +18,7 @@ linux: `docker compose up -d` - prometheus will be accessable on `localhost:9090` - sig metrics will be published to localhost:12345 (if you change this on the sig cli, you will need to also modify the prometheus `target` to point to the different port). +- To enable profiling, optionally supply SIG_PID `e.g. SIG_PID=$(pgrep sig) docker compose up -d` ## Shutting down diff --git a/metrics/alloy/config.alloy b/metrics/alloy/config.alloy index 0480af0d5..a38920e34 100644 --- a/metrics/alloy/config.alloy +++ b/metrics/alloy/config.alloy @@ -14,3 +14,18 @@ loki.write "grafana_loki" { url = "http://loki:3100/loki/api/v1/push" } } + +pyroscope.ebpf "instance" { + forward_to = [pyroscope.write.endpoint.receiver] + targets = [{ + __process_pid__ = env("SIG_PID"), + service_name = "sig", + }] + +} + +pyroscope.write "endpoint" { + endpoint { + url = "http://pyroscope:4040" + } +} \ No newline at end of file diff --git a/metrics/docker-compose.yml b/metrics/docker-compose.yml index 19dda2d95..cc957e32b 100644 --- a/metrics/docker-compose.yml +++ b/metrics/docker-compose.yml @@ -30,6 +30,11 @@ services: alloy: image: grafana/alloy:v1.3.1 container_name: alloy + + # needed to access sig process + pid: "host" + privileged: true + ports: - "3200:3200" volumes: @@ -41,6 +46,8 @@ services: "--server.http.listen-addr=0.0.0.0:3200", "/etc/alloy/config.alloy", ] + environment: + - SIG_PID=${SIG_PID} grafana: image: grafana/grafana @@ -63,5 +70,13 @@ services: - 9100:9100 restart: unless-stopped + pyroscope: + image: grafana/pyroscope:1.11.0 + container_name: pyroscope + ports: + - "4040:4040" + environment: + - STORAGE_DRIVER=in-memory + volumes: prom_data: diff --git a/metrics/grafana/datasources/datasource.yml b/metrics/grafana/datasources/datasource.yml index 7b32a4785..424efe709 100644 --- a/metrics/grafana/datasources/datasource.yml +++ b/metrics/grafana/datasources/datasource.yml @@ -14,3 +14,7 @@ datasources: isDefault: false version: 1 editable: false + + - name: Pyroscope + type: grafana-pyroscope-datasource + url: http://pyroscope:4040