[client] Add local Prometheus metrics endpoint#6689
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR adds an optional local Prometheus ChangesLocal metrics feature
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant CLI as Client CLI
participant Server as Daemon Server
participant Manager as localmetrics.Manager
participant Status as peer.Status
participant Prometheus as Prometheus Scraper
CLI->>Server: SetConfigRequest / LoginRequest
Server->>Server: update config and reconcile local metrics
Server->>Manager: Reconcile(enabled, address)
Prometheus->>Manager: GET /metrics
Manager->>Status: GetPeerStates()
Manager-->>Prometheus: metrics response
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
client/internal/localmetrics/localmetrics.go (1)
60-63: 🔒 Security & Privacy | 🔵 TrivialConsider warning when binding to a non-loopback address.
The endpoint exposes peer FQDNs, latency, and connectivity state without authentication. Default is loopback-only, but
addris fully user-controlled; a log warning (or explicit opt-in) when the host isn't loopback would help users avoid accidental exposure.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@client/internal/localmetrics/localmetrics.go` around lines 60 - 63, The local metrics endpoint in Manager.Reconcile can bind to any user-supplied addr, which may accidentally expose sensitive peer and connectivity data. Update Reconcile to detect when addr is not loopback after defaulting to DefaultListenAddress, and emit a clear warning (or require explicit opt-in) before starting the listener. Keep the check near the address selection logic so the behavior is obvious and easy to maintain.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@client/internal/localmetrics/localmetrics.go`:
- Line 94: The local metrics server created in `Start` uses `http.Server`
without any timeout protections, leaving it vulnerable to slow client
connections. Update the `srv := &http.Server{...}` construction to set
appropriate `ReadTimeout`, `ReadHeaderTimeout`, `WriteTimeout`, and
`IdleTimeout` values, keeping the existing `Addr` and `Handler` behavior intact.
Use the `Start` function and the `http.Server` setup as the place to apply these
limits.
---
Nitpick comments:
In `@client/internal/localmetrics/localmetrics.go`:
- Around line 60-63: The local metrics endpoint in Manager.Reconcile can bind to
any user-supplied addr, which may accidentally expose sensitive peer and
connectivity data. Update Reconcile to detect when addr is not loopback after
defaulting to DefaultListenAddress, and emit a clear warning (or require
explicit opt-in) before starting the listener. Keep the check near the address
selection logic so the behavior is obvious and easy to maintain.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 7f956574-47e5-405e-a5e6-4581c2baf2ed
⛔ Files ignored due to path filters (1)
client/proto/daemon.pb.gois excluded by!**/*.pb.go
📒 Files selected for processing (15)
client/cmd/root.goclient/cmd/up.goclient/internal/localmetrics/localmetrics.goclient/internal/localmetrics/localmetrics_test.goclient/internal/metrics/influxdb.goclient/internal/metrics/metrics.goclient/internal/metrics/metrics_default.goclient/internal/metrics/prometheus.goclient/internal/peer/status.goclient/internal/profilemanager/config.goclient/proto/daemon.protoclient/server/server.goclient/server/setconfig_test.gogo.modinfrastructure_files/observability/grafana/dashboards/client.json
Release artifactsBuilt for PR head
GHCR images (amd64)
This comment is updated by the Release workflow. Artifact links expire according to the workflow retention policy. |
cd0ecae to
6d9cb90
Compare
|



Adds an opt-in Prometheus
/metricsendpoint to the client daemon so deployments can scrape connection health locally (requested for a RedHat evaluation: latency, connected peers, P2P vs relay).netbird up --enable-local-metricsand--local-metrics-address(default127.0.0.1:9191); the setting persists in the profile config and travels through SetConfig/Login like other config flags--disable-update-settingsand MDM policy (enableLocalMetrics,localMetricsAddresskeys)All labels are bounded enums except the per-peer latency series, which carries the peer FQDN only.
Issue ticket number and link
Stack
Checklist
Documentation
Select exactly one:
Docs PR URL (required if "docs added" is checked)
Paste the PR link from https://github.com/netbirdio/docs here:
https://github.com/netbirdio/docs/pull/__
Summary by CodeRabbit
/metricsendpoint for the client, configurable via CLI and settings (enable/disable and listen address).