feat(federation): ADR-F6 stream connection pool (RECON-F6)#44
Merged
Conversation
Adds semaphore-bounded concurrent stream limit (D1), token-bucket admission rate limiter (D2), and Prometheus metrics (D4) to FederationServer. Env vars FEDERATION_MAX_CONCURRENT_STREAMS (default 50, range 1-1000) and FEDERATION_ADMISSION_RATE (default 5, must be >0) configure the pool at startup. ActiveStreamCount() exposes the current gauge value for health checks. Five unit tests cover: semaphore rejection at limit, concurrent admission up to limit, activeCount increment/decrement on connect/disconnect, and both env-var parser edge cases.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
FEDERATION_MAX_CONCURRENT_STREAMS(default 50, range 1-1000); 3rd+ concurrent stream receivesRESOURCE_EXHAUSTEDgolang.org/x/time/rate) enforcesFEDERATION_ADMISSION_RATEconnections/sec (default 5, burst 2x); over-rate streams receiveRESOURCE_EXHAUSTEDconductor_federation_stream_active_countPrometheus gauge +conductor_federation_stream_reconnects_totalcounter vec (labeledcluster_id), registered onctrlmetrics.RegistryParseFederationMaxStreams/ParseFederationAdmissionRate: env-var parsers with range validation and safe defaultsActiveStreamCount() int64: health-check accessor returning current atomic active countgolang.org/x/time v0.14.0promoted from indirect to direct dependencyTest plan
TestFederationServer_RejectsWhenLimitReached: limit=2, 3rd acquire returns falseTestFederationServer_AdmitsUpToLimit: 2 goroutines both admittedTestActiveStreamCount_DecreasesOnDisconnect: atomic inc/dec + semaphore round-tripTestParseFederationMaxStreams: 7 cases (empty, valid, out-of-range, invalid)TestParseFederationAdmissionRate: 6 cases (empty, valid, zero, negative, invalid)Closes RECON-F6.