feat: Add conditional and router sinks for event routing#60
Merged
willibrandon merged 6 commits intomainfrom Aug 22, 2025
Merged
feat: Add conditional and router sinks for event routing#60willibrandon merged 6 commits intomainfrom
willibrandon merged 6 commits intomainfrom
Conversation
…lities - Add ConditionalSink for zero-overhead predicate-based routing (3.7ns when false) - Add RouterSink with FirstMatch/AllMatch modes and runtime route management - Implement route priority system and route groups for organization - Add PredicateBuilder for fluent predicate composition - Include route statistics tracking and TestEvent() for debugging - Add health checks (HealthCheckable interface) for all sinks - Implement CircuitBreakerSink with automatic failure recovery - Add Prometheus metrics exporter and Grafana dashboard template - Support JSON configuration for routing in appsettings.json - Add selflog support for diagnostics - Document 11 production routing patterns with examples The implementation provides enterprise-grade event routing with zero-overhead design, production monitoring, and resilience patterns. Routes can be managed at runtime, grouped for organization, and protected with circuit breakers.
Remove sync.RWMutex from RouterStats struct to make it safe to copy. Split into routerStatsInternal (with mutex) for internal use and RouterStats (without mutex) for public API.
The router was sharing slice references between goroutines when reading routes in Emit()/TestEvent() while RemoveRoute() was modifying the underlying array. Fixed by making defensive copies of the routes slice before releasing the mutex.
There was a problem hiding this comment.
Pull Request Overview
This PR implements comprehensive event routing infrastructure for mtlog, adding conditional and router sinks that enable sophisticated log event routing similar to Serilog's capabilities. The implementation brings production-ready routing with zero-overhead conditional filtering, flexible routing modes, health checks, circuit breakers, and monitoring integration.
Key Changes
- Zero-overhead conditional routing - 3.7ns when predicate returns false with built-in predicates and fluent predicate builder
- Flexible router sink - FirstMatch (exclusive) and AllMatch (broadcast) routing modes with priority-based route ordering
- Production resilience features - Health checks, circuit breakers, fallback sinks, and comprehensive error handling
Reviewed Changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| sinks/conditional.go | Core conditional sink implementation with panic recovery and built-in predicates |
| sinks/router.go | Advanced router sink with dynamic route management and statistics tracking |
| sinks/predicate_builder.go | Fluent API for building complex routing predicates with logical operators |
| sinks/health.go | Health check infrastructure for monitoring sink connectivity and status |
| sinks/circuit_breaker.go | Circuit breaker implementation for resilient logging with fallback mechanisms |
| sinks/router_metrics.go | Prometheus metrics exporter for router statistics and monitoring integration |
| options.go | Integration with mtlog's option system for easy configuration |
| configuration/builder.go | JSON configuration support for conditional and router sinks |
| examples/ | Comprehensive examples demonstrating routing patterns and usage scenarios |
| docs/ | Complete documentation including routing patterns and best practices |
Comments suppressed due to low confidence (1)
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
- Replace inefficient recursive contains() with strings.Contains() - Fix route naming to avoid rune conversion issues for indices > 25 - Use strings.HasPrefix() instead of manual string slicing
…integration tests
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.
Description
Implements advanced event routing infrastructure with conditional and router sinks, with production-ready features including route priorities, groups, health checks, circuit breakers, and Prometheus/Grafana integration for monitoring.
Key highlights:
Type of change
Checklist
go test ./...)golangci-lint run)Additional notes
Fixes #43