netbird icon indicating copy to clipboard operation
netbird copied to clipboard

[signal, management] Allow pprof port configuration through NB_PPROF_ADDR

Open ujaandas opened this issue 2 months ago • 4 comments

Describe your changes

Signal and Management servers previously hard‑coded a pprof listener on localhost:6060, which caused port conflicts when multiple services ran in the same namespace (ie; in the same pod or as a NixOS service). This PR refactors both to use the same pprof.go helper pattern already present in Client/Relay.

Does this change build semantics though? To test it, I ran it with -tags pprof. If it does, it shouldn't be a huge change to just slap what pprof.go does directly into the relevant functions.

Issue ticket number and link

Fixes #4923

Stack

Branch: pprof-configurable-signal-mgmt

Checklist

  • [ ] Is it a bug fix
  • [ ] Is a typo/documentation fix
  • [x] Is a feature enhancement
  • [ ] It is a refactor
  • [ ] Created tests that fail without the change (if possible)

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • [ ] I added/updated documentation for this change
  • [x] Documentation is not needed for this change (explain why)

The behavior is consistent with existing Client/Relay profiling logic, so no new user‑facing configuration is introduced beyond the existing NB_PPROF_ADDR.

Summary by CodeRabbit

  • Refactor
    • Reorganized profiling infrastructure for optional runtime profiling support through build configuration.
    • Profiling address now configurable via NB_PPROF_ADDR environment variable (defaults to localhost:6060).

✏️ Tip: You can customize this high-level summary in your review settings.

ujaandas avatar Dec 18 '25 17:12 ujaandas

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Dec 18 '25 17:12 CLAassistant

Walkthrough

The pull request refactors pprof profiling support from hardcoded runtime initialization to an optional, configurable mechanism. Pprof integration is removed from main entry points and relocated to separate build-tagged files that read NB_PPROF_ADDR environment variable for address configuration, enabling both management and signal servers to run on the same host without port conflicts.

Changes

Cohort / File(s) Summary
Removal of hardcoded pprof
management/main.go, signal/cmd/run.go
Deleted imports and initialization code that unconditionally started pprof HTTP server on startup.
Optional build-tagged pprof support
management/cmd/pprof.go, signal/cmd/pprof.go
Added new build-tagged modules (guarded by pprof tag) that register init functions to start pprof server. Address is read from NB_PPROF_ADDR environment variable with default localhost:6060. Includes helper functions for address resolution and server startup with error logging.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify NB_PPROF_ADDR environment variable name is consistently used across both files
  • Confirm default address (localhost:6060) is identical in both implementations
  • Ensure build tag syntax and init function execution flow are correct
  • Validate that removals from main files don't leave orphaned references elsewhere

Poem

🐰 Two servers clashed on port six-oh-six, Now flags and vars help us fix, Build with pprof when you dare, Set addresses with care, No more conflicts—just metrics to mix! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: making pprof port configurable through the NB_PPROF_ADDR environment variable across signal and management services.
Description check ✅ Passed The description adequately explains the problem (hardcoded pprof port conflicts), the solution (using NB_PPROF_ADDR like Client/Relay), and references the fixed issue #4923 with appropriate checklist completion.
Linked Issues check ✅ Passed The PR fully addresses issue #4923 by making pprof port configurable via NB_PPROF_ADDR environment variable for both Signal and Management services, eliminating port conflicts when running multiple services on the same host.
Out of Scope Changes check ✅ Passed All changes are directly related to the objective: refactoring Signal and Management pprof initialization to use configurable NB_PPROF_ADDR. No unrelated modifications detected.
✨ Finishing touches
  • [ ] 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Dec 18 '25 17:12 coderabbitai[bot]

Oh, i also encountered that... Fixes #5028

vooon avatar Jan 04 '26 13:01 vooon