From 8742f1b44d445da731b14986663045b9067c4457 Mon Sep 17 00:00:00 2001 From: clawbot <35+clawbot@noreply.example.org> Date: Mon, 19 Oct 2026 12:41:15 +0200 Subject: [PATCH] Let bgp_peer_count drop to 0 (closes #92) SetBGPPeerCount stored a count only when it was above 0, so when the last peer the streamer knew of went down, bgp_peer_count kept its old value. It now stores every count from 0 up. Model: opus-5-5 --- internal/metrics/metrics.go | 2 +- internal/metrics/metrics_test.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/internal/metrics/metrics.go b/internal/metrics/metrics.go index ad04309..657d042 100644 --- a/internal/metrics/metrics.go +++ b/internal/metrics/metrics.go @@ -168,7 +168,7 @@ func (t *Tracker) RecordWithdrawal() { // SetBGPPeerCount updates the current BGP peer count func (t *Tracker) SetBGPPeerCount(count int) { // BGP peer count is always small (< 1000), so int32 is safe - if count > 0 && count < 1<<31 { + if count >= 0 && count < 1<<31 { t.bgpPeerCount.Store(int32(count)) } } diff --git a/internal/metrics/metrics_test.go b/internal/metrics/metrics_test.go index c301122..38ccae7 100644 --- a/internal/metrics/metrics_test.go +++ b/internal/metrics/metrics_test.go @@ -25,3 +25,18 @@ func TestReconnectCount(t *testing.T) { t.Fatalf("reconnect count = %d, want %d", got, wantReconnects) } } + +// TestBGPPeerCountDropsToZero sets a peer count of 1 and then 0, the way the +// streamer does when the last peer's session ends, and expects 0 back. +func TestBGPPeerCountDropsToZero(t *testing.T) { + t.Parallel() + + tracker := metrics.New() + + tracker.SetBGPPeerCount(1) + tracker.SetBGPPeerCount(0) + + if got := tracker.GetBGPPeerCount(); got != 0 { + t.Fatalf("peer count = %d after setting 0, want 0", got) + } +}