Conversation
- Add circuit breaker pattern for fail-fast during outages - Configurable failure/success thresholds and open duration - Three states: Closed, Open, HalfOpen - Integrated with IggyClientWrapper reconnection logic - Add Prometheus metrics export (metrics-rs) - Counters: messages sent/polled, reconnects, circuit breaker events - Histograms: request/send/poll duration - Gauges: connection status, circuit breaker state - Configurable via METRICS_PORT (default: 9090, 0 = disabled) - Add request timeout propagation middleware - Clients specify timeout via X-Request-Timeout header (milliseconds) - Bounded: 100ms min, 5min max - RequestTimeoutExt trait for handler extraction - Fix empty X-Forwarded-For header handling - Empty/whitespace-only headers now return "unknown" - Prevents separate rate-limit buckets for empty headers - Add consumer ID upper bound validation - MAX_CONSUMER_ID = 1 billion - Catches likely misconfigurations 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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
Adds production-level resilience features including circuit breaker pattern, Prometheus metrics export, request timeout propagation, and fixes for edge cases in IP extraction and validation.
Type of Change
Changes Made
Circuit Breaker Pattern (
src/iggy_client/circuit_breaker.rs)IggyClientWrapper.with_reconnect()for fail-fast during outagesAppError::CircuitOpenerror type (returns 503)Prometheus Metrics (
src/metrics.rs)iggy_messages_sent_total,iggy_messages_polled_total,iggy_connection_reconnects_total,iggy_circuit_breaker_opens_totaliggy_request_duration_seconds,iggy_send_duration_seconds,iggy_poll_duration_secondsiggy_connection_status,iggy_circuit_breaker_stateMETRICS_PORT(default: 9090, 0 = disabled)Request Timeout Propagation (
src/middleware/timeout.rs)X-Request-Timeoutheader (milliseconds)RequestTimeoutExttrait for easy extraction in handlersBug Fixes
X-Forwarded-Forheaders now return "unknown" instead of empty stringValidation Improvements
MAX_CONSUMER_ID(1 billion) upper bound validationTesting
Test commands run:
Checklist
Code Quality
cargo fmt)cargo clippy -- -D warnings)Testing
Documentation
Security
New Configuration Options
CIRCUIT_BREAKER_FAILURE_THRESHOLD5CIRCUIT_BREAKER_SUCCESS_THRESHOLD2CIRCUIT_BREAKER_OPEN_DURATION_SECS30METRICS_PORT9090Additional Notes
init_metrics()call (noop if not initialized)