Repository navigation
feat: implement a pprof server to help profile ncps - #1063
Conversation
|
This change is part of the following stack: Change managed by git-spice. |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a significant enhancement for debugging and performance analysis by integrating a pprof profiling server into the Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Documentation Updates 1 document(s) were updated by changes in this PR: OpenTelemetry Instrumentation and MetricsView Changes@@ -70,6 +70,49 @@
The `/metrics` endpoint is available on the server's HTTP address (default `:8501`) and can be scraped by Prometheus or queried directly for metrics [[source]](https://github.com/kalbasit/ncps/blob/b7653d4303670bb88fd34b8bf82ed3aade09885d/cmd/serve.go#L255-L529).
+### pprof Profiling Support
+The pprof profiling server enables CPU and memory profiling for performance analysis and troubleshooting. Profiling is disabled by default for security and must be explicitly enabled using the `--pprof-addr` flag.
+
+When enabled, pprof exposes standard profiling endpoints on a separate HTTP server:
+
+- `/debug/pprof/` - Index page listing available profiles
+- `/debug/pprof/cmdline` - Command-line invocation of the program
+- `/debug/pprof/profile` - CPU profile (30-second sampling by default)
+- `/debug/pprof/symbol` - Symbol lookup for addresses
+- `/debug/pprof/trace` - Execution trace
+
+Example:
+
+```sh
+ncps serve --pprof-addr=:6060
+```
+
+The pprof endpoints are then available at `http://localhost:6060/debug/pprof/`. You can use Go's pprof tool to analyze profiles:
+
+```sh
+# CPU profile
+go tool pprof http://localhost:6060/debug/pprof/profile
+
+# Memory profile
+go tool pprof http://localhost:6060/debug/pprof/heap
+```
+
+#### Helm Chart Configuration
+When deploying with the Helm chart, configure pprof using:
+
+```yaml
+config:
+ observability:
+ pprof:
+ enabled: true
+ addr: ":6060"
+```
+
+#### Security Considerations
+**Important:** The pprof server should typically be disabled in production environments or only exposed on internal networks. Profiling endpoints can expose sensitive runtime information and consume significant resources during profile collection. The default configuration (empty `--pprof-addr` value) keeps pprof disabled for security.
+
+Consider restricting access to the pprof port using network policies or firewall rules, and only enable profiling temporarily when investigating performance issues.
+
### Metrics Collected for NAR and NarInfo File Serving
A new observable gauge metric is available:
@@ -80,17 +123,18 @@
### Tracing Spans for NAR and NarInfo Operations
In addition to tracing spans for NAR and NarInfo operations, lock operations are now instrumented with OpenTelemetry metrics. Both local and distributed (Redis-based) lock implementations record metrics for acquisition attempts, contention, failures (with detailed reasons), retry attempts, and lock hold durations. While lock operations do not create tracing spans, the emitted metrics provide fine-grained observability into lock behavior, including contention events and failure diagnostics for distributed systems.
-### Enabling and Accessing Metrics for Observability
-To enable tracing and metrics:
+### Enabling and Accessing Observability Features
+To enable tracing, metrics, and profiling:
1. Start the server with `--otel-enabled` to activate OpenTelemetry tracing, metrics, and logging.
2. Optionally, set `--otel-grpc-url` to export telemetry to a remote OTLP collector.
3. Add `--prometheus-enabled` to expose Prometheus metrics at `/metrics`.
+4. Add `--pprof-addr=:6060` to enable pprof profiling endpoints (optional, disabled by default).
Example:
```sh
-ncps serve --otel-enabled --prometheus-enabled
+ncps serve --otel-enabled --prometheus-enabled --pprof-addr=:6060
```
To access metrics, configure Prometheus to scrape the `/metrics` endpoint (default `http://localhost:8501/metrics`). Example Prometheus scrape config:
@@ -109,5 +153,6 @@
- Use the `--otel-grpc-url` flag to export telemetry to a centralized collector for production deployments.
- Monitor the `result` and `status` attributes on NAR and NarInfo metrics to identify cache misses and errors.
- Ensure Prometheus is configured to scrape the correct endpoint and port.
+- Keep pprof disabled in production unless actively troubleshooting performance issues, and restrict access to the pprof port to internal networks only.
For further customization or troubleshooting, refer to the CLI help (`ncps --help`) and review logs for OpenTelemetry initialization messages. |
There was a problem hiding this comment.
Code Review
This pull request introduces a pprof server to aid in profiling ncps. The implementation adds a --pprof-addr flag to enable the server on a specified address. The changes are well-contained and the feature is opt-in, which is good practice. I've suggested a simplification to the pprof handler registration to make the code more concise and maintainable.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1063 +/- ##
=====================================
Coverage 5.04% 5.04%
=====================================
Files 6 6
Lines 436 436
=====================================
Hits 22 22
Misses 410 410
Partials 4 4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
8ecf9af to
d152e09
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a pprof server to ncps for performance profiling. However, the current implementation lacks authentication and uses an insecure default binding in the Helm chart, which could lead to unauthorized access to sensitive profiling data and potential Denial of Service attacks. Additionally, consider improving the documentation for port-forwarding to make it more robust for users with different Helm release names.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> (cherry picked from commit 1f9c6d8)
|
Successfully created backport PR for |
## Summary The `[Unreleased]` section was populated in #1309 but skewed toward the recent CDC-drain, in-flight-staging, and Ent-migration work, omitting several user-facing features and fixes that also landed since v0.9.4. This backfills the missing notable changes, each cross-referenced by PR. **Added** - `ncps fsck` command + Helm fsck CronJob (#975, #996, #998, #999, #1000, #1004, #1006, #1176) - Closure pinning HTTP endpoints `POST`/`DELETE /pin/{hash}.narinfo`, `GET /pins` (#1108) - pprof server via `--pprof-addr` (#1063) - CDC lazy chunking as a feature + `--cache-cdc-lazy-cleanup-schedule` + recovery cron (#1082, #1083, #1089, #1096) - Helm: auto `GOMEMLIMIT` (#1061), configurable temp volume / `volumeClaimTemplate` (#1074, #1077), SQLite `Recreate` strategy (#1012) - Startup storage reporting + deprecated-narinfo warning (#959, #961) - `docker-dev` image (#1097) **Fixed** - `store/tmp` no longer wiped on startup (#1313) - `nix-hash` NAR verification (#1101) - Prometheus counters primed at startup (#1337, #1343) - 404 on un-reassemblable chunked NARs (#1319), purged narinfo no longer 500 (#1318), fail-fast tmp validation (#1086) - Further CDC/cache reliability fixes (#1317, #1346, #1341, #1342, #1331, #1347) **Changed** - CDC config now persisted in the DB config table (#971) Dependency bumps, CI/test-only changes, and the internal Ent-conversion PRs are intentionally excluded; the existing Ent-migration entry already covers that work. ## Test plan - [x] `nix fmt` reports no changes (docs-only edit) - [x] CHANGELOG section structure intact (Added/Fixed/Changed/Removed/Migration/CI)
No description provided.