Skip to content

feat(gobgp): add kube_router_bgp_peer_info metric#2003

Merged
aauren merged 1 commit intocloudnativelabs:masterfrom
damex:feature/implement-bgp-peers-info-metric
Mar 8, 2026
Merged

feat(gobgp): add kube_router_bgp_peer_info metric#2003
aauren merged 1 commit intocloudnativelabs:masterfrom
damex:feature/implement-bgp-peers-info-metric

Conversation

@damex
Copy link
Contributor

@damex damex commented Feb 14, 2026

Replace the misleading kube_router_controller_bgp_peers gauge
which only counts 'cluster nodes'. with a new per peer metric
kube_router_bgp_peer_info with 'GaugeVec' that exposes actual
BGP session state from gobgp. labels include peer address, asn,
and session state. metric value is 1 if established and 0 otherwise.

Closes: #848

@damex
Copy link
Contributor Author

damex commented Feb 14, 2026

made isolated testing for the changes on the same node

made simplified bird2 bgp config

protocol bgp kubernetes {
  local 10.128.76.16 as 64567;
  neighbor 10.128.76.16 port 180 as 64567;
  ipv4 {
    import all;
    export all;
  };
}

this is the metric before connection is established:

$ curl 10.128.76.16:9109/metrics |& grep bgp_peer
# HELP kube_router_bgp_peer_info BGP peer information
# TYPE kube_router_bgp_peer_info gauge
kube_router_bgp_peer_info{asn="64567",peer="10.128.76.16",state="active"} 0

and this is after:

$ curl 10.128.76.16:9109/metrics |& grep bgp_peer
# HELP kube_router_bgp_peer_info BGP peer information
# TYPE kube_router_bgp_peer_info gauge
kube_router_bgp_peer_info{asn="64567",peer="10.128.76.16",state="established"} 1

@damex damex force-pushed the feature/implement-bgp-peers-info-metric branch 2 times, most recently from edfb8b5 to f49bc36 Compare February 14, 2026 11:54
@damex
Copy link
Contributor Author

damex commented Feb 14, 2026

i did see that workflows got an approval and received message about this:

https://github.com/cloudnativelabs/kube-router/actions/runs/22016039123/job/63619708028 pipeline here complained about not handling SESSION_STATE_UNSPECIFIED.

i originally map all others states and had fallback to 'unknown' (unspecified is supposed to be 'unknown'). so i have added mapping for this 'unspecified' case too and it satisfies linter.

i did run lint locally and it passed

damex@foosha:~/Documents/kube-router$ git status
On branch feature/implement-bgp-peers-info-metric
Your branch is up to date with 'origin/feature/implement-bgp-peers-info-metric'.

nothing to commit, working tree clean
damex@foosha:~/Documents/kube-router$ golangci-lint run
0 issues.

please run pipeline again

@damex
Copy link
Contributor Author

damex commented Feb 14, 2026

maybe we want to distinguish here if it is ibgp or ebgp peer (internal/external) ?
something like

kube_router_bgp_peer_info{asn="64567",peer="10.128.76.16",state="established", type="ibgp"} 1

i can add it here or as a separate pull request if that's acceptable

@damex damex force-pushed the feature/implement-bgp-peers-info-metric branch from f49bc36 to 8985458 Compare February 14, 2026 14:37
@damex
Copy link
Contributor Author

damex commented Feb 14, 2026

i thought about it and added type = ibgp/ebgp.
also renamed peer label to address since that seem to make much more sense here.

that's before establishing connection with bird2

$ curl 10.128.76.16:9109/metrics |& grep bgp_peer
# HELP kube_router_bgp_peer_info BGP peer information
# TYPE kube_router_bgp_peer_info gauge
kube_router_bgp_peer_info{address="10.128.76.16",asn="64567",state="active",type="ibgp"} 0

and that's after

$ curl 10.128.76.16:9109/metrics |& grep bgp_peer
# HELP kube_router_bgp_peer_info BGP peer information
# TYPE kube_router_bgp_peer_info gauge
kube_router_bgp_peer_info{address="10.128.76.16",asn="64567",state="established",type="ibgp"} 1

and this is ebgp with other 'host'

that's before establishing connection with bird2

$ curl 10.128.76.16:9109/metrics |& grep bgp_peer
# HELP kube_router_bgp_peer_info BGP peer information
# TYPE kube_router_bgp_peer_info gauge
kube_router_bgp_peer_info{address="10.128.76.15",asn="64568",state="active",type="ebgp"} 0

that's after

$ curl 10.128.76.16:9109/metrics |& grep bgp_peer
# HELP kube_router_bgp_peer_info BGP peer information
# TYPE kube_router_bgp_peer_info gauge
kube_router_bgp_peer_info{address="10.128.76.15",asn="64568",state="established",type="ebgp"} 1

@catherinetcai catherinetcai requested a review from aauren February 15, 2026 02:21
@aauren
Copy link
Collaborator

aauren commented Feb 22, 2026

Hey @damex - Thanks for the contribution, I've been slammed the past couple of weeks, but I'll try to take a look at this one and your other one for SCTP support as soon as possible.

Copy link
Collaborator

@catherinetcai catherinetcai left a comment

Choose a reason for hiding this comment

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

Thank you so much for your detailed notes and thorough testing @damex! I only have very, very minor comments here.

@damex damex force-pushed the feature/implement-bgp-peers-info-metric branch from 0f334ee to a200fd2 Compare February 23, 2026 08:24
Replace the misleading kube_router_controller_bgp_peers gauge
  which only counts 'cluster nodes' with a new per peer metric
  kube_router_bgp_peer_info with 'GaugeVec' that exposes actual
  BGP session state from gobgp. labels include peer address, asn,
  type, and state. Metric value is 1 if established and 0 otherwise.

Closes: cloudnativelabs#848
Signed-off-by: Roman Kuzmitskii <roman@damex.org>
@damex damex force-pushed the feature/implement-bgp-peers-info-metric branch from fa2d078 to 0be45ff Compare March 6, 2026 13:54
@aauren
Copy link
Collaborator

aauren commented Mar 8, 2026

Hey @damex apologies for getting to this late.

Thanks for the contribution! Everything looks good here, and I agree with all of @catherinetcai's suggestions. I tried deploying it and it looks good to me.

@aauren aauren merged commit b1a34ed into cloudnativelabs:master Mar 8, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Monitoring metrics do not report external BGP peers

3 participants