feat(diagnostics): implement unified DiagnosticsModule - #412
Merged
Lakes41 merged 1 commit intoJul 28, 2026
Conversation
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.
Here is a summary of the work accomplished:
1. DiagnosticsModule Implementation
• Created src/diagnostics/DiagnosticsModule.ts (and its types), which acts
as a central aggregator and event emitter.
• The module exposes getSnapshot(), which provides a holistic snapshot
encompassing:
• In-Flight Requests: Counts active requests to help track
deduplication behavior.
• Cache Statistics: Simple hit/miss counters.
• Rate Limits: Real-time throttling limits and current rate consumption.
• Circuit Breakers: Maps URLs to their respective health (open status,
failure count, cooldowns, latency).
2. Event Emitter
• The module provides .on(), .off(), and .emit() methods.
• Available events include circuitOpen, circuitClosed, rateLimitThrottled,
cacheHit, and cacheMiss.
3. Decoupled Aggregation
• Instead of subsystems like TokenBucket or HealthTracker needing to import
the DiagnosticsModule directly, we've used an observer pattern.
• Subsystems simply provide registration callbacks via their configs (e.g.,
onThrottled for rate limits or onCircuitOpen for circuit breakers) and the
GuildPassClient acts as the orchestrator to map those callbacks back to the
DiagnosticsModule's emitter.
• We also registered state provider functions (registerInFlightRequests,
registerRateLimit, etc.) on the Diagnostics module, ensuring the
diagnostics module observes the subcomponents, preventing circular
dependencies.
4. Tests and Validation
• Added tests/diagnostics.test.ts to ensure that getSnapshot() works
properly with at least three tracked operational states and that events
accurately fire for state transitions (e.g. simulating a circuit trip
manually triggering onCircuitOpen).
• Fixed all TS type and compilation errors resulting from strict event
typing and new properties.
closes #311