[PR #6683] [relay] add transport label to peer activity and transfer metrics #26659

Open
opened 2026-08-05 07:07:39 -04:00 by saavagebueno · 0 comments
Owner

Original Pull Request: https://github.com/netbirdio/netbird/pull/6683

State: open
Merged: No


Describe your changes

relay_peers is already exported with a transport label (ws / quic), but the other relay metrics are not, so operators can't break connection activity or throughput down by transport. This adds the transport label to the remaining relay peer/transfer metrics so they're consistent with relay_peers:

  • relay_peers_active
  • relay_peers_idle
  • relay_transfer_sent_bytes_total
  • relay_transfer_received_bytes_total

Implementation notes

  • relay_peers_active / relay_peers_idle are observable gauges derived from an in-memory activity map that only stored each peer's last-active time. The map now also stores the peer's transport (captured at connect time in PeerConnected), and calculateActiveIdleConnections groups the counts by transport.
  • For the transfer counters the label is applied at the connection the bytes actually cross: received bytes use the receiving peer's transport, and relayed/sent bytes use the destination peer's transport (the write target). So a WS→QUIC relayed packet is correctly attributed to relay_transfer_received_bytes_total{transport="ws"} and relay_transfer_sent_bytes_total{transport="quic"}.
  • Minor behavior fix: a late PeerActivity event no longer re-inserts an already-disconnected peer into the activity map.
  • The two transfer counters were made private and are now written through RecordBytesSent / RecordBytesRecv helpers (consistent with the existing PeerConnected(id, transport) style and the "use private where possible" guideline).

Operator impact

Adding a label splits each of these metrics into per-transport series. Dashboards/alerts that already aggregate (e.g. sum(rate(relay_transfer_sent_bytes_total[...]))) are unaffected; any that selected a single bare series will now see one series per transport. The bundled Grafana dashboard (infrastructure_files/observability/grafana/dashboards/relay.json) already renders relay_peers per-transport, so no dashboard changes are required.

N/A

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)
  • This change does not modify the public API, gRPC protocols, functionality behavior, CLI / service flags, or introduce a new feature. The only surface touched is Prometheus/OTel metric labels, extending the transport label pattern already used by relay_peers.

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
  • Documentation is not needed for this change (it extends existing metric labels; there is no user-facing config, API, or CLI change)

Docs PR URL (required if "docs added" is checked)

N/A

Summary by CodeRabbit

  • New Features

    • Relay metrics now label active/idle peer counts by connection transport.
    • Peer byte transfer metrics are reported separately per transport.
    • Peers now expose their transport type to drive accurate reporting.
  • Bug Fixes

    • Peer activity updates no longer revive disconnected peers in metrics.
    • Newly connected peers are treated as idle until activity is observed.
  • Tests

    • Expanded coverage for transport-labeled peer/byte metrics and edge cases in active/idle counting.
**Original Pull Request:** https://github.com/netbirdio/netbird/pull/6683 **State:** open **Merged:** No --- ## Describe your changes `relay_peers` is already exported with a `transport` label (`ws` / `quic`), but the other relay metrics are not, so operators can't break connection activity or throughput down by transport. This adds the `transport` label to the remaining relay peer/transfer metrics so they're consistent with `relay_peers`: - `relay_peers_active` - `relay_peers_idle` - `relay_transfer_sent_bytes_total` - `relay_transfer_received_bytes_total` **Implementation notes** - `relay_peers_active` / `relay_peers_idle` are observable gauges derived from an in-memory activity map that only stored each peer's last-active time. The map now also stores the peer's transport (captured at connect time in `PeerConnected`), and `calculateActiveIdleConnections` groups the counts by transport. - For the transfer counters the label is applied at the connection the bytes actually cross: **received** bytes use the receiving peer's transport, and **relayed/sent** bytes use the **destination** peer's transport (the write target). So a WS→QUIC relayed packet is correctly attributed to `relay_transfer_received_bytes_total{transport="ws"}` and `relay_transfer_sent_bytes_total{transport="quic"}`. - Minor behavior fix: a late `PeerActivity` event no longer re-inserts an already-disconnected peer into the activity map. - The two transfer counters were made private and are now written through `RecordBytesSent` / `RecordBytesRecv` helpers (consistent with the existing `PeerConnected(id, transport)` style and the "use private where possible" guideline). **Operator impact** Adding a label splits each of these metrics into per-transport series. Dashboards/alerts that already aggregate (e.g. `sum(rate(relay_transfer_sent_bytes_total[...]))`) are unaffected; any that selected a single bare series will now see one series per transport. The bundled Grafana dashboard (`infrastructure_files/observability/grafana/dashboards/relay.json`) already renders `relay_peers` per-transport, so no dashboard changes are required. ## Issue ticket number and link N/A ## Stack <!-- branch-stack --> ### Checklist - [ ] Is it a bug fix - [ ] Is a typo/documentation fix - [x] Is a feature enhancement - [ ] It is a refactor - [x] Created tests that fail without the change (if possible) - [x] This change does **not** modify the public API, gRPC protocols, functionality behavior, CLI / service flags, or introduce a new feature. The only surface touched is Prometheus/OTel metric labels, extending the `transport` label pattern already used by `relay_peers`. > By submitting this pull request, you confirm that you have read and agree to the terms of the [Contributor License Agreement](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT.md). ## Documentation Select exactly one: - [ ] I added/updated documentation for this change - [x] Documentation is **not needed** for this change (it extends existing metric labels; there is no user-facing config, API, or CLI change) ### Docs PR URL (required if "docs added" is checked) N/A <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Relay metrics now label active/idle peer counts by connection transport. * Peer byte transfer metrics are reported separately per transport. * Peers now expose their transport type to drive accurate reporting. * **Bug Fixes** * Peer activity updates no longer revive disconnected peers in metrics. * Newly connected peers are treated as idle until activity is observed. * **Tests** * Expanded coverage for transport-labeled peer/byte metrics and edge cases in active/idle counting. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
saavagebueno added the pull-request label 2026-08-05 07:07:39 -04:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DYNR/netbird#26659