Repository navigation
p2plimits: say a peer-scope connection refusal as a connection, not a stream - #988
kavishkartha05 wants to merge 1 commit into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request refactors peer blocking behavior in internal/p2plimits/streams.go to treat peer-scope blocks as connection refusals rather than stream refusals, updating the logging and metrics accordingly. The review feedback focuses on adhering to the repository style guide: specifically, ensuring that log lines for peer blocks include the peer identifier (Section 6, Rule 4) and that test assertions explicitly state both the observed and expected values (Section 3, Rule 8).
d8f3a85 to
002e1a9
Compare
… stream
libp2p calls MetricsReporter.BlockPeer from a connection scope's SetPeer,
when a connection is refused at its peer scope. A stream refused at its
peer scope arrives through BlockStream. StreamRefusals counted BlockPeer
under *_streams_refused_total{scope="peer"} and logged "[Stream] Refused
... the peer sees its stream reset", so a refused connection read as a
refused stream.
BlockPeer no longer counts in the stream counter. It logs a rate-limited
"[Conn] Refused N connection(s) at the peer scope" line instead, naming
the peer of the last refusal it counts. It stays out of the inbound
connection counters too: BlockPeer carries no direction.
The existing log test used BlockPeer as a synthetic empty-protocol case;
BlockStream covers that, so it uses BlockStream now. A new test covers
the [Conn] line, its once-per-interval limit and that the stream counter
gets no series. Test assertions state both the observed and the expected
value.
Fixes google#951
002e1a9 to
5ef4d6c
Compare
What
StreamRefusals.BlockPeerno longer counts under*_streams_refused_total{scope="peer"}and no longer logs the[Stream] Refused ... the peer sees its stream resetline. A peer-scope connection refusal is now a rate-limited[Conn] Refused N connection(s) at the peer scope since the last report: ...line (one perRefusalLogInterval, carrying the count since the last report). The now-unusedStreamScopePeerconstant is removed.Why
In go-libp2p v0.51.0 the resource manager calls
BlockPeeronly fromconnectionScope.SetPeer(rcmgr.go:826), i.e. when a connection is refused at its peer scope. A stream refused at its peer scope arrives asBlockStream. So connection refusals were showing up as stream refusals in the metric and the log. This follows the fix aojea described on #951: log it as a[Conn]line instead of counting it in*_streams_refused_total. It is left out of*_inbound_connections_refused_totalbecauseBlockPeercarries no connection direction, so counting it there could mislabel outbound refusals.TestStreamRefusalsLogOneProtocolOncePerIntervalonly usedBlockPeeras a synthetic "scope with no protocol" case, whichBlockStreamalready covers, so it usesBlockStreamnow. A new test,TestStreamRefusalsSayPeerScopeConnectionRefusalsApart, checks the[Conn]line, that it is logged once per interval with the accumulated count, and that the stream refusal counter gets no series.Fixes #951
Testing
go test -race -count 1 ./internal/p2plimits ./internal/node ./internal/router: pass.hack/lint.sh(golangci-lint v2.14.0 plus deadcode): 0 issues.gofmtandgo vetclean.TMPDIR=/tmp/am:internal/nodehas tests that fail on macOS's long default temp path (unix socket paths are limited to 103 bytes). They pass with a shortTMPDIRand are unrelated to this change.tests/integrationandmake e2e-testwere not run locally (the integration suite fails on my machine before this change too, for what looks like a local port conflict, andkind/batsare not installed); I'm relying on CI for those.Breaking changes
None to the API or wire format. Operators who alerted on
*_streams_refused_total{scope="peer"}will no longer see peer-scope connection refusals there; they are in the[Conn]log line.🤖 Generated with Claude Code