Skip to content

Conversation

@Drstone-23
Copy link

Closes #3011

What

Adds Functional_Peers_Connected and Reserved_Peers_Connected metrics that match GraphQL peer count.

Why

peer_count_per_protocol counts at libp2p transport level, while GraphQL returns peers from PeerManager (after LimitedBehaviour filtering). Not a bug, just different abstraction levels.

Changes

  • New gauges in p2p_metrics.rs
  • Auto-update on connect/disconnect
  • Test validating the behavior

Note for infra

Grafana should use Functional_Peers_Connected instead of peer_count_per_protocol.

@fuel-cla-bot
Copy link

fuel-cla-bot bot commented Dec 8, 2025

Thanks for the contribution! Unfortunately we can't verify the commit author(s): Drstone-23 <d***@e***.com>. One possible solution is to add that email to your GitHub account. Alternatively you can change your commits to another email and force push the change. After getting your commits associated with your GitHub account, sign the Fuel Labs Contributor License Agreement and this Pull Request will be revalidated.

@cursor
Copy link

cursor bot commented Dec 8, 2025

PR Summary

Adds Functional_Peers_Connected and Reserved_Peers_Connected gauges, updates them on peer connect/disconnect, exposes count accessors, and adds tests (incl. functional vs discovery limit).

  • Metrics:
    • Add gauges Functional_Peers_Connected and Reserved_Peers_Connected in crates/metrics/src/p2p_metrics.rs with setters and Prometheus registration.
    • Unit tests ensure presence and correct updates.
  • P2P Service (crates/services/p2p/src/p2p_service.rs):
    • Update metrics on PeerConnected/PeerDisconnected via update_peer_metrics().
    • Wire in setters from p2p_metrics.
  • PeerManager (crates/services/p2p/src/peer_manager.rs):
    • Expose non_reserved_peers_connected() and reserved_peers_connected() helpers.
  • Tests (crates/services/p2p/src/p2p_service/tests.rs):
    • Add test verifying max_functional_peers_connected is enforced independently of discovery limit.
  • Changelog:
    • Add .changes/added/3011.md describing new metrics and context.

Written by Cursor Bugbot for commit 6cc217a. This will update automatically on new commits. Configure here.

Closes FuelLabs#3011

Found that peer_count_per_protocol != GraphQL peers because they measure
different things. libp2p counts at protocol level while GraphQL returns
what PeerManager tracks (after LimitedBehaviour filtering).

Added Functional_Peers_Connected and Reserved_Peers_Connected gauges
that match what GraphQL reports. Updated automatically on connect/disconnect.

Grafana should switch to Functional_Peers_Connected for accurate counts.
@Drstone-23 Drstone-23 force-pushed the fix/p2p-peer-count-metrics-3011 branch from 650a32d to 6cc217a Compare December 8, 2025 01:55
@fuel-cla-bot
Copy link

fuel-cla-bot bot commented Dec 8, 2025

Thanks for the contribution! Before we can merge this, we need @Drstone-23 to sign the Fuel Labs Contributor License Agreement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(p2p): investigate discrepency between peer count metric vs peers returned via graphql

1 participant