Skip to content

feat: implement a pprof server to help profile ncps [backport #1063] - #1066

Merged
kalbasit merged 1 commit into
release-0.9from
backport-1063-to-release-0.9
Mar 11, 2026
Merged

kalbasit merged 1 commit into
release-0.9from
backport-1063-to-release-0.9

Conversation

@kalbasit

Copy link
Copy Markdown
Owner

Bot-based backport to release-0.9, triggered by a label in #1063.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
(cherry picked from commit 1f9c6d8)
@kalbasit
kalbasit enabled auto-merge (squash) March 11, 2026 06:23
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. enhancement New feature or request go Pull requests that update go code helm labels Mar 11, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 new feature that enables profiling of the ncps service using Go's built-in pprof tool. This enhancement provides critical observability into the application's performance characteristics, allowing developers to diagnose and optimize resource utilization more effectively. The changes span across the application's core logic, Helm chart configurations, development tooling, and user documentation to ensure comprehensive support for this new profiling capability.

Highlights

  • Pprof Server Implementation: A pprof HTTP server has been integrated into the ncps application, allowing for dynamic profiling of the service. This server listens on a configurable address and exposes standard pprof endpoints.
  • Helm Chart Configuration: The Helm chart for ncps has been updated to include new configuration options under config.observability.pprof to enable and configure the pprof server address. This includes adding the --pprof-addr argument to the ncps command and defining a pprof container port in both Deployment and StatefulSet templates.
  • Development Script Integration: The dev-scripts/run.py script was modified to support the new pprof functionality, assigning a unique pprof port to each ncps instance when running locally.
  • Documentation Updates: The user guide and chart reference documentation have been updated to reflect the new pprof configuration options and provide instructions on how to enable and access the pprof endpoints using kubectl port-forward.
Changelog
  • charts/ncps/templates/deployment.yaml
    • Added conditional --pprof-addr argument to the ncps container command.
    • Included a conditional pprof container port definition.
  • charts/ncps/templates/statefulset.yaml
    • Added conditional --pprof-addr argument to the ncps container command.
    • Included a conditional pprof container port definition.
  • charts/ncps/values.yaml
    • Introduced a new config.observability.pprof section with enabled and addr fields for pprof configuration.
  • dev-scripts/run.py
    • Defined a PPROF_BASE_PORT constant.
    • Calculated a unique pprof_port for each ncps instance.
    • Passed the --pprof-addr argument to the ncps command when launching instances.
  • docs/docs/User Guide/Installation/Helm Chart.md
    • Added a new documentation section detailing pprof configuration and access instructions.
  • docs/docs/User Guide/Installation/Helm Chart/Chart Reference.md
    • Updated the chart reference table to include config.observability.pprof.enabled and config.observability.pprof.addr.
  • pkg/ncps/serve.go
    • Imported the net/http/pprof package.
    • Added a pprof-addr CLI flag to configure the pprof server address.
    • Implemented logic to initialize and start an HTTP server for pprof endpoints if pprof-addr is specified.
Activity
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@dosubot

dosubot Bot commented Mar 11, 2026

Copy link
Copy Markdown

Related Documentation

1 document(s) may need updating based on files changed in this PR:

kalbasit's Space

Cache and Storage Configuration Flags
View Suggested Changes
@@ -314,6 +314,45 @@
 - Otherwise, the NAR is skipped
 
 This allows fsck to focus resources on files that haven't been verified recently, while maintaining confidence that all files are periodically checked. The optimization is especially beneficial for large caches with many chunked NARs, where chunk-level verification can be time-consuming.
+
+## Profiling Configuration
+
+The `ncps serve` command supports optional pprof profiling for performance analysis and troubleshooting.
+
+**Flag:** `--pprof-addr`
+
+**Environment Variable:** `PPROF_ADDR`
+
+**YAML Key:** `pprof.addr`
+
+**Purpose:** Specifies the address to listen on for pprof profiling endpoints (e.g., `:6060`). When set to an empty value (default), pprof is disabled.
+
+**Default value:** `""` (empty, disabled by default)
+
+pprof is a Go profiling tool that helps analyze CPU usage, memory allocation, goroutines, and other runtime metrics for performance troubleshooting. When enabled, pprof endpoints are available at `http://[pprof-addr]/debug/pprof`.
+
+**CLI Example:**
+```bash
+ncps serve --pprof-addr :6060
+```
+
+**YAML Example:**
+```yaml
+pprof:
+  addr: ":6060"
+```
+
+**Accessing pprof endpoints:**
+
+Once the server is running with pprof enabled, you can access the profiling interface at `http://localhost:6060/debug/pprof` (or whatever address you configured). Available endpoints include:
+
+- `/debug/pprof/` - Index page with all available profiles
+- `/debug/pprof/cmdline` - Command line invocation
+- `/debug/pprof/profile` - CPU profile (30-second sample by default)
+- `/debug/pprof/symbol` - Symbol information
+- `/debug/pprof/trace` - Execution trace
+
+**Note:** pprof endpoints should only be exposed in trusted environments, as they can reveal internal application state and consume system resources during profiling operations.
 
 ## Summary Table of Storage Flags
 | Purpose         | CLI Flag                              | YAML Key                       | Required |
@@ -326,6 +365,7 @@
 | S3 secret key   | `--cache-storage-s3-secret-access-key`| `cache.storage.s3.secret-access-key` | Yes** |
 | S3 force path style | `--cache-storage-s3-force-path-style` | `cache.storage.s3.force-path-style` | No       |
 | LRU schedule timezone | `--cache-lru-schedule-timezone` | `cache.lru.schedule.timezone` | No       |
+| Profiling address | `--pprof-addr` | `pprof.addr` | No       |
 
 * Either local or S3 storage must be configured, not both.  
 ** Required for S3 storage.

[Accept] [Decline]

Note: You must be authenticated to accept/decline updates.

How did I do? Any feedback?  Join Discord

@github-actions

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a pprof server for profiling, a valuable addition for performance analysis. While the default configuration binding to all network interfaces for pprof is acceptable as per repository rules, the implementation exposes sensitive profiling endpoints without authentication, which is a concern. Additionally, consider setting an IdleTimeout on the new HTTP server for better resource management.

Comment thread pkg/ncps/serve.go
Comment on lines +517 to +540
if pprofAddr := cmd.String("pprof-addr"); pprofAddr != "" {
pprofMux := http.NewServeMux()
pprofMux.HandleFunc("/debug/pprof/", netpprof.Index)
pprofMux.HandleFunc("/debug/pprof/cmdline", netpprof.Cmdline)
pprofMux.HandleFunc("/debug/pprof/profile", netpprof.Profile)
pprofMux.HandleFunc("/debug/pprof/symbol", netpprof.Symbol)
pprofMux.HandleFunc("/debug/pprof/trace", netpprof.Trace)

pprofServer := &http.Server{
Addr: pprofAddr,
Handler: pprofMux,
ReadHeaderTimeout: 10 * time.Second,
}

go func() {
if err := pprofServer.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
logger.Error().Err(err).Msg("pprof server error")
}
}()

registerShutdown("pprof", pprofServer.Shutdown)

logger.Info().Str("pprof_addr", pprofAddr).Msg("pprof profiling enabled")
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-medium medium

The pprof server, when enabled via the pprof-addr flag, exposes sensitive profiling endpoints (e.g., /debug/pprof/heap, /debug/pprof/profile) without authentication, potentially leaking internal application state. While the default configuration binding to all network interfaces is acceptable for disabled-by-default features (as per repository rules), implementing authentication for these sensitive endpoints is still highly recommended. Additionally, for better resource management and server hardening, consider setting an IdleTimeout on the http.Server to prevent idle connections from lingering.

            pprofServer := &http.Server{
				Addr:              pprofAddr,
				Handler:           pprofMux,
				ReadHeaderTimeout: 10 * time.Second,
				IdleTimeout:       60 * time.Second,
			}
References
  1. For optional debugging features (e.g., pprof) that are disabled by default, it is acceptable for the default configuration to bind to all network interfaces. The risk is considered low as the user must explicitly enable the feature.

@codecov

codecov Bot commented Mar 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 5.04%. Comparing base (f1cd76c) to head (15c4b13).
⚠️ Report is 1 commits behind head on release-0.9.

Additional details and impacted files
@@             Coverage Diff             @@
##           release-0.9   #1066   +/-   ##
===========================================
  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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kalbasit
kalbasit merged commit 304dc3f into release-0.9 Mar 11, 2026
14 checks passed
@kalbasit
kalbasit deleted the backport-1063-to-release-0.9 branch March 11, 2026 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update go code helm size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant