metrics: Prometheus endpoint on its own --metrics listener; the pod exposes it inside the cluster only

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
This commit is contained in:
2026-11-19 10:56:43 +01:00
co-authored by Claude Sonnet 5.5
parent b922808a51
commit c653ae4206
13 changed files with 306 additions and 3 deletions
+18
View File
@@ -4,6 +4,7 @@ import (
"context"
"log/slog"
"sync"
"sync/atomic"
"time"
pubsub "github.com/libp2p/go-libp2p-pubsub"
@@ -38,6 +39,12 @@ type peerGuard struct {
disconnect func(peer.ID)
self peer.ID
// Totals since the start, for the metrics.
dropped atomic.Uint64 // messages dropped for exceeding the rate
invalid atomic.Uint64 // messages rejected as invalid
bans atomic.Uint64 // peers banned
syncRefused atomic.Uint64 // sync requests refused
mu sync.Mutex
peers map[peer.ID]*peerCount
streams map[peer.ID]int // sync streams open per peer
@@ -107,6 +114,7 @@ func (g *peerGuard) admit(p peer.ID) bool {
if c.total <= maxPerWindow {
return true
}
g.dropped.Add(1)
if !c.noted {
c.noted = true
g.log.Warn("peer sends too much; dropping its messages until the minute is over",
@@ -117,6 +125,7 @@ func (g *peerGuard) admit(p peer.ID) bool {
// bad counts an invalid message from p and bans it past the limit.
func (g *peerGuard) bad(p peer.ID) {
g.invalid.Add(1)
g.mu.Lock()
c := g.count(p)
c.bad++
@@ -126,6 +135,7 @@ func (g *peerGuard) bad(p peer.ID) {
return
}
g.bl.Add(p)
g.bans.Add(1)
g.log.Warn("banned a peer that kept sending invalid messages", "peer", p,
"invalid_in_a_minute", maxBadPerWindow, "for", banFor)
if g.disconnect != nil {
@@ -146,6 +156,14 @@ const (
// peers asking too often and peers with too many streams open; otherwise it
// returns the function to call when the stream is done.
func (g *peerGuard) beginSync(p peer.ID) (end func(), ok bool) {
end, ok = g.beginSyncUncounted(p)
if !ok {
g.syncRefused.Add(1)
}
return end, ok
}
func (g *peerGuard) beginSyncUncounted(p peer.ID) (end func(), ok bool) {
if g.banned(p) {
return nil, false
}