Skip to content

Commit

Permalink
Remove the port from the peer metrics label
Browse files Browse the repository at this point in the history
For each VRF we can have only one neighbor for a given address, which
makes the port irrelevant.

Additionally, now that frr-k8s can accept connections too, the port can
either be the one used on our side to establish the connection, or
the source port in case we are accepting a bgp connection.
This makes the metric labels non predictable and hard to monitor.

Because of this, here we remove the port from the label.

Signed-off-by: Federico Paolinelli <[email protected]>
  • Loading branch information
fedepaol committed Oct 7, 2024
1 parent 6c94b05 commit ae0cfff
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
7 changes: 3 additions & 4 deletions e2etests/tests/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,20 +384,19 @@ func labelsForPeers(peers []*frrcontainer.FRR, ipFamily ipfamily.Family) []peerP
if ipFamily == ipfamily.IPv6 {
address = c.Ipv6
}
peerAddr := address + fmt.Sprintf(":%d", c.RouterConfig.BGPPort)

// Note: we deliberately don't add the vrf label in case of the default vrf to validate that
// it is still possible to list the metrics using only the peer label, which is what most users
// who don't care about vrfs should do.
labelsBGP := map[string]string{"peer": peerAddr}
labelsForQueryBGP := fmt.Sprintf(`peer="%s"`, peerAddr)
labelsBGP := map[string]string{"peer": address}
labelsForQueryBGP := fmt.Sprintf(`peer="%s"`, address)
labelsBFD := map[string]string{"peer": address}
labelsForQueryBFD := fmt.Sprintf(`peer="%s"`, address)
noEcho := c.NeighborConfig.MultiHop

if c.RouterConfig.VRF != "" {
labelsBGP["vrf"] = c.RouterConfig.VRF
labelsForQueryBGP = fmt.Sprintf(`peer="%s",vrf="%s"`, peerAddr, c.RouterConfig.VRF)
labelsForQueryBGP = fmt.Sprintf(`peer="%s",vrf="%s"`, address, c.RouterConfig.VRF)
labelsBFD["vrf"] = c.RouterConfig.VRF
labelsForQueryBFD = fmt.Sprintf(`peer="%s",vrf="%s"`, address, c.RouterConfig.VRF)
}
Expand Down
2 changes: 1 addition & 1 deletion frr-tools/metrics/collector/bgp.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func updateNeighborsMetrics(ch chan<- prometheus.Metric, neighbors map[string][]
if !n.Connected {
sessionUp = 0
}
peerLabel := fmt.Sprintf("%s:%d", n.IP.String(), n.Port)
peerLabel := n.IP.String()

ch <- prometheus.MustNewConstMetric(sessionUpDesc, prometheus.GaugeValue, float64(sessionUp), peerLabel, vrf)
ch <- prometheus.MustNewConstMetric(prefixesDesc, prometheus.GaugeValue, float64(n.PrefixSent), peerLabel, vrf)
Expand Down
4 changes: 2 additions & 2 deletions frr-tools/metrics/collector/bgp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var (
{
desc: "Output contains only IPv4 advertisements",
vtyshOutput: neighborsIPv4Only,
neighborIP: "172.18.0.4:179",
neighborIP: "172.18.0.4",
neighborVRF: "default",
announcedPrefixes: 3,
receivedPrefixes: 3,
Expand All @@ -95,7 +95,7 @@ var (
{
desc: "Output contains mixed IPv4 and IPv6 advertisements",
vtyshOutput: neighborsDual,
neighborIP: "172.18.0.4:180",
neighborIP: "172.18.0.4",
neighborVRF: "default",
announcedPrefixes: 6,
receivedPrefixes: 6,
Expand Down

0 comments on commit ae0cfff

Please sign in to comment.