observability

package
v0.7.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSpanContext

func GetSpanContext(ctx context.Context) (string, bool)

GetSpanContext retrieves span context from context.Context.

func GetTraceContext

func GetTraceContext(ctx context.Context) (string, bool)

GetTraceContext retrieves trace context from context.Context.

Types

type Alert

type Alert struct {
	ID           string
	Rule         string
	Severity     AlertSeverity
	Message      string
	Details      map[string]any
	StartTime    time.Time
	LastUpdate   time.Time
	FireCount    int
	Acknowledged bool
	Resolved     bool
	ResolvedAt   time.Time
}

Alert represents an active alert.

type AlertCondition

type AlertCondition func(ctx context.Context, data map[string]any) bool

AlertCondition is a function that evaluates alert conditions.

type AlertConfig

type AlertConfig struct {
	EnableAlerts    bool
	MaxActiveAlerts int
	MaxHistory      int
}

AlertConfig contains alert configuration.

type AlertEvent

type AlertEvent struct {
	Timestamp time.Time
	Type      AlertEventType
	AlertID   string
	Rule      string
	Severity  AlertSeverity
	Message   string
}

AlertEvent represents an alert event in history.

type AlertEventType

type AlertEventType string

AlertEventType represents alert event type.

const (
	// AlertEventTypeFired alert fired.
	AlertEventTypeFired AlertEventType = "fired"
	// AlertEventTypeAcknowledged alert acknowledged.
	AlertEventTypeAcknowledged AlertEventType = "acknowledged"
	// AlertEventTypeResolved alert resolved.
	AlertEventTypeResolved AlertEventType = "resolved"
)

type AlertHandler

type AlertHandler func(alert *Alert)

AlertHandler handles alert notifications.

type AlertManager

type AlertManager struct {
	// contains filtered or unexported fields
}

AlertManager manages alerts and notifications for consensus issues.

func NewAlertManager

func NewAlertManager(nodeID string, config AlertConfig, logger forge.Logger) *AlertManager

NewAlertManager creates a new alert manager.

func (*AlertManager) AcknowledgeAlert

func (am *AlertManager) AcknowledgeAlert(alertID string) error

AcknowledgeAlert acknowledges an alert.

func (*AlertManager) ClearResolvedAlerts

func (am *AlertManager) ClearResolvedAlerts() int

ClearResolvedAlerts clears resolved alerts from memory.

func (*AlertManager) DisableRule

func (am *AlertManager) DisableRule(ruleName string) error

DisableRule disables an alert rule.

func (*AlertManager) EnableRule

func (am *AlertManager) EnableRule(ruleName string) error

EnableRule enables an alert rule.

func (*AlertManager) EvaluateRule

func (am *AlertManager) EvaluateRule(ctx context.Context, ruleName string, data map[string]any)

EvaluateRule evaluates an alert rule.

func (*AlertManager) GetActiveAlerts

func (am *AlertManager) GetActiveAlerts() []*Alert

GetActiveAlerts returns all active alerts.

func (*AlertManager) GetAlertsBySeverity

func (am *AlertManager) GetAlertsBySeverity(severity AlertSeverity) []*Alert

GetAlertsBySeverity returns alerts by severity.

func (*AlertManager) GetCriticalAlerts

func (am *AlertManager) GetCriticalAlerts() []*Alert

GetCriticalAlerts returns critical alerts.

func (*AlertManager) GetHistory

func (am *AlertManager) GetHistory(limit int) []AlertEvent

GetHistory returns alert history.

func (*AlertManager) GetStatistics

func (am *AlertManager) GetStatistics() AlertStatistics

GetStatistics returns alert statistics.

func (*AlertManager) MonitorAlerts

func (am *AlertManager) MonitorAlerts(ctx context.Context, interval time.Duration, dataProvider func() map[string]any)

MonitorAlerts monitors and evaluates alert rules.

func (*AlertManager) RegisterHandler

func (am *AlertManager) RegisterHandler(handler AlertHandler)

RegisterHandler registers an alert handler.

func (*AlertManager) RegisterRule

func (am *AlertManager) RegisterRule(rule *AlertRule)

RegisterRule registers a new alert rule.

func (*AlertManager) ResolveAlert

func (am *AlertManager) ResolveAlert(alertID string) error

ResolveAlert resolves an alert.

type AlertRule

type AlertRule struct {
	Name        string
	Condition   AlertCondition
	Severity    AlertSeverity
	Description string
	Enabled     bool
	Cooldown    time.Duration
	// contains filtered or unexported fields
}

AlertRule defines conditions for triggering alerts.

type AlertSeverity

type AlertSeverity string

AlertSeverity represents alert severity.

const (
	// AlertSeverityCritical critical severity.
	AlertSeverityCritical AlertSeverity = "critical"
	// AlertSeverityHigh high severity.
	AlertSeverityHigh AlertSeverity = "high"
	// AlertSeverityMedium medium severity.
	AlertSeverityMedium AlertSeverity = "medium"
	// AlertSeverityLow low severity.
	AlertSeverityLow AlertSeverity = "low"
)

type AlertStatistics

type AlertStatistics struct {
	TotalAlerts        int64
	ActiveAlerts       int64
	CriticalAlerts     int64
	HighAlerts         int64
	MediumAlerts       int64
	LowAlerts          int64
	AcknowledgedAlerts int64
	ResolvedAlerts     int64
}

AlertStatistics contains alert statistics.

type HealthCheckFunc

type HealthCheckFunc func(ctx context.Context) internal.HealthCheck

HealthCheckFunc is a function that performs a health check.

type HealthChecker

type HealthChecker struct {
	// contains filtered or unexported fields
}

HealthChecker performs comprehensive health checks.

func NewHealthChecker

func NewHealthChecker(
	config HealthCheckerConfig,
	logger forge.Logger,
	raftNode internal.RaftNode,
	clusterManager internal.ClusterManager,
	storage internal.Storage,
	transport internal.Transport,
) *HealthChecker

NewHealthChecker creates a new health checker.

func (*HealthChecker) Check

Check performs all health checks.

func (*HealthChecker) GetHealthStatus

func (hc *HealthChecker) GetHealthStatus(ctx context.Context) internal.HealthStatus

GetHealthStatus returns the current health status.

func (*HealthChecker) IsHealthy

func (hc *HealthChecker) IsHealthy(ctx context.Context) bool

IsHealthy returns true if the system is healthy.

func (*HealthChecker) RegisterCheck

func (hc *HealthChecker) RegisterCheck(name string, fn HealthCheckFunc)

RegisterCheck registers a custom health check.

func (*HealthChecker) UnregisterCheck

func (hc *HealthChecker) UnregisterCheck(name string)

UnregisterCheck unregisters a health check.

type HealthCheckerConfig

type HealthCheckerConfig struct {
	Timeout time.Duration
}

HealthCheckerConfig contains health checker configuration.

type LogConfig

type LogConfig struct {
	EnableBuffer     bool
	BufferSize       int
	EnableTracing    bool
	EnableStructured bool
	SampleRate       float64
}

LogConfig contains logging configuration.

type LogEntry

type LogEntry struct {
	Timestamp time.Time
	Level     LogLevel
	Operation string
	Message   string
	Fields    map[string]any
	TraceID   string
	SpanID    string
	NodeID    string
}

LogEntry represents a structured log entry.

type LogFilter

type LogFilter struct {
	Level     LogLevel
	Operation string
	TraceID   string
	StartTime time.Time
	EndTime   time.Time
}

LogFilter filters log entries.

func (LogFilter) Matches

func (lf LogFilter) Matches(entry LogEntry) bool

Matches checks if entry matches filter.

type LogLevel

type LogLevel string

LogLevel represents log level.

const (
	// LogLevelDebug debug level.
	LogLevelDebug LogLevel = "debug"
	// LogLevelInfo info level.
	LogLevelInfo LogLevel = "info"
	// LogLevelWarn warning level.
	LogLevelWarn LogLevel = "warn"
	// LogLevelError error level.
	LogLevelError LogLevel = "error"
)

type LogManager

type LogManager struct {
	// contains filtered or unexported fields
}

LogManager manages structured logging for consensus operations.

func NewLogManager

func NewLogManager(nodeID string, config LogConfig, logger forge.Logger) *LogManager

NewLogManager creates a new log manager.

func (*LogManager) ClearBuffer

func (lm *LogManager) ClearBuffer()

ClearBuffer clears the log buffer.

func (*LogManager) Debug

func (lm *LogManager) Debug(ctx context.Context, operation, message string, fields ...any)

Debug logs a debug message.

func (*LogManager) Error

func (lm *LogManager) Error(ctx context.Context, operation, message string, fields ...any)

Error logs an error message.

func (*LogManager) ExportLogs

func (lm *LogManager) ExportLogs(filter LogFilter) []map[string]any

ExportLogs exports logs in structured format.

func (*LogManager) GetBuffer

func (lm *LogManager) GetBuffer(limit int) []LogEntry

GetBuffer returns buffered log entries.

func (*LogManager) GetErrorLogs

func (lm *LogManager) GetErrorLogs(limit int) []LogEntry

GetErrorLogs returns error logs.

func (*LogManager) GetLogsByLevel

func (lm *LogManager) GetLogsByLevel(level LogLevel, limit int) []LogEntry

GetLogsByLevel returns logs filtered by level.

func (*LogManager) GetLogsByOperation

func (lm *LogManager) GetLogsByOperation(operation string, limit int) []LogEntry

GetLogsByOperation returns logs for a specific operation.

func (*LogManager) GetLogsByTrace

func (lm *LogManager) GetLogsByTrace(traceID string) []LogEntry

GetLogsByTrace returns logs for a specific trace.

func (*LogManager) GetRecentLogs

func (lm *LogManager) GetRecentLogs(duration time.Duration, limit int) []LogEntry

GetRecentLogs returns most recent logs.

func (*LogManager) GetStatistics

func (lm *LogManager) GetStatistics() LogStatistics

GetStatistics returns logging statistics.

func (*LogManager) GetWarningLogs

func (lm *LogManager) GetWarningLogs(limit int) []LogEntry

GetWarningLogs returns warning logs.

func (*LogManager) Info

func (lm *LogManager) Info(ctx context.Context, operation, message string, fields ...any)

Info logs an info message.

func (*LogManager) LogClusterChange

func (lm *LogManager) LogClusterChange(ctx context.Context, event string, nodeID string, memberCount int)

LogClusterChange logs cluster membership changes.

func (*LogManager) LogElection

func (lm *LogManager) LogElection(ctx context.Context, event string, term uint64, candidateID string)

LogElection logs election-related events.

func (*LogManager) LogPerformance

func (lm *LogManager) LogPerformance(ctx context.Context, operation string, duration time.Duration, success bool)

LogPerformance logs performance metrics.

func (*LogManager) LogReplication

func (lm *LogManager) LogReplication(ctx context.Context, event string, followerID string, index uint64)

LogReplication logs replication events.

func (*LogManager) LogSnapshot

func (lm *LogManager) LogSnapshot(ctx context.Context, event string, index uint64, size int64)

LogSnapshot logs snapshot events.

func (*LogManager) LogStateChange

func (lm *LogManager) LogStateChange(ctx context.Context, event string, index uint64)

LogStateChange logs state machine changes.

func (*LogManager) SearchLogs

func (lm *LogManager) SearchLogs(filter LogFilter) []LogEntry

SearchLogs searches buffered logs.

func (*LogManager) Warn

func (lm *LogManager) Warn(ctx context.Context, operation, message string, fields ...any)

Warn logs a warning message.

type LogStatistics

type LogStatistics struct {
	TotalLogs    int64
	DebugLogs    int64
	InfoLogs     int64
	WarnLogs     int64
	ErrorLogs    int64
	BufferedLogs int
}

LogStatistics contains logging statistics.

type MetricsCollector

type MetricsCollector struct {
	// contains filtered or unexported fields
}

MetricsCollector collects and exports consensus metrics.

func NewMetricsCollector

func NewMetricsCollector(config MetricsConfig, metrics forge.Metrics, logger forge.Logger) *MetricsCollector

NewMetricsCollector creates a new metrics collector.

func (*MetricsCollector) GetMetrics

func (mc *MetricsCollector) GetMetrics() map[string]any

GetMetrics returns current metrics as a map.

func (*MetricsCollector) RecordApplyLatency

func (mc *MetricsCollector) RecordApplyLatency(latencyMs float64)

RecordApplyLatency records a state machine apply latency.

func (*MetricsCollector) RecordConfigChange

func (mc *MetricsCollector) RecordConfigChange()

RecordConfigChange records a configuration change.

func (*MetricsCollector) RecordElection

func (mc *MetricsCollector) RecordElection(success bool)

RecordElection records an election event.

func (*MetricsCollector) RecordLeadershipTransfer

func (mc *MetricsCollector) RecordLeadershipTransfer()

RecordLeadershipTransfer records a leadership transfer.

func (*MetricsCollector) RecordLogAppend

func (mc *MetricsCollector) RecordLogAppend(success bool)

RecordLogAppend records a log append event.

func (*MetricsCollector) RecordReplicationLatency

func (mc *MetricsCollector) RecordReplicationLatency(latencyMs float64)

RecordReplicationLatency records a replication latency.

func (*MetricsCollector) RecordSnapshot

func (mc *MetricsCollector) RecordSnapshot(success bool)

RecordSnapshot records a snapshot event.

func (*MetricsCollector) Start

func (mc *MetricsCollector) Start(ctx context.Context) error

Start starts the metrics collector.

func (*MetricsCollector) Stop

func (mc *MetricsCollector) Stop(ctx context.Context) error

Stop stops the metrics collector.

func (*MetricsCollector) UpdateGauges

func (mc *MetricsCollector) UpdateGauges(stats internal.ConsensusStats)

UpdateGauges updates gauge metrics.

type MetricsConfig

type MetricsConfig struct {
	NodeID             string
	CollectionInterval time.Duration
	EnableHistograms   bool
	HistogramSize      int
}

MetricsConfig contains metrics collector configuration.

type Span

type Span struct {
	SpanID    string
	ParentID  string
	TraceID   string
	Operation string
	StartTime time.Time
	EndTime   time.Time
	Duration  time.Duration
	Tags      map[string]any
	Logs      []SpanLog
	Status    SpanStatus
}

Span represents a span within a trace.

type SpanLog

type SpanLog struct {
	Timestamp time.Time
	Message   string
	Fields    map[string]any
}

SpanLog represents a log entry within a span.

type SpanStatus

type SpanStatus string

SpanStatus represents span status.

const (
	// SpanStatusActive span is active.
	SpanStatusActive SpanStatus = "active"
	// SpanStatusComplete span completed successfully.
	SpanStatusComplete SpanStatus = "complete"
	// SpanStatusError span completed with error.
	SpanStatusError SpanStatus = "error"
)

type Trace

type Trace struct {
	TraceID     string
	OperationID string
	Operation   string
	StartTime   time.Time
	EndTime     time.Time
	Duration    time.Duration
	Spans       []*Span
	Tags        map[string]any
	Status      TraceStatus
	// contains filtered or unexported fields
}

Trace represents a distributed trace.

type TraceStatus

type TraceStatus string

TraceStatus represents trace status.

const (
	// TraceStatusActive trace is active.
	TraceStatusActive TraceStatus = "active"
	// TraceStatusComplete trace completed successfully.
	TraceStatusComplete TraceStatus = "complete"
	// TraceStatusError trace completed with error.
	TraceStatusError TraceStatus = "error"
)

type TracingConfig

type TracingConfig struct {
	Enabled          bool
	SampleRate       float64 // 0.0 to 1.0
	MaxTraces        int
	MaxSpansPerTrace int
}

TracingConfig contains tracing configuration.

type TracingManager

type TracingManager struct {
	// contains filtered or unexported fields
}

TracingManager manages distributed tracing for consensus operations.

func NewTracingManager

func NewTracingManager(config TracingConfig, logger forge.Logger) *TracingManager

NewTracingManager creates a new tracing manager.

func (*TracingManager) AddSpanLog

func (tm *TracingManager) AddSpanLog(span *Span, message string, fields map[string]any)

AddSpanLog adds a log to a span.

func (*TracingManager) ClearOldTraces

func (tm *TracingManager) ClearOldTraces(olderThan time.Duration) int

ClearOldTraces clears traces older than duration.

func (*TracingManager) EndSpan

func (tm *TracingManager) EndSpan(span *Span, err error)

EndSpan ends a span.

func (*TracingManager) EndTrace

func (tm *TracingManager) EndTrace(trace *Trace, err error)

EndTrace ends a trace.

func (*TracingManager) ExportTrace

func (tm *TracingManager) ExportTrace(traceID string) (map[string]any, error)

ExportTrace exports a trace in a structured format.

func (*TracingManager) GetActiveTraces

func (tm *TracingManager) GetActiveTraces() []*Trace

GetActiveTraces returns all active traces.

func (*TracingManager) GetStatistics

func (tm *TracingManager) GetStatistics() TracingStatistics

GetStatistics returns tracing statistics.

func (*TracingManager) GetTrace

func (tm *TracingManager) GetTrace(traceID string) (*Trace, error)

GetTrace retrieves a trace by ID.

func (*TracingManager) SetSpanTag

func (tm *TracingManager) SetSpanTag(span *Span, key string, value any)

SetSpanTag sets a tag on a span.

func (*TracingManager) SetTraceTag

func (tm *TracingManager) SetTraceTag(trace *Trace, key string, value any)

SetTraceTag sets a tag on a trace.

func (*TracingManager) StartSpan

func (tm *TracingManager) StartSpan(ctx context.Context, operation string) (*Span, context.Context)

StartSpan starts a new span within a trace.

func (*TracingManager) StartTrace

func (tm *TracingManager) StartTrace(ctx context.Context, operation string) (*Trace, context.Context)

StartTrace starts a new trace.

type TracingStatistics

type TracingStatistics struct {
	TotalTraces     int64
	ActiveTraces    int64
	CompletedTraces int64
	ErrorTraces     int64
	TotalSpans      int64
	AverageDuration time.Duration
}

TracingStatistics contains tracing statistics.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL