Documentation
¶
Overview ¶
Package ratelimitml provides machine learning extensions for advanced rate limiting
Index ¶
- Constants
- func GetPlugin() plugin.Plugin
- type AnomalyDetector
- type AnomalyEvent
- type BehaviorPrediction
- type CoordinatedAttack
- type Decision
- type HistoricalData
- type IsolationForest
- type IsolationNode
- type IsolationTree
- type MLBlock
- type MLMetrics
- func (m *MLMetrics) GetCurrentMetrics() map[string]interface{}
- func (m *MLMetrics) RecordAnomaly(clientIP string, score float64)
- func (m *MLMetrics) RecordLearningData(clientIP string)
- func (m *MLMetrics) RecordModelUpdate()
- func (m *MLMetrics) RecordPatternAnalysis()
- func (m *MLMetrics) RecordRequest(clientIP string, anomalyScore float64, decision Decision)
- type MLRateLimitConfig
- type NormalProfile
- type PatternAnalyzer
- type RateLimitCoordinator
- type RateLimitMLPlugin
- func (p *RateLimitMLPlugin) CreateMiddleware() (func(http.Handler) http.Handler, error)
- func (p *RateLimitMLPlugin) Dependencies() []plugin.PluginDependency
- func (p *RateLimitMLPlugin) Description() string
- func (p *RateLimitMLPlugin) Initialize(ctx context.Context, host plugin.PluginHost, config map[string]interface{}) error
- func (p *RateLimitMLPlugin) Name() string
- func (p *RateLimitMLPlugin) Priority() int
- func (p *RateLimitMLPlugin) Shutdown(ctx context.Context) error
- func (p *RateLimitMLPlugin) Version() string
- type TimeWindow
- type TrafficAnomaly
- type TrafficPattern
- type TrafficPredictor
Constants ¶
const ( PluginName = "ratelimit-ml" PluginVersion = "1.0.0" )
Plugin constants
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AnomalyDetector ¶
type AnomalyDetector struct {
// contains filtered or unexported fields
}
AnomalyDetector implements advanced anomaly detection
func NewAnomalyDetector ¶
func NewAnomalyDetector(modelPath string, threshold float64) *AnomalyDetector
NewAnomalyDetector creates a new anomaly detector
func (*AnomalyDetector) DetectAnomaly ¶
func (ad *AnomalyDetector) DetectAnomaly(pattern *TrafficPattern) float64
DetectAnomaly detects anomalies in traffic patterns
func (*AnomalyDetector) LoadModel ¶
func (ad *AnomalyDetector) LoadModel() error
LoadModel loads the ML model (placeholder implementation)
func (*AnomalyDetector) SaveModel ¶
func (ad *AnomalyDetector) SaveModel() error
SaveModel saves the ML model (placeholder implementation)
type AnomalyEvent ¶
type AnomalyEvent struct {
Timestamp time.Time
Score float64
Type string
Description string
Action string
}
AnomalyEvent represents a detected anomaly
type BehaviorPrediction ¶
type CoordinatedAttack ¶
type Decision ¶
type Decision struct {
Block bool
Reason string
Confidence float64
Duration time.Duration
Escalation int
}
Decision represents an ML-based rate limiting decision
type HistoricalData ¶
type IsolationForest ¶
type IsolationForest struct {
Trees []*IsolationTree
NumTrees int
SampleSize int
MaxDepth int
FeatureNames []string
AnomalyScores map[string]float64 // Cache for recent scores
}
IsolationForest represents the ensemble of isolation trees
type IsolationNode ¶
type IsolationNode struct {
IsLeaf bool
SplitFeature int
SplitValue float64
Left *IsolationNode
Right *IsolationNode
Size int // Number of samples at this node
}
IsolationNode represents a node in the isolation tree
type IsolationTree ¶
type IsolationTree struct {
Root *IsolationNode
PathLength map[string]float64
}
IsolationTree represents a single tree in the forest
type MLMetrics ¶
type MLMetrics struct {
AnomaliesDetected int64
PredictionsMade int64
ModelUpdates int64
TruePositives int64
FalsePositives int64
// contains filtered or unexported fields
}
MLMetrics collects and records ML-related metrics
func NewMLMetrics ¶
func NewMLMetrics() *MLMetrics
func (*MLMetrics) GetCurrentMetrics ¶
GetCurrentMetrics returns current metrics
func (*MLMetrics) RecordAnomaly ¶
RecordAnomaly records an anomaly detection
func (*MLMetrics) RecordLearningData ¶
RecordLearningData records new learning data
func (*MLMetrics) RecordModelUpdate ¶
func (m *MLMetrics) RecordModelUpdate()
RecordModelUpdate records a model update
func (*MLMetrics) RecordPatternAnalysis ¶
func (m *MLMetrics) RecordPatternAnalysis()
RecordPatternAnalysis records pattern analysis completion
type MLRateLimitConfig ¶
type MLRateLimitConfig struct {
Enabled bool `json:"enabled"`
ModelPath string `json:"modelPath"`
AnomalyThreshold float64 `json:"anomalyThreshold"`
PredictionWindow string `json:"predictionWindow"`
LearningEnabled bool `json:"learningEnabled"`
CoordinationEnabled bool `json:"coordinationEnabled"`
BlockDuration string `json:"blockDuration"`
EscalationMultiplier float64 `json:"escalationMultiplier"`
}
MLRateLimitConfig holds configuration
type NormalProfile ¶
type NormalProfile struct {
ClientIP string
AverageRate float64
StdDeviation float64
PeakHours []int
TypicalEndpoints map[string]float64
UserAgent string
LastSeen time.Time
}
NormalProfile represents normal traffic behavior
type PatternAnalyzer ¶
type PatternAnalyzer struct {
// contains filtered or unexported fields
}
PatternAnalyzer analyzes request patterns
func NewPatternAnalyzer ¶
func NewPatternAnalyzer() *PatternAnalyzer
func (*PatternAnalyzer) AnalyzeRequest ¶
func (pa *PatternAnalyzer) AnalyzeRequest(clientIP string, r *http.Request) *TrafficPattern
func (*PatternAnalyzer) GetActivePatterns ¶
func (pa *PatternAnalyzer) GetActivePatterns() map[string]*TrafficPattern
type RateLimitCoordinator ¶
type RateLimitCoordinator struct {
// contains filtered or unexported fields
}
RateLimitCoordinator coordinates with base rate limiter
func NewRateLimitCoordinator ¶
func NewRateLimitCoordinator() *RateLimitCoordinator
func (*RateLimitCoordinator) ApplyMLBlock ¶
func (rlc *RateLimitCoordinator) ApplyMLBlock(clientIP string, decision Decision)
type RateLimitMLPlugin ¶
type RateLimitMLPlugin struct {
// contains filtered or unexported fields
}
RateLimitMLPlugin extends rate limiting with ML-based anomaly detection
func (*RateLimitMLPlugin) CreateMiddleware ¶
CreateMiddleware creates the ML rate limiting middleware
func (*RateLimitMLPlugin) Dependencies ¶
func (p *RateLimitMLPlugin) Dependencies() []plugin.PluginDependency
Dependencies returns required dependencies
func (*RateLimitMLPlugin) Description ¶
func (p *RateLimitMLPlugin) Description() string
Description returns the plugin description
func (*RateLimitMLPlugin) Initialize ¶
func (p *RateLimitMLPlugin) Initialize(ctx context.Context, host plugin.PluginHost, config map[string]interface{}) error
Initialize implements the Plugin interface
func (*RateLimitMLPlugin) Name ¶
func (p *RateLimitMLPlugin) Name() string
Name returns the plugin name
func (*RateLimitMLPlugin) Priority ¶
func (p *RateLimitMLPlugin) Priority() int
Priority returns the plugin priority (higher numbers run later)
func (*RateLimitMLPlugin) Shutdown ¶
func (p *RateLimitMLPlugin) Shutdown(ctx context.Context) error
Shutdown gracefully stops the plugin
func (*RateLimitMLPlugin) Version ¶
func (p *RateLimitMLPlugin) Version() string
Version returns the plugin version
type TrafficAnomaly ¶
type TrafficPattern ¶
type TrafficPattern struct {
ClientIP string
RequestRate float64
BurstPattern []int
Periodicity float64
Entropy float64
EntropyScore float64 // Alias for Entropy
Predictability float64
AnomalyScore float64
IsAnomalous bool
LastUpdated time.Time
}
TrafficPattern represents analyzed traffic patterns
type TrafficPredictor ¶
type TrafficPredictor struct {
// contains filtered or unexported fields
}
TrafficPredictor predicts future traffic behavior
func NewTrafficPredictor ¶
func NewTrafficPredictor(window string) *TrafficPredictor
func (*TrafficPredictor) PredictBehavior ¶
func (tp *TrafficPredictor) PredictBehavior(pattern *TrafficPattern) *BehaviorPrediction