Improves flow handling and adds runtime stats APIs
Refactors TCP and UDP flow managers to enhance analyzer selection and flow binding accuracy, including O(1) UDP stream rebinding by 5-tuple. Introduces runtime stats tracking for engine and ruleset operations, exposing new APIs for granular performance and error metrics. Optimizes GeoMatcher with result caching and supports efficient geosite set matching, reducing redundant computation in ruleset expressions.
This commit is contained in:
@@ -2,6 +2,7 @@ package engine
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync/atomic"
|
||||
|
||||
"git.difuse.io/Difuse/Mellaris/io"
|
||||
"git.difuse.io/Difuse/Mellaris/ruleset"
|
||||
@@ -13,6 +14,49 @@ type Engine interface {
|
||||
UpdateRuleset(ruleset.Ruleset) error
|
||||
// Run runs the engine, until an error occurs or the context is cancelled.
|
||||
Run(context.Context) error
|
||||
// Stats returns a consistent snapshot of runtime counters.
|
||||
Stats() Stats
|
||||
}
|
||||
|
||||
type OverflowPolicy string
|
||||
|
||||
const (
|
||||
OverflowPolicyAccept OverflowPolicy = "accept"
|
||||
OverflowPolicyDrop OverflowPolicy = "drop"
|
||||
OverflowPolicyBackpressure OverflowPolicy = "backpressure"
|
||||
)
|
||||
|
||||
type AnalyzerSelectionMode string
|
||||
|
||||
const (
|
||||
AnalyzerSelectionModeAlways AnalyzerSelectionMode = "always"
|
||||
AnalyzerSelectionModeSignature AnalyzerSelectionMode = "signature"
|
||||
)
|
||||
|
||||
type statsCounters struct {
|
||||
OverflowEvents atomic.Uint64
|
||||
OverflowAccepts atomic.Uint64
|
||||
OverflowDrops atomic.Uint64
|
||||
OverflowBackpressureEvents atomic.Uint64
|
||||
|
||||
AnalyzerSelectionsTotal atomic.Uint64
|
||||
AnalyzerSelectionsPruned atomic.Uint64
|
||||
|
||||
UDPTupleLookups atomic.Uint64
|
||||
UDPTupleHits atomic.Uint64
|
||||
}
|
||||
|
||||
type Stats struct {
|
||||
OverflowEvents uint64
|
||||
OverflowAccepts uint64
|
||||
OverflowDrops uint64
|
||||
OverflowBackpressureEvents uint64
|
||||
|
||||
AnalyzerSelectionsTotal uint64
|
||||
AnalyzerSelectionsPruned uint64
|
||||
|
||||
UDPTupleLookups uint64
|
||||
UDPTupleHits uint64
|
||||
}
|
||||
|
||||
// Config is the configuration for the engine.
|
||||
@@ -26,6 +70,8 @@ type Config struct {
|
||||
WorkerTCPMaxBufferedPagesTotal int
|
||||
WorkerTCPMaxBufferedPagesPerConn int
|
||||
WorkerUDPMaxStreams int
|
||||
OverflowPolicy OverflowPolicy
|
||||
AnalyzerSelectionMode AnalyzerSelectionMode
|
||||
}
|
||||
|
||||
// Logger is the combined logging interface for the engine, workers and analyzers.
|
||||
|
||||
Reference in New Issue
Block a user