Feat/picod prometheus metrics#400
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Code Review
This pull request introduces Prometheus metrics to the PicoD server, adding a new /metrics endpoint and middleware to track active executions, request counts, and HTTP latencies. The feedback highlights a potential Denial of Service (DoS) vulnerability due to high cardinality in the metrics middleware when c.FullPath() is empty, and points out an incorrect metric label ("invalid" instead of "error") when directory creation fails with an HTTP 500 error.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Pull request overview
Adds Prometheus observability to PicoD (the sandbox-side execution daemon) by introducing a dedicated Prometheus registry, a /metrics endpoint, and request/execute instrumentation so operators can monitor request rates, latency, and command execution behavior.
Changes:
- Introduces
pkg/picod/metrics.gowith a private Prometheus registry, collectors, and Gin middleware for HTTP request counting/latency. - Exposes
/metricsin the PicoD Gin server and excludes it from gzip compression. - Instruments
ExecuteHandlerto emit execution outcome counters and an “active executions” gauge; adds unit tests validating metric collection viaRegistry.Gather().
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/picod/server.go | Wires metrics middleware and /metrics endpoint into PicoD’s Gin server and gzip exclusions. |
| pkg/picod/metrics.go | Implements PicoD Prometheus registry, collectors, /metrics handler, and HTTP instrumentation middleware. |
| pkg/picod/metrics_test.go | Adds tests that exercise /metrics, execute a command, and validate gathered metric families. |
| pkg/picod/execute.go | Adds execution-level metric updates (active gauge + outcome counter). |
| go.mod | Promotes prometheus/client_golang to a direct dependency. |
| go.sum | Tidies module checksums accordingly. |
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #400 +/- ##
===========================================
+ Coverage 47.57% 59.49% +11.92%
===========================================
Files 30 38 +8
Lines 2819 3570 +751
===========================================
+ Hits 1341 2124 +783
+ Misses 1338 1237 -101
- Partials 140 209 +69
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
5dca3fa to
482fcaf
Compare
Implement a /metrics Prometheus endpoint in PicoD to monitor command executions, request latency, and HTTP requests. - Add metrics for active executions and request outcomes. - Add Gin middleware for path/method/status metrics. - Exclude /metrics from auth and gzip compression. - Add unit tests. Signed-off-by: Vanshika <pahalvanshikaa@gmail.com>
482fcaf to
3e4ac99
Compare
622a676 to
3e4ac99
Compare
|
@hzxuzhonghu Please review it. |
|
I did a local pass over the current head (
One issue still looks worth fixing before merge:
I verified this locally with a temporary test that sends an oversized Suggested focused test coverage:
Two smaller follow-ups:
|
/kind feature
What type of PR is this?
/kind feature
What this PR does / why we need it:
PicoD currently exposes only a
/healthendpoint and does not provide any Prometheus-compatible metrics. This makes it difficult to monitor sandbox activity, understand request patterns, or observe command execution behavior.This PR adds a Prometheus
/metricsendpoint to PicoD using the existingprometheus/client_golangdependency already present in the module graph. The implementation introduces a dedicated Prometheus registry and exports metrics focused on request handling and command execution.Metrics added:
picod_active_executions– Gauge tracking in-flight execute requests.picod_execute_requests_total– Counter tracking execute request outcomes (success,error,timeout,invalid).picod_http_requests_total– Counter tracking processed HTTP requests by method, path, and status code.picod_http_request_duration_seconds– Histogram tracking request latency by method and path.The
/metricsendpoint is exposed similarly to/healthand is excluded from gzip compression. The implementation also includes middleware-based request instrumentation and unit tests validating metric registration and collection behavior.Which issue(s) this PR fixes:
Fixes #386
Special notes for your reviewer:
Registry.Gather()rather than relying on text exposition output.Does this PR introduce a user-facing change?: