chore: align slurp config and scaffolding

This commit is contained in:
anthonyrawlins
2025-09-27 21:03:12 +10:00
parent acc4361463
commit 4a77862289
47 changed files with 5133 additions and 4274 deletions

View File

@@ -15,48 +15,48 @@ import (
// MonitoringSystem provides comprehensive monitoring for the distributed context system
type MonitoringSystem struct {
mu sync.RWMutex
config *config.Config
metrics *MetricsCollector
healthChecks *HealthCheckManager
alertManager *AlertManager
dashboard *DashboardServer
logManager *LogManager
traceManager *TraceManager
mu sync.RWMutex
config *config.Config
metrics *MetricsCollector
healthChecks *HealthCheckManager
alertManager *AlertManager
dashboard *DashboardServer
logManager *LogManager
traceManager *TraceManager
// State
running bool
monitoringPort int
updateInterval time.Duration
retentionPeriod time.Duration
running bool
monitoringPort int
updateInterval time.Duration
retentionPeriod time.Duration
}
// MetricsCollector collects and aggregates system metrics
type MetricsCollector struct {
mu sync.RWMutex
timeSeries map[string]*TimeSeries
counters map[string]*Counter
gauges map[string]*Gauge
histograms map[string]*Histogram
customMetrics map[string]*CustomMetric
aggregatedStats *AggregatedStatistics
exporters []MetricsExporter
lastCollection time.Time
mu sync.RWMutex
timeSeries map[string]*TimeSeries
counters map[string]*Counter
gauges map[string]*Gauge
histograms map[string]*Histogram
customMetrics map[string]*CustomMetric
aggregatedStats *AggregatedStatistics
exporters []MetricsExporter
lastCollection time.Time
}
// TimeSeries represents a time-series metric
type TimeSeries struct {
Name string `json:"name"`
Labels map[string]string `json:"labels"`
DataPoints []*TimeSeriesPoint `json:"data_points"`
Name string `json:"name"`
Labels map[string]string `json:"labels"`
DataPoints []*TimeSeriesPoint `json:"data_points"`
RetentionTTL time.Duration `json:"retention_ttl"`
LastUpdated time.Time `json:"last_updated"`
LastUpdated time.Time `json:"last_updated"`
}
// TimeSeriesPoint represents a single data point in a time series
type TimeSeriesPoint struct {
Timestamp time.Time `json:"timestamp"`
Value float64 `json:"value"`
Timestamp time.Time `json:"timestamp"`
Value float64 `json:"value"`
Labels map[string]string `json:"labels,omitempty"`
}
@@ -64,7 +64,7 @@ type TimeSeriesPoint struct {
type Counter struct {
Name string `json:"name"`
Value int64 `json:"value"`
Rate float64 `json:"rate"` // per second
Rate float64 `json:"rate"` // per second
Labels map[string]string `json:"labels"`
LastUpdated time.Time `json:"last_updated"`
}
@@ -82,13 +82,13 @@ type Gauge struct {
// Histogram represents distribution of values
type Histogram struct {
Name string `json:"name"`
Buckets map[float64]int64 `json:"buckets"`
Count int64 `json:"count"`
Sum float64 `json:"sum"`
Labels map[string]string `json:"labels"`
Name string `json:"name"`
Buckets map[float64]int64 `json:"buckets"`
Count int64 `json:"count"`
Sum float64 `json:"sum"`
Labels map[string]string `json:"labels"`
Percentiles map[float64]float64 `json:"percentiles"`
LastUpdated time.Time `json:"last_updated"`
LastUpdated time.Time `json:"last_updated"`
}
// CustomMetric represents application-specific metrics
@@ -114,81 +114,81 @@ const (
// AggregatedStatistics provides high-level system statistics
type AggregatedStatistics struct {
SystemOverview *SystemOverview `json:"system_overview"`
PerformanceMetrics *PerformanceOverview `json:"performance_metrics"`
HealthMetrics *HealthOverview `json:"health_metrics"`
ErrorMetrics *ErrorOverview `json:"error_metrics"`
ResourceMetrics *ResourceOverview `json:"resource_metrics"`
NetworkMetrics *NetworkOverview `json:"network_metrics"`
LastUpdated time.Time `json:"last_updated"`
SystemOverview *SystemOverview `json:"system_overview"`
PerformanceMetrics *PerformanceOverview `json:"performance_metrics"`
HealthMetrics *HealthOverview `json:"health_metrics"`
ErrorMetrics *ErrorOverview `json:"error_metrics"`
ResourceMetrics *ResourceOverview `json:"resource_metrics"`
NetworkMetrics *NetworkOverview `json:"network_metrics"`
LastUpdated time.Time `json:"last_updated"`
}
// SystemOverview provides system-wide overview metrics
type SystemOverview struct {
TotalNodes int `json:"total_nodes"`
HealthyNodes int `json:"healthy_nodes"`
TotalContexts int64 `json:"total_contexts"`
DistributedContexts int64 `json:"distributed_contexts"`
ReplicationFactor float64 `json:"average_replication_factor"`
SystemUptime time.Duration `json:"system_uptime"`
ClusterVersion string `json:"cluster_version"`
LastRestart time.Time `json:"last_restart"`
TotalNodes int `json:"total_nodes"`
HealthyNodes int `json:"healthy_nodes"`
TotalContexts int64 `json:"total_contexts"`
DistributedContexts int64 `json:"distributed_contexts"`
ReplicationFactor float64 `json:"average_replication_factor"`
SystemUptime time.Duration `json:"system_uptime"`
ClusterVersion string `json:"cluster_version"`
LastRestart time.Time `json:"last_restart"`
}
// PerformanceOverview provides performance metrics
type PerformanceOverview struct {
RequestsPerSecond float64 `json:"requests_per_second"`
AverageResponseTime time.Duration `json:"average_response_time"`
P95ResponseTime time.Duration `json:"p95_response_time"`
P99ResponseTime time.Duration `json:"p99_response_time"`
Throughput float64 `json:"throughput_mbps"`
CacheHitRate float64 `json:"cache_hit_rate"`
QueueDepth int `json:"queue_depth"`
ActiveConnections int `json:"active_connections"`
RequestsPerSecond float64 `json:"requests_per_second"`
AverageResponseTime time.Duration `json:"average_response_time"`
P95ResponseTime time.Duration `json:"p95_response_time"`
P99ResponseTime time.Duration `json:"p99_response_time"`
Throughput float64 `json:"throughput_mbps"`
CacheHitRate float64 `json:"cache_hit_rate"`
QueueDepth int `json:"queue_depth"`
ActiveConnections int `json:"active_connections"`
}
// HealthOverview provides health-related metrics
type HealthOverview struct {
OverallHealthScore float64 `json:"overall_health_score"`
ComponentHealth map[string]float64 `json:"component_health"`
FailedHealthChecks int `json:"failed_health_checks"`
LastHealthCheck time.Time `json:"last_health_check"`
HealthTrend string `json:"health_trend"` // improving, stable, degrading
CriticalAlerts int `json:"critical_alerts"`
WarningAlerts int `json:"warning_alerts"`
OverallHealthScore float64 `json:"overall_health_score"`
ComponentHealth map[string]float64 `json:"component_health"`
FailedHealthChecks int `json:"failed_health_checks"`
LastHealthCheck time.Time `json:"last_health_check"`
HealthTrend string `json:"health_trend"` // improving, stable, degrading
CriticalAlerts int `json:"critical_alerts"`
WarningAlerts int `json:"warning_alerts"`
}
// ErrorOverview provides error-related metrics
type ErrorOverview struct {
TotalErrors int64 `json:"total_errors"`
ErrorRate float64 `json:"error_rate"`
ErrorsByType map[string]int64 `json:"errors_by_type"`
ErrorsByComponent map[string]int64 `json:"errors_by_component"`
LastError *ErrorEvent `json:"last_error"`
ErrorTrend string `json:"error_trend"` // increasing, stable, decreasing
TotalErrors int64 `json:"total_errors"`
ErrorRate float64 `json:"error_rate"`
ErrorsByType map[string]int64 `json:"errors_by_type"`
ErrorsByComponent map[string]int64 `json:"errors_by_component"`
LastError *ErrorEvent `json:"last_error"`
ErrorTrend string `json:"error_trend"` // increasing, stable, decreasing
}
// ResourceOverview provides resource utilization metrics
type ResourceOverview struct {
CPUUtilization float64 `json:"cpu_utilization"`
MemoryUtilization float64 `json:"memory_utilization"`
DiskUtilization float64 `json:"disk_utilization"`
NetworkUtilization float64 `json:"network_utilization"`
StorageUsed int64 `json:"storage_used_bytes"`
StorageAvailable int64 `json:"storage_available_bytes"`
FileDescriptors int `json:"open_file_descriptors"`
Goroutines int `json:"goroutines"`
CPUUtilization float64 `json:"cpu_utilization"`
MemoryUtilization float64 `json:"memory_utilization"`
DiskUtilization float64 `json:"disk_utilization"`
NetworkUtilization float64 `json:"network_utilization"`
StorageUsed int64 `json:"storage_used_bytes"`
StorageAvailable int64 `json:"storage_available_bytes"`
FileDescriptors int `json:"open_file_descriptors"`
Goroutines int `json:"goroutines"`
}
// NetworkOverview provides network-related metrics
type NetworkOverview struct {
TotalConnections int `json:"total_connections"`
ActiveConnections int `json:"active_connections"`
BandwidthUtilization float64 `json:"bandwidth_utilization"`
PacketLossRate float64 `json:"packet_loss_rate"`
AverageLatency time.Duration `json:"average_latency"`
NetworkPartitions int `json:"network_partitions"`
DataTransferred int64 `json:"data_transferred_bytes"`
TotalConnections int `json:"total_connections"`
ActiveConnections int `json:"active_connections"`
BandwidthUtilization float64 `json:"bandwidth_utilization"`
PacketLossRate float64 `json:"packet_loss_rate"`
AverageLatency time.Duration `json:"average_latency"`
NetworkPartitions int `json:"network_partitions"`
DataTransferred int64 `json:"data_transferred_bytes"`
}
// MetricsExporter exports metrics to external systems
@@ -200,49 +200,49 @@ type MetricsExporter interface {
// HealthCheckManager manages system health checks
type HealthCheckManager struct {
mu sync.RWMutex
healthChecks map[string]*HealthCheck
checkResults map[string]*HealthCheckResult
schedules map[string]*HealthCheckSchedule
running bool
mu sync.RWMutex
healthChecks map[string]*HealthCheck
checkResults map[string]*HealthCheckResult
schedules map[string]*HealthCheckSchedule
running bool
}
// HealthCheck represents a single health check
type HealthCheck struct {
Name string `json:"name"`
Description string `json:"description"`
CheckType HealthCheckType `json:"check_type"`
Target string `json:"target"`
Timeout time.Duration `json:"timeout"`
Interval time.Duration `json:"interval"`
Retries int `json:"retries"`
Metadata map[string]interface{} `json:"metadata"`
Enabled bool `json:"enabled"`
CheckFunction func(context.Context) (*HealthCheckResult, error) `json:"-"`
Name string `json:"name"`
Description string `json:"description"`
CheckType HealthCheckType `json:"check_type"`
Target string `json:"target"`
Timeout time.Duration `json:"timeout"`
Interval time.Duration `json:"interval"`
Retries int `json:"retries"`
Metadata map[string]interface{} `json:"metadata"`
Enabled bool `json:"enabled"`
CheckFunction func(context.Context) (*HealthCheckResult, error) `json:"-"`
}
// HealthCheckType represents different types of health checks
type HealthCheckType string
const (
HealthCheckTypeHTTP HealthCheckType = "http"
HealthCheckTypeTCP HealthCheckType = "tcp"
HealthCheckTypeCustom HealthCheckType = "custom"
HealthCheckTypeComponent HealthCheckType = "component"
HealthCheckTypeDatabase HealthCheckType = "database"
HealthCheckTypeService HealthCheckType = "service"
HealthCheckTypeHTTP HealthCheckType = "http"
HealthCheckTypeTCP HealthCheckType = "tcp"
HealthCheckTypeCustom HealthCheckType = "custom"
HealthCheckTypeComponent HealthCheckType = "component"
HealthCheckTypeDatabase HealthCheckType = "database"
HealthCheckTypeService HealthCheckType = "service"
)
// HealthCheckResult represents the result of a health check
type HealthCheckResult struct {
CheckName string `json:"check_name"`
Status HealthCheckStatus `json:"status"`
ResponseTime time.Duration `json:"response_time"`
Message string `json:"message"`
Details map[string]interface{} `json:"details"`
Error string `json:"error,omitempty"`
Timestamp time.Time `json:"timestamp"`
Attempt int `json:"attempt"`
CheckName string `json:"check_name"`
Status HealthCheckStatus `json:"status"`
ResponseTime time.Duration `json:"response_time"`
Message string `json:"message"`
Details map[string]interface{} `json:"details"`
Error string `json:"error,omitempty"`
Timestamp time.Time `json:"timestamp"`
Attempt int `json:"attempt"`
}
// HealthCheckStatus represents the status of a health check
@@ -258,45 +258,45 @@ const (
// HealthCheckSchedule defines when health checks should run
type HealthCheckSchedule struct {
CheckName string `json:"check_name"`
Interval time.Duration `json:"interval"`
NextRun time.Time `json:"next_run"`
LastRun time.Time `json:"last_run"`
Enabled bool `json:"enabled"`
FailureCount int `json:"failure_count"`
CheckName string `json:"check_name"`
Interval time.Duration `json:"interval"`
NextRun time.Time `json:"next_run"`
LastRun time.Time `json:"last_run"`
Enabled bool `json:"enabled"`
FailureCount int `json:"failure_count"`
}
// AlertManager manages system alerts and notifications
type AlertManager struct {
mu sync.RWMutex
alertRules map[string]*AlertRule
activeAlerts map[string]*Alert
alertHistory []*Alert
notifiers []AlertNotifier
silences map[string]*AlertSilence
running bool
mu sync.RWMutex
alertRules map[string]*AlertRule
activeAlerts map[string]*Alert
alertHistory []*Alert
notifiers []AlertNotifier
silences map[string]*AlertSilence
running bool
}
// AlertRule defines conditions for triggering alerts
type AlertRule struct {
Name string `json:"name"`
Description string `json:"description"`
Severity AlertSeverity `json:"severity"`
Conditions []*AlertCondition `json:"conditions"`
Duration time.Duration `json:"duration"` // How long condition must persist
Cooldown time.Duration `json:"cooldown"` // Minimum time between alerts
Labels map[string]string `json:"labels"`
Annotations map[string]string `json:"annotations"`
Enabled bool `json:"enabled"`
LastTriggered *time.Time `json:"last_triggered,omitempty"`
Name string `json:"name"`
Description string `json:"description"`
Severity AlertSeverity `json:"severity"`
Conditions []*AlertCondition `json:"conditions"`
Duration time.Duration `json:"duration"` // How long condition must persist
Cooldown time.Duration `json:"cooldown"` // Minimum time between alerts
Labels map[string]string `json:"labels"`
Annotations map[string]string `json:"annotations"`
Enabled bool `json:"enabled"`
LastTriggered *time.Time `json:"last_triggered,omitempty"`
}
// AlertCondition defines a single condition for an alert
type AlertCondition struct {
MetricName string `json:"metric_name"`
Operator ConditionOperator `json:"operator"`
Threshold float64 `json:"threshold"`
Duration time.Duration `json:"duration"`
MetricName string `json:"metric_name"`
Operator ConditionOperator `json:"operator"`
Threshold float64 `json:"threshold"`
Duration time.Duration `json:"duration"`
}
// ConditionOperator represents comparison operators for alert conditions
@@ -313,39 +313,39 @@ const (
// Alert represents an active alert
type Alert struct {
ID string `json:"id"`
RuleName string `json:"rule_name"`
Severity AlertSeverity `json:"severity"`
Status AlertStatus `json:"status"`
Message string `json:"message"`
Details map[string]interface{} `json:"details"`
Labels map[string]string `json:"labels"`
Annotations map[string]string `json:"annotations"`
StartsAt time.Time `json:"starts_at"`
EndsAt *time.Time `json:"ends_at,omitempty"`
LastUpdated time.Time `json:"last_updated"`
AckBy string `json:"acknowledged_by,omitempty"`
AckAt *time.Time `json:"acknowledged_at,omitempty"`
ID string `json:"id"`
RuleName string `json:"rule_name"`
Severity AlertSeverity `json:"severity"`
Status AlertStatus `json:"status"`
Message string `json:"message"`
Details map[string]interface{} `json:"details"`
Labels map[string]string `json:"labels"`
Annotations map[string]string `json:"annotations"`
StartsAt time.Time `json:"starts_at"`
EndsAt *time.Time `json:"ends_at,omitempty"`
LastUpdated time.Time `json:"last_updated"`
AckBy string `json:"acknowledged_by,omitempty"`
AckAt *time.Time `json:"acknowledged_at,omitempty"`
}
// AlertSeverity represents the severity level of an alert
type AlertSeverity string
const (
SeverityInfo AlertSeverity = "info"
SeverityWarning AlertSeverity = "warning"
SeverityError AlertSeverity = "error"
SeverityCritical AlertSeverity = "critical"
AlertAlertSeverityInfo AlertSeverity = "info"
AlertAlertSeverityWarning AlertSeverity = "warning"
AlertAlertSeverityError AlertSeverity = "error"
AlertAlertSeverityCritical AlertSeverity = "critical"
)
// AlertStatus represents the current status of an alert
type AlertStatus string
const (
AlertStatusFiring AlertStatus = "firing"
AlertStatusResolved AlertStatus = "resolved"
AlertStatusFiring AlertStatus = "firing"
AlertStatusResolved AlertStatus = "resolved"
AlertStatusAcknowledged AlertStatus = "acknowledged"
AlertStatusSilenced AlertStatus = "silenced"
AlertStatusSilenced AlertStatus = "silenced"
)
// AlertNotifier sends alert notifications
@@ -357,64 +357,64 @@ type AlertNotifier interface {
// AlertSilence represents a silenced alert
type AlertSilence struct {
ID string `json:"id"`
Matchers map[string]string `json:"matchers"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
CreatedBy string `json:"created_by"`
Comment string `json:"comment"`
Active bool `json:"active"`
ID string `json:"id"`
Matchers map[string]string `json:"matchers"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
CreatedBy string `json:"created_by"`
Comment string `json:"comment"`
Active bool `json:"active"`
}
// DashboardServer provides web-based monitoring dashboard
type DashboardServer struct {
mu sync.RWMutex
server *http.Server
dashboards map[string]*Dashboard
widgets map[string]*Widget
customPages map[string]*CustomPage
running bool
port int
mu sync.RWMutex
server *http.Server
dashboards map[string]*Dashboard
widgets map[string]*Widget
customPages map[string]*CustomPage
running bool
port int
}
// Dashboard represents a monitoring dashboard
type Dashboard struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Widgets []*Widget `json:"widgets"`
Layout *DashboardLayout `json:"layout"`
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Widgets []*Widget `json:"widgets"`
Layout *DashboardLayout `json:"layout"`
Settings *DashboardSettings `json:"settings"`
CreatedBy string `json:"created_by"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
CreatedBy string `json:"created_by"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// Widget represents a dashboard widget
type Widget struct {
ID string `json:"id"`
Type WidgetType `json:"type"`
Title string `json:"title"`
DataSource string `json:"data_source"`
Query string `json:"query"`
Settings map[string]interface{} `json:"settings"`
Position *WidgetPosition `json:"position"`
RefreshRate time.Duration `json:"refresh_rate"`
LastUpdated time.Time `json:"last_updated"`
ID string `json:"id"`
Type WidgetType `json:"type"`
Title string `json:"title"`
DataSource string `json:"data_source"`
Query string `json:"query"`
Settings map[string]interface{} `json:"settings"`
Position *WidgetPosition `json:"position"`
RefreshRate time.Duration `json:"refresh_rate"`
LastUpdated time.Time `json:"last_updated"`
}
// WidgetType represents different types of dashboard widgets
type WidgetType string
const (
WidgetTypeMetric WidgetType = "metric"
WidgetTypeChart WidgetType = "chart"
WidgetTypeTable WidgetType = "table"
WidgetTypeAlert WidgetType = "alert"
WidgetTypeHealth WidgetType = "health"
WidgetTypeTopology WidgetType = "topology"
WidgetTypeLog WidgetType = "log"
WidgetTypeCustom WidgetType = "custom"
WidgetTypeMetric WidgetType = "metric"
WidgetTypeChart WidgetType = "chart"
WidgetTypeTable WidgetType = "table"
WidgetTypeAlert WidgetType = "alert"
WidgetTypeHealth WidgetType = "health"
WidgetTypeTopology WidgetType = "topology"
WidgetTypeLog WidgetType = "log"
WidgetTypeCustom WidgetType = "custom"
)
// WidgetPosition defines widget position and size
@@ -427,11 +427,11 @@ type WidgetPosition struct {
// DashboardLayout defines dashboard layout settings
type DashboardLayout struct {
Columns int `json:"columns"`
RowHeight int `json:"row_height"`
Margins [2]int `json:"margins"` // [x, y]
Spacing [2]int `json:"spacing"` // [x, y]
Breakpoints map[string]int `json:"breakpoints"`
Columns int `json:"columns"`
RowHeight int `json:"row_height"`
Margins [2]int `json:"margins"` // [x, y]
Spacing [2]int `json:"spacing"` // [x, y]
Breakpoints map[string]int `json:"breakpoints"`
}
// DashboardSettings contains dashboard configuration
@@ -446,43 +446,43 @@ type DashboardSettings struct {
// CustomPage represents a custom monitoring page
type CustomPage struct {
Path string `json:"path"`
Title string `json:"title"`
Content string `json:"content"`
ContentType string `json:"content_type"`
Handler http.HandlerFunc `json:"-"`
Path string `json:"path"`
Title string `json:"title"`
Content string `json:"content"`
ContentType string `json:"content_type"`
Handler http.HandlerFunc `json:"-"`
}
// LogManager manages system logs and log analysis
type LogManager struct {
mu sync.RWMutex
logSources map[string]*LogSource
logEntries []*LogEntry
logAnalyzers []LogAnalyzer
mu sync.RWMutex
logSources map[string]*LogSource
logEntries []*LogEntry
logAnalyzers []LogAnalyzer
retentionPolicy *LogRetentionPolicy
running bool
running bool
}
// LogSource represents a source of log data
type LogSource struct {
Name string `json:"name"`
Type LogSourceType `json:"type"`
Location string `json:"location"`
Format LogFormat `json:"format"`
Labels map[string]string `json:"labels"`
Enabled bool `json:"enabled"`
LastRead time.Time `json:"last_read"`
Name string `json:"name"`
Type LogSourceType `json:"type"`
Location string `json:"location"`
Format LogFormat `json:"format"`
Labels map[string]string `json:"labels"`
Enabled bool `json:"enabled"`
LastRead time.Time `json:"last_read"`
}
// LogSourceType represents different types of log sources
type LogSourceType string
const (
LogSourceTypeFile LogSourceType = "file"
LogSourceTypeHTTP LogSourceType = "http"
LogSourceTypeStream LogSourceType = "stream"
LogSourceTypeDatabase LogSourceType = "database"
LogSourceTypeCustom LogSourceType = "custom"
LogSourceTypeFile LogSourceType = "file"
LogSourceTypeHTTP LogSourceType = "http"
LogSourceTypeStream LogSourceType = "stream"
LogSourceTypeDatabase LogSourceType = "database"
LogSourceTypeCustom LogSourceType = "custom"
)
// LogFormat represents log entry format
@@ -497,14 +497,14 @@ const (
// LogEntry represents a single log entry
type LogEntry struct {
Timestamp time.Time `json:"timestamp"`
Level LogLevel `json:"level"`
Source string `json:"source"`
Message string `json:"message"`
Fields map[string]interface{} `json:"fields"`
Labels map[string]string `json:"labels"`
TraceID string `json:"trace_id,omitempty"`
SpanID string `json:"span_id,omitempty"`
Timestamp time.Time `json:"timestamp"`
Level LogLevel `json:"level"`
Source string `json:"source"`
Message string `json:"message"`
Fields map[string]interface{} `json:"fields"`
Labels map[string]string `json:"labels"`
TraceID string `json:"trace_id,omitempty"`
SpanID string `json:"span_id,omitempty"`
}
// LogLevel represents log entry severity
@@ -527,22 +527,22 @@ type LogAnalyzer interface {
// LogAnalysisResult represents the result of log analysis
type LogAnalysisResult struct {
AnalyzerName string `json:"analyzer_name"`
Anomalies []*LogAnomaly `json:"anomalies"`
Patterns []*LogPattern `json:"patterns"`
Statistics *LogStatistics `json:"statistics"`
Recommendations []string `json:"recommendations"`
AnalyzedAt time.Time `json:"analyzed_at"`
AnalyzerName string `json:"analyzer_name"`
Anomalies []*LogAnomaly `json:"anomalies"`
Patterns []*LogPattern `json:"patterns"`
Statistics *LogStatistics `json:"statistics"`
Recommendations []string `json:"recommendations"`
AnalyzedAt time.Time `json:"analyzed_at"`
}
// LogAnomaly represents detected log anomaly
type LogAnomaly struct {
Type AnomalyType `json:"type"`
Severity AlertSeverity `json:"severity"`
Description string `json:"description"`
Entries []*LogEntry `json:"entries"`
Confidence float64 `json:"confidence"`
DetectedAt time.Time `json:"detected_at"`
Type AnomalyType `json:"type"`
Severity AlertSeverity `json:"severity"`
Description string `json:"description"`
Entries []*LogEntry `json:"entries"`
Confidence float64 `json:"confidence"`
DetectedAt time.Time `json:"detected_at"`
}
// AnomalyType represents different types of log anomalies
@@ -558,38 +558,38 @@ const (
// LogPattern represents detected log pattern
type LogPattern struct {
Pattern string `json:"pattern"`
Frequency int `json:"frequency"`
LastSeen time.Time `json:"last_seen"`
Sources []string `json:"sources"`
Confidence float64 `json:"confidence"`
Pattern string `json:"pattern"`
Frequency int `json:"frequency"`
LastSeen time.Time `json:"last_seen"`
Sources []string `json:"sources"`
Confidence float64 `json:"confidence"`
}
// LogStatistics provides log statistics
type LogStatistics struct {
TotalEntries int64 `json:"total_entries"`
EntriesByLevel map[LogLevel]int64 `json:"entries_by_level"`
EntriesBySource map[string]int64 `json:"entries_by_source"`
ErrorRate float64 `json:"error_rate"`
AverageRate float64 `json:"average_rate"`
TimeRange [2]time.Time `json:"time_range"`
TotalEntries int64 `json:"total_entries"`
EntriesByLevel map[LogLevel]int64 `json:"entries_by_level"`
EntriesBySource map[string]int64 `json:"entries_by_source"`
ErrorRate float64 `json:"error_rate"`
AverageRate float64 `json:"average_rate"`
TimeRange [2]time.Time `json:"time_range"`
}
// LogRetentionPolicy defines log retention rules
type LogRetentionPolicy struct {
RetentionPeriod time.Duration `json:"retention_period"`
MaxEntries int64 `json:"max_entries"`
CompressionAge time.Duration `json:"compression_age"`
ArchiveAge time.Duration `json:"archive_age"`
Rules []*RetentionRule `json:"rules"`
RetentionPeriod time.Duration `json:"retention_period"`
MaxEntries int64 `json:"max_entries"`
CompressionAge time.Duration `json:"compression_age"`
ArchiveAge time.Duration `json:"archive_age"`
Rules []*RetentionRule `json:"rules"`
}
// RetentionRule defines specific retention rules
type RetentionRule struct {
Name string `json:"name"`
Condition string `json:"condition"` // Query expression
Retention time.Duration `json:"retention"`
Action RetentionAction `json:"action"`
Name string `json:"name"`
Condition string `json:"condition"` // Query expression
Retention time.Duration `json:"retention"`
Action RetentionAction `json:"action"`
}
// RetentionAction represents retention actions
@@ -603,47 +603,47 @@ const (
// TraceManager manages distributed tracing
type TraceManager struct {
mu sync.RWMutex
traces map[string]*Trace
spans map[string]*Span
samplers []TraceSampler
exporters []TraceExporter
running bool
mu sync.RWMutex
traces map[string]*Trace
spans map[string]*Span
samplers []TraceSampler
exporters []TraceExporter
running bool
}
// Trace represents a distributed trace
type Trace struct {
TraceID string `json:"trace_id"`
Spans []*Span `json:"spans"`
Duration time.Duration `json:"duration"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
Status TraceStatus `json:"status"`
Tags map[string]string `json:"tags"`
Operations []string `json:"operations"`
TraceID string `json:"trace_id"`
Spans []*Span `json:"spans"`
Duration time.Duration `json:"duration"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
Status TraceStatus `json:"status"`
Tags map[string]string `json:"tags"`
Operations []string `json:"operations"`
}
// Span represents a single span in a trace
type Span struct {
SpanID string `json:"span_id"`
TraceID string `json:"trace_id"`
ParentID string `json:"parent_id,omitempty"`
Operation string `json:"operation"`
Service string `json:"service"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
Duration time.Duration `json:"duration"`
Status SpanStatus `json:"status"`
Tags map[string]string `json:"tags"`
Logs []*SpanLog `json:"logs"`
SpanID string `json:"span_id"`
TraceID string `json:"trace_id"`
ParentID string `json:"parent_id,omitempty"`
Operation string `json:"operation"`
Service string `json:"service"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
Duration time.Duration `json:"duration"`
Status SpanStatus `json:"status"`
Tags map[string]string `json:"tags"`
Logs []*SpanLog `json:"logs"`
}
// TraceStatus represents the status of a trace
type TraceStatus string
const (
TraceStatusOK TraceStatus = "ok"
TraceStatusError TraceStatus = "error"
TraceStatusOK TraceStatus = "ok"
TraceStatusError TraceStatus = "error"
TraceStatusTimeout TraceStatus = "timeout"
)
@@ -675,18 +675,18 @@ type TraceExporter interface {
// ErrorEvent represents a system error event
type ErrorEvent struct {
ID string `json:"id"`
Timestamp time.Time `json:"timestamp"`
Level LogLevel `json:"level"`
Component string `json:"component"`
Message string `json:"message"`
Error string `json:"error"`
Context map[string]interface{} `json:"context"`
TraceID string `json:"trace_id,omitempty"`
SpanID string `json:"span_id,omitempty"`
Count int `json:"count"`
FirstSeen time.Time `json:"first_seen"`
LastSeen time.Time `json:"last_seen"`
ID string `json:"id"`
Timestamp time.Time `json:"timestamp"`
Level LogLevel `json:"level"`
Component string `json:"component"`
Message string `json:"message"`
Error string `json:"error"`
Context map[string]interface{} `json:"context"`
TraceID string `json:"trace_id,omitempty"`
SpanID string `json:"span_id,omitempty"`
Count int `json:"count"`
FirstSeen time.Time `json:"first_seen"`
LastSeen time.Time `json:"last_seen"`
}
// NewMonitoringSystem creates a comprehensive monitoring system
@@ -722,7 +722,7 @@ func (ms *MonitoringSystem) initializeComponents() error {
aggregatedStats: &AggregatedStatistics{
LastUpdated: time.Now(),
},
exporters: []MetricsExporter{},
exporters: []MetricsExporter{},
lastCollection: time.Now(),
}
@@ -1134,15 +1134,15 @@ func (ms *MonitoringSystem) createDefaultDashboards() {
func (ms *MonitoringSystem) severityWeight(severity AlertSeverity) int {
switch severity {
case SeverityCritical:
case AlertSeverityCritical:
return 4
case SeverityError:
case AlertSeverityError:
return 3
case SeverityWarning:
case AlertSeverityWarning:
return 2
case SeverityInfo:
case AlertSeverityInfo:
return 1
default:
return 0
}
}
}