Documentation
¶
Overview ¶
Package monitoring provides production alerting and monitoring capabilities for serverless applications.
Index ¶
- Constants
- Variables
- func AnalyzeQueryComplexity(queryType string, filters map[string]any, limit int) int
- func ValidateHealthCheckEvent(event HealthCheckEvent) error
- type Alert
- type AlertManager
- func (am *AlertManager) CheckCapacity(ctx context.Context, resource string, utilization float64)
- func (am *AlertManager) CheckColdStarts(ctx context.Context, service string, coldStartsPerMinute int64)
- func (am *AlertManager) CheckCost(ctx context.Context, costMicroCents float64)
- func (am *AlertManager) CheckErrorRate(ctx context.Context, service string, errorRate float64)
- func (am *AlertManager) CheckFederationHealth(ctx context.Context, instance string, failureRate float64, totalRequests int64)
- func (am *AlertManager) CheckHealth(ctx context.Context, service string, isHealthy bool, errorMsg string)
- func (am *AlertManager) CheckLatency(ctx context.Context, service string, latencyMs float64, percentile string)
- func (am *AlertManager) CheckQueueDepth(ctx context.Context, queueName string, depth int64)
- func (am *AlertManager) CheckSecurity(ctx context.Context, eventType string, severity AlertSeverity, ...)
- func (am *AlertManager) SendAlert(ctx context.Context, alert *Alert) error
- type AlertManagerConfig
- type AlertRateLimiter
- type AlertSeverity
- type AlertType
- type BatchMetrics
- type CloudWatchMetrics
- func (cwm *CloudWatchMetrics) FlushMetrics(_ context.Context) error
- func (cwm *CloudWatchMetrics) RecordBusinessMetrics(metricName string, value float64, unit types.StandardUnit, ...)
- func (cwm *CloudWatchMetrics) RecordCostMetrics(operation string, costData CostData)
- func (cwm *CloudWatchMetrics) RecordDynamORMMetrics(_ context.Context, metrics DynamORMMetrics)
- type ComponentCheckConfig
- type ComponentChecker
- type ComponentHealth
- type ComponentHealthResult
- type ConsumedCapacity
- type CostData
- type CustomChecker
- type DynamORMMetrics
- type DynamoDBChecker
- type EnhancedMetricBuffer
- type ErrInvalidHealthCheckEvent
- type HealthCheckComponent
- type HealthCheckEvent
- type HealthCheckOptions
- type HealthCheckResponse
- type HealthCheckSummary
- type HealthMonitor
- func (hm *HealthMonitor) CheckDynamoDBHealth(ctx context.Context, tableName string) error
- func (hm *HealthMonitor) CheckLambdaHealth(ctx context.Context, functionName string) error
- func (hm *HealthMonitor) CheckSQSHealth(ctx context.Context, queueURL string) error
- func (hm *HealthMonitor) GetHealthStatus() map[string]ComponentHealth
- func (hm *HealthMonitor) GetOverallHealth() HealthStatus
- func (hm *HealthMonitor) StartHealthChecks(ctx context.Context, interval time.Duration, components []HealthCheckComponent)
- type HealthStatus
- type LambdaChecker
- type MetricConfig
- type MetricData
- type MetricRecorder
- type N1QueryPattern
- type OptimizationTracker
- func (ot *OptimizationTracker) GetColdStartRatio() float64
- func (ot *OptimizationTracker) TrackColdStart(_ context.Context)
- func (ot *OptimizationTracker) TrackDBQuery(_ context.Context, tableName string, operation string, duration time.Duration)
- func (ot *OptimizationTracker) TrackLatency(_ context.Context, operation string, duration time.Duration)
- func (ot *OptimizationTracker) TrackWarmStart(_ context.Context)
- type PerformanceMonitor
- func (pm *PerformanceMonitor) AddXRayAnnotation(ctx context.Context, key string, value any) error
- func (pm *PerformanceMonitor) AddXRayMetadata(ctx context.Context, namespace string, key string, value any) error
- func (pm *PerformanceMonitor) CreateAlarm(ctx context.Context, alarmName, metricName string, threshold float64, ...) error
- func (pm *PerformanceMonitor) GetPerformanceInsights(ctx context.Context, metricName string, startTime, endTime time.Time) ([]types.Datapoint, error)
- func (pm *PerformanceMonitor) NewBatchMetrics() *BatchMetrics
- func (pm *PerformanceMonitor) RecordCacheHit(ctx context.Context, cacheName string, hit bool) error
- func (pm *PerformanceMonitor) RecordDynamoDBConsumedCapacity(ctx context.Context, tableName string, operation string, ...) error
- func (pm *PerformanceMonitor) RecordError(ctx context.Context, operation string, errorType string) error
- func (pm *PerformanceMonitor) RecordFederationPerformance(ctx context.Context, domain string, operation string, latencyMs float64, ...) error
- func (pm *PerformanceMonitor) RecordLambdaColdStart(ctx context.Context, functionName string, coldStart bool, ...) error
- func (pm *PerformanceMonitor) RecordLatency(ctx context.Context, operation string, latencyMs float64) error
- func (pm *PerformanceMonitor) RecordQueryComplexity(ctx context.Context, queryName string, complexity int) error
- func (pm *PerformanceMonitor) RecordSQSQueueDepth(ctx context.Context, queueName string, depth int64) error
- func (pm *PerformanceMonitor) RecordXRayError(ctx context.Context, err error)
- func (pm *PerformanceMonitor) StartXRaySegment(ctx context.Context, name string) (context.Context, *xray.Segment)
- func (pm *PerformanceMonitor) StartXRaySubsegment(ctx context.Context, name string) (context.Context, *xray.Segment)
- func (pm *PerformanceMonitor) TraceDBQuery(ctx context.Context, operation string, tableName string, ...) error
- func (pm *PerformanceMonitor) TraceFederationCall(ctx context.Context, domain string, operation string, ...) error
- func (pm *PerformanceMonitor) TraceGraphQLQuery(ctx context.Context, queryName string, complexity int, ...) error
- func (pm *PerformanceMonitor) TraceLambdaHandler(ctx context.Context, functionName string, fn func(context.Context) error) error
- type QueryAnalyzer
- func (qa *QueryAnalyzer) DetectN1Queries() []N1QueryPattern
- func (qa *QueryAnalyzer) GetAverageQueryTime(queryPattern string) (time.Duration, bool)
- func (qa *QueryAnalyzer) GetQueryStats() map[string]QueryStats
- func (qa *QueryAnalyzer) GetSlowQueries(limit int) []SlowQuery
- func (qa *QueryAnalyzer) ResetStats()
- func (qa *QueryAnalyzer) StartQuery(queryPattern string, parameters map[string]any) *QueryExecution
- type QueryExecution
- type QueryPlan
- type QueryStats
- type SQSChecker
- type ServerlessHealthMonitor
- func (s *ServerlessHealthMonitor) CreateHealthCheckSummary(ctx context.Context, results []ComponentHealthResult) error
- func (s *ServerlessHealthMonitor) GetComponentHistory(ctx context.Context, componentType, component string, limit int) ([]models.ComponentHealthHistory, error)
- func (s *ServerlessHealthMonitor) GetStoredResults(ctx context.Context, componentType, component string, limit int) ([]models.HealthCheckResult, error)
- func (s *ServerlessHealthMonitor) ProcessHealthCheckEvent(ctx context.Context, event HealthCheckEvent) (*HealthCheckResponse, error)
- func (s *ServerlessHealthMonitor) RegisterChecker(checker ComponentChecker)
- func (s *ServerlessHealthMonitor) SetMetricsPublisher(publisher *CloudWatchMetrics)
- type SlowQuery
- type SlowQueryLog
- type WebhookConfig
- type XRaySegment
- type XRayTracer
- func (xt *XRayTracer) AWSConfigLoadOptions() []func(*config.LoadOptions) error
- func (xt *XRayTracer) AddAnnotation(ctx context.Context, key string, value interface{}) error
- func (xt *XRayTracer) AddMetadata(ctx context.Context, namespace string, data map[string]interface{}) error
- func (xt *XRayTracer) GetTraceID(ctx context.Context) string
- func (xt *XRayTracer) InstrumentAWSConfig(cfg aws.Config) aws.Config
- func (xt *XRayTracer) InstrumentS3Client(client *s3.Client) *s3.Client
- func (xt *XRayTracer) InstrumentSQSClient(client *sqs.Client) *sqs.Client
- func (xt *XRayTracer) IsEnabled() bool
- func (xt *XRayTracer) RecordError(ctx context.Context, err error)
- func (xt *XRayTracer) TraceAuthOperation(ctx context.Context, operation, authType string, ...) (bool, error)
- func (xt *XRayTracer) TraceCostOperation(ctx context.Context, service string, costMicroCents int64, ...) error
- func (xt *XRayTracer) TraceDynamoDBOperation(ctx context.Context, operation, tableName string, ...) error
- func (xt *XRayTracer) TraceFederationCall(ctx context.Context, domain, operation, activityType string, ...) error
- func (xt *XRayTracer) TraceGraphQLResolver(ctx context.Context, resolver, fieldName string, ...) error
- func (xt *XRayTracer) TraceMediaProcessing(ctx context.Context, operation, mediaType string, size int64, ...) error
- func (xt *XRayTracer) TraceS3Operation(ctx context.Context, operation, bucket, key string, ...) error
- func (xt *XRayTracer) TraceSQSOperation(ctx context.Context, operation, queueName string, messageCount int, ...) error
- func (xt *XRayTracer) TraceStreamProcessor(ctx context.Context, processorName string, recordCount int, ...) error
Constants ¶
const (
ErrorHighLatency = "High latency detected"
)
Error message constants
const (
ProviderAWS = "aws"
)
Provider constants
const (
StatusUnknown = "unknown"
)
Status constants
Variables ¶
var ( // DefaultHealthCheckEvent provides a basic health check configuration DefaultHealthCheckEvent = HealthCheckEvent{ Action: "check_health", Components: []ComponentCheckConfig{ {Type: "dynamodb", Identifier: "lesser-main", Name: "Main Database"}, }, Options: HealthCheckOptions{ StoreResults: true, PublishMetrics: true, IncludeMetadata: true, TimeoutSeconds: 30, RetryAttempts: 2, }, } // ComprehensiveHealthCheckEvent checks all major components ComprehensiveHealthCheckEvent = HealthCheckEvent{ Action: "check_health", Components: []ComponentCheckConfig{ {Type: "dynamodb", Identifier: "lesser-main", Name: "Main Database"}, {Type: "lambda", Identifier: "lesser-api", Name: "API Handler"}, {Type: "lambda", Identifier: "lesser-processor-timeline", Name: "Timeline Processor"}, {Type: "sqs", Identifier: "timeline-updates", Name: "Timeline Updates Queue"}, {Type: "sqs", Identifier: "federation-delivery", Name: "Federation Delivery Queue"}, }, Options: HealthCheckOptions{ StoreResults: true, PublishMetrics: true, IncludeMetadata: true, TimeoutSeconds: 45, RetryAttempts: 3, }, } // QuickHealthCheckEvent provides minimal checks for frequent monitoring QuickHealthCheckEvent = HealthCheckEvent{ Action: "check_health", Components: []ComponentCheckConfig{ {Type: "dynamodb", Identifier: "lesser-main", Name: "Main Database"}, }, Options: HealthCheckOptions{ StoreResults: false, PublishMetrics: true, IncludeMetadata: false, TimeoutSeconds: 15, RetryAttempts: 1, }, } )
Predefined health check event configurations
Functions ¶
func AnalyzeQueryComplexity ¶
AnalyzeQueryComplexity calculates the complexity score for a query
func ValidateHealthCheckEvent ¶
func ValidateHealthCheckEvent(event HealthCheckEvent) error
ValidateHealthCheckEvent validates that a health check event is properly formatted
Types ¶
type Alert ¶
type Alert struct {
Type AlertType `json:"type"`
Severity AlertSeverity `json:"severity"`
Title string `json:"title"`
Description string `json:"description"`
Service string `json:"service"`
Region string `json:"region"`
Timestamp time.Time `json:"timestamp"`
Metadata map[string]interface{} `json:"metadata"`
Source string `json:"source"`
RunbookURL string `json:"runbook_url,omitempty"`
Priority string `json:"priority,omitempty"` // P0, P1, P2
}
Alert represents an alert to be sent
type AlertManager ¶
type AlertManager struct {
// contains filtered or unexported fields
}
AlertManager handles production alerting
func NewAlertManager ¶
func NewAlertManager(logger *zap.Logger) *AlertManager
NewAlertManager creates a new alert manager
func NewAlertManagerWithConfig ¶
func NewAlertManagerWithConfig(config *AlertManagerConfig) *AlertManager
NewAlertManagerWithConfig creates a new alert manager with full configuration
func (*AlertManager) CheckCapacity ¶
func (am *AlertManager) CheckCapacity(ctx context.Context, resource string, utilization float64)
CheckCapacity triggers alert for capacity issues
func (*AlertManager) CheckColdStarts ¶
func (am *AlertManager) CheckColdStarts(ctx context.Context, service string, coldStartsPerMinute int64)
CheckColdStarts triggers alert for excessive cold starts
func (*AlertManager) CheckCost ¶
func (am *AlertManager) CheckCost(ctx context.Context, costMicroCents float64)
CheckCost triggers alert if cost is too high
func (*AlertManager) CheckErrorRate ¶
func (am *AlertManager) CheckErrorRate(ctx context.Context, service string, errorRate float64)
CheckErrorRate triggers alert if error rate is too high
func (*AlertManager) CheckFederationHealth ¶
func (am *AlertManager) CheckFederationHealth(ctx context.Context, instance string, failureRate float64, totalRequests int64)
CheckFederationHealth triggers alert for federation issues
func (*AlertManager) CheckHealth ¶
func (am *AlertManager) CheckHealth(ctx context.Context, service string, isHealthy bool, errorMsg string)
CheckHealth triggers alert for health check failures
func (*AlertManager) CheckLatency ¶
func (am *AlertManager) CheckLatency(ctx context.Context, service string, latencyMs float64, percentile string)
CheckLatency triggers alert if latency is too high
func (*AlertManager) CheckQueueDepth ¶
func (am *AlertManager) CheckQueueDepth(ctx context.Context, queueName string, depth int64)
CheckQueueDepth triggers alert for queue depth issues
func (*AlertManager) CheckSecurity ¶
func (am *AlertManager) CheckSecurity(ctx context.Context, eventType string, severity AlertSeverity, details map[string]interface{})
CheckSecurity triggers alert for security events
type AlertManagerConfig ¶
type AlertManagerConfig struct {
Logger *zap.Logger
SNSClient snsAPI
SNSTopicArn string
WebhookURL string
WebhookHeaders map[string]string
Enabled bool
}
AlertManagerConfig contains configuration for the alert manager
type AlertRateLimiter ¶
type AlertRateLimiter struct {
// contains filtered or unexported fields
}
AlertRateLimiter prevents alert flooding
func NewAlertRateLimiter ¶
func NewAlertRateLimiter(threshold time.Duration) *AlertRateLimiter
NewAlertRateLimiter creates a new rate limiter for alerts
func (*AlertRateLimiter) ShouldAlert ¶
func (rl *AlertRateLimiter) ShouldAlert(key string) bool
ShouldAlert checks if an alert should be sent based on rate limiting
type AlertSeverity ¶
type AlertSeverity string
AlertSeverity represents the severity level of an alert
const ( // SeverityInfo represents informational alerts SeverityInfo AlertSeverity = "info" // SeverityWarning represents warning level alerts SeverityWarning AlertSeverity = "warning" // SeverityError represents error level alerts SeverityError AlertSeverity = "error" // SeverityCritical represents critical alerts requiring immediate attention SeverityCritical AlertSeverity = "critical" )
type AlertType ¶
type AlertType string
AlertType represents the type of alert
const ( // AlertTypeErrorRate represents high error rate alerts AlertTypeErrorRate AlertType = "error_rate" // AlertTypeLatency represents high latency alerts AlertTypeLatency AlertType = "latency" // AlertTypeCost represents cost threshold alerts AlertTypeCost AlertType = "cost" // AlertTypeHealth represents health check failure alerts AlertTypeHealth AlertType = "health" // AlertTypeSecurity represents security-related alerts AlertTypeSecurity AlertType = "security" // AlertTypeCapacity represents capacity/scaling alerts AlertTypeCapacity AlertType = "capacity" )
type BatchMetrics ¶
type BatchMetrics struct {
// contains filtered or unexported fields
}
BatchMetrics allows batching multiple metrics for efficiency
func (*BatchMetrics) Add ¶
func (bm *BatchMetrics) Add(metric MetricData)
Add adds a metric to the batch
type CloudWatchMetrics ¶
type CloudWatchMetrics struct {
// contains filtered or unexported fields
}
CloudWatchMetrics provides enhanced metrics collection with DynamORM integration
func NewCloudWatchMetrics ¶
func NewCloudWatchMetrics(awsConfig aws.Config, config MetricConfig, logger *zap.Logger) *CloudWatchMetrics
NewCloudWatchMetrics creates a new CloudWatch metrics collector
func (*CloudWatchMetrics) FlushMetrics ¶
func (cwm *CloudWatchMetrics) FlushMetrics(_ context.Context) error
FlushMetrics manually flushes all buffered metrics
func (*CloudWatchMetrics) RecordBusinessMetrics ¶
func (cwm *CloudWatchMetrics) RecordBusinessMetrics(metricName string, value float64, unit types.StandardUnit, businessDims map[string]string)
RecordBusinessMetrics records application-specific business metrics
func (*CloudWatchMetrics) RecordCostMetrics ¶
func (cwm *CloudWatchMetrics) RecordCostMetrics(operation string, costData CostData)
RecordCostMetrics records cost-related metrics
func (*CloudWatchMetrics) RecordDynamORMMetrics ¶
func (cwm *CloudWatchMetrics) RecordDynamORMMetrics(_ context.Context, metrics DynamORMMetrics)
RecordDynamORMMetrics records comprehensive DynamoDB operation metrics
type ComponentCheckConfig ¶
type ComponentCheckConfig struct {
Type string `json:"type"` // "dynamodb", "lambda", "sqs"
Identifier string `json:"identifier"` // table name, function name, or queue URL
Name string `json:"name"` // friendly name for the component
}
ComponentCheckConfig defines a component to check
type ComponentChecker ¶
type ComponentChecker interface {
Check(ctx context.Context, identifier string) (*ComponentHealthResult, error)
GetType() string
}
ComponentChecker defines the interface for checking individual components
type ComponentHealth ¶
type ComponentHealth struct {
Component string
Status HealthStatus
LastCheck time.Time
ErrorCount int
LastError error
Metadata map[string]any
}
ComponentHealth represents the health status of a component
type ComponentHealthResult ¶
type ComponentHealthResult struct {
Component string `json:"component"`
Type string `json:"type"`
Status HealthStatus `json:"status"`
CheckTime time.Time `json:"check_time"`
LatencyMs int64 `json:"latency_ms"`
Error string `json:"error,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
RetryAttempts int `json:"retry_attempts"`
}
ComponentHealthResult represents the result of checking a single component
type ConsumedCapacity ¶
ConsumedCapacity represents DynamoDB consumed capacity units
type CostData ¶
type CostData struct {
TotalCostMicroCents int64
DynamoDBCostMicroCents int64
LambdaCostMicroCents int64
S3CostMicroCents int64
}
CostData represents cost information for an operation
type CustomChecker ¶
type CustomChecker struct {
// contains filtered or unexported fields
}
CustomChecker allows for custom health check implementations
func NewCustomChecker ¶
func NewCustomChecker(componentType string, checkFunc func(ctx context.Context, identifier string) (*ComponentHealthResult, error)) *CustomChecker
NewCustomChecker creates a new custom checker
func (*CustomChecker) Check ¶
func (c *CustomChecker) Check(ctx context.Context, identifier string) (*ComponentHealthResult, error)
Check performs the custom health check
func (*CustomChecker) GetType ¶
func (c *CustomChecker) GetType() string
GetType returns the component type
type DynamORMMetrics ¶
type DynamORMMetrics struct {
Operation string
TableName string
ConsumedCapacity ConsumedCapacity
ItemCount int64
Duration time.Duration
Error error
}
DynamORMMetrics contains DynamoDB operation metrics
type DynamoDBChecker ¶
type DynamoDBChecker struct {
// contains filtered or unexported fields
}
DynamoDBChecker implements health checking for DynamoDB tables
func (*DynamoDBChecker) Check ¶
func (d *DynamoDBChecker) Check(ctx context.Context, tableName string) (*ComponentHealthResult, error)
Check performs a health check on a DynamoDB table
func (*DynamoDBChecker) GetType ¶
func (d *DynamoDBChecker) GetType() string
GetType returns the component type
type EnhancedMetricBuffer ¶
type EnhancedMetricBuffer struct {
// contains filtered or unexported fields
}
EnhancedMetricBuffer provides thread-safe buffering with automatic flushing
func (*EnhancedMetricBuffer) Add ¶
func (emb *EnhancedMetricBuffer) Add(metric types.MetricDatum)
Add adds a metric to the buffer (thread-safe)
func (*EnhancedMetricBuffer) Flush ¶
func (emb *EnhancedMetricBuffer) Flush() error
Flush sends all buffered metrics using the flush function
func (*EnhancedMetricBuffer) ShouldFlush ¶
func (emb *EnhancedMetricBuffer) ShouldFlush() bool
ShouldFlush determines if the buffer should be flushed In serverless mode, we only flush when buffer reaches capacity to avoid time-based triggers
func (*EnhancedMetricBuffer) Size ¶
func (emb *EnhancedMetricBuffer) Size() int
Size returns the current buffer size (thread-safe)
type ErrInvalidHealthCheckEvent ¶
type ErrInvalidHealthCheckEvent string
ErrInvalidHealthCheckEvent represents an error with health check event validation
func (ErrInvalidHealthCheckEvent) Error ¶
func (e ErrInvalidHealthCheckEvent) Error() string
type HealthCheckComponent ¶
type HealthCheckComponent struct {
Type string // "dynamodb", "lambda", "sqs"
Identifier string // table name, function name, or queue URL
}
HealthCheckComponent defines a component to monitor
type HealthCheckEvent ¶
type HealthCheckEvent struct {
Action string `json:"action"`
Components []ComponentCheckConfig `json:"components"`
Options HealthCheckOptions `json:"options,omitempty"`
}
HealthCheckEvent represents an EventBridge event for triggering health checks
type HealthCheckOptions ¶
type HealthCheckOptions struct {
StoreResults bool `json:"store_results"` // whether to store results in DynamoDB
PublishMetrics bool `json:"publish_metrics"` // whether to publish CloudWatch metrics
IncludeMetadata bool `json:"include_metadata"` // whether to include detailed metadata
TimeoutSeconds int `json:"timeout_seconds"` // timeout for individual checks
RetryAttempts int `json:"retry_attempts"` // number of retry attempts for failed checks
}
HealthCheckOptions provides configuration for health checks
type HealthCheckResponse ¶
type HealthCheckResponse struct {
RequestID string `json:"request_id"`
Timestamp time.Time `json:"timestamp"`
OverallStatus HealthStatus `json:"overall_status"`
ComponentResults []ComponentHealthResult `json:"component_results"`
Summary HealthCheckSummary `json:"summary"`
ExecutionTime int64 `json:"execution_time_ms"`
}
HealthCheckResponse represents the response from a health check Lambda
type HealthCheckSummary ¶
type HealthCheckSummary struct {
TotalComponents int `json:"total_components"`
HealthyComponents int `json:"healthy_components"`
WarningComponents int `json:"warning_components"`
CriticalComponents int `json:"critical_components"`
UnknownComponents int `json:"unknown_components"`
FailedChecks int `json:"failed_checks"`
}
HealthCheckSummary provides aggregated information about the health check
type HealthMonitor ¶
type HealthMonitor struct {
// contains filtered or unexported fields
}
HealthMonitor monitors infrastructure health
func NewHealthMonitor ¶
func NewHealthMonitor(cfg aws.Config, monitor *PerformanceMonitor) *HealthMonitor
NewHealthMonitor creates a new health monitor
func (*HealthMonitor) CheckDynamoDBHealth ¶
func (hm *HealthMonitor) CheckDynamoDBHealth(ctx context.Context, tableName string) error
CheckDynamoDBHealth checks DynamoDB table health
func (*HealthMonitor) CheckLambdaHealth ¶
func (hm *HealthMonitor) CheckLambdaHealth(ctx context.Context, functionName string) error
CheckLambdaHealth checks Lambda function health
func (*HealthMonitor) CheckSQSHealth ¶
func (hm *HealthMonitor) CheckSQSHealth(ctx context.Context, queueURL string) error
CheckSQSHealth checks SQS queue health
func (*HealthMonitor) GetHealthStatus ¶
func (hm *HealthMonitor) GetHealthStatus() map[string]ComponentHealth
GetHealthStatus returns the current health status
func (*HealthMonitor) GetOverallHealth ¶
func (hm *HealthMonitor) GetOverallHealth() HealthStatus
GetOverallHealth returns the overall system health
func (*HealthMonitor) StartHealthChecks ¶
func (hm *HealthMonitor) StartHealthChecks(ctx context.Context, interval time.Duration, components []HealthCheckComponent)
StartHealthChecks starts periodic health checks
type HealthStatus ¶
type HealthStatus string
HealthStatus represents the health state
const ( // HealthStatusHealthy represents a healthy status HealthStatusHealthy HealthStatus = "healthy" // HealthStatusWarning represents a warning status HealthStatusWarning HealthStatus = "warning" // HealthStatusCritical represents a critical status HealthStatusCritical HealthStatus = "critical" // HealthStatusUnknown represents an unknown status HealthStatusUnknown HealthStatus = "unknown" )
type LambdaChecker ¶
type LambdaChecker struct {
// contains filtered or unexported fields
}
LambdaChecker implements health checking for Lambda functions
func (*LambdaChecker) Check ¶
func (l *LambdaChecker) Check(ctx context.Context, functionName string) (*ComponentHealthResult, error)
Check performs a health check on a Lambda function
func (*LambdaChecker) GetType ¶
func (l *LambdaChecker) GetType() string
GetType returns the component type
type MetricConfig ¶
type MetricConfig struct {
Namespace string
Environment string
BufferSize int
FlushSize int
FlushInterval time.Duration
DefaultDims map[string]string
EnableBatching bool
}
MetricConfig configures CloudWatch metrics behavior
func DefaultMetricConfig ¶
func DefaultMetricConfig() MetricConfig
DefaultMetricConfig returns sensible defaults
type MetricData ¶
type MetricData struct {
Name string
Value float64
Unit types.StandardUnit
Dimensions map[string]string
}
MetricData represents a single metric data point
type MetricRecorder ¶
type MetricRecorder interface {
RecordLatency(ctx context.Context, operation string, latencyMs float64) error
RecordError(ctx context.Context, operation string, errorType string) error
RecordDynamoDBConsumedCapacity(ctx context.Context, tableName string, operation string, readCapacity, writeCapacity float64) error
}
MetricRecorder records performance metrics. Implemented by PerformanceMonitor. This interface enables testing QueryAnalyzer without AWS dependencies.
type N1QueryPattern ¶
type N1QueryPattern struct {
QueryPattern string
ExecutionCount int64
AverageTime time.Duration
TotalTime time.Duration
}
N1QueryPattern represents a potential N+1 query problem
type OptimizationTracker ¶
type OptimizationTracker struct {
// contains filtered or unexported fields
}
OptimizationTracker tracks Lambda performance optimizations
func NewOptimizationTracker ¶
func NewOptimizationTracker(logger *zap.Logger) *OptimizationTracker
NewOptimizationTracker creates a new optimization tracker
func (*OptimizationTracker) GetColdStartRatio ¶
func (ot *OptimizationTracker) GetColdStartRatio() float64
GetColdStartRatio returns the ratio of cold starts to total starts
func (*OptimizationTracker) TrackColdStart ¶
func (ot *OptimizationTracker) TrackColdStart(_ context.Context)
TrackColdStart records a cold start event
func (*OptimizationTracker) TrackDBQuery ¶
func (ot *OptimizationTracker) TrackDBQuery(_ context.Context, tableName string, operation string, duration time.Duration)
TrackDBQuery records database query performance
func (*OptimizationTracker) TrackLatency ¶
func (ot *OptimizationTracker) TrackLatency(_ context.Context, operation string, duration time.Duration)
TrackLatency records request latency
func (*OptimizationTracker) TrackWarmStart ¶
func (ot *OptimizationTracker) TrackWarmStart(_ context.Context)
TrackWarmStart records a warm start event
type PerformanceMonitor ¶
type PerformanceMonitor struct {
// contains filtered or unexported fields
}
PerformanceMonitor handles performance metrics collection
func NewPerformanceMonitor ¶
func NewPerformanceMonitor(cfg aws.Config, namespace, environment string) *PerformanceMonitor
NewPerformanceMonitor creates a new performance monitor
func (*PerformanceMonitor) AddXRayAnnotation ¶
AddXRayAnnotation adds an annotation to the current X-Ray segment
func (*PerformanceMonitor) AddXRayMetadata ¶
func (pm *PerformanceMonitor) AddXRayMetadata(ctx context.Context, namespace string, key string, value any) error
AddXRayMetadata adds metadata to the current X-Ray segment
func (*PerformanceMonitor) CreateAlarm ¶
func (pm *PerformanceMonitor) CreateAlarm(ctx context.Context, alarmName, metricName string, threshold float64, comparisonOperator types.ComparisonOperator) error
CreateAlarm creates a CloudWatch alarm for monitoring
func (*PerformanceMonitor) GetPerformanceInsights ¶
func (pm *PerformanceMonitor) GetPerformanceInsights(ctx context.Context, metricName string, startTime, endTime time.Time) ([]types.Datapoint, error)
GetPerformanceInsights queries CloudWatch for performance insights
func (*PerformanceMonitor) NewBatchMetrics ¶
func (pm *PerformanceMonitor) NewBatchMetrics() *BatchMetrics
NewBatchMetrics creates a new batch metrics collector
func (*PerformanceMonitor) RecordCacheHit ¶
RecordCacheHit records cache hit/miss metrics
func (*PerformanceMonitor) RecordDynamoDBConsumedCapacity ¶
func (pm *PerformanceMonitor) RecordDynamoDBConsumedCapacity(ctx context.Context, tableName string, operation string, readCapacity, writeCapacity float64) error
RecordDynamoDBConsumedCapacity records DynamoDB consumed capacity
func (*PerformanceMonitor) RecordError ¶
func (pm *PerformanceMonitor) RecordError(ctx context.Context, operation string, errorType string) error
RecordError records an error metric
func (*PerformanceMonitor) RecordFederationPerformance ¶
func (pm *PerformanceMonitor) RecordFederationPerformance(ctx context.Context, domain string, operation string, latencyMs float64, success bool) error
RecordFederationPerformance records federation-specific performance metrics
func (*PerformanceMonitor) RecordLambdaColdStart ¶
func (pm *PerformanceMonitor) RecordLambdaColdStart(ctx context.Context, functionName string, coldStart bool, initDurationMs float64) error
RecordLambdaColdStart records Lambda cold start metrics
func (*PerformanceMonitor) RecordLatency ¶
func (pm *PerformanceMonitor) RecordLatency(ctx context.Context, operation string, latencyMs float64) error
RecordLatency records a latency metric
func (*PerformanceMonitor) RecordQueryComplexity ¶
func (pm *PerformanceMonitor) RecordQueryComplexity(ctx context.Context, queryName string, complexity int) error
RecordQueryComplexity records GraphQL query complexity metrics
func (*PerformanceMonitor) RecordSQSQueueDepth ¶
func (pm *PerformanceMonitor) RecordSQSQueueDepth(ctx context.Context, queueName string, depth int64) error
RecordSQSQueueDepth records SQS queue depth metrics
func (*PerformanceMonitor) RecordXRayError ¶
func (pm *PerformanceMonitor) RecordXRayError(ctx context.Context, err error)
RecordXRayError records an error in the current X-Ray segment
func (*PerformanceMonitor) StartXRaySegment ¶
func (pm *PerformanceMonitor) StartXRaySegment(ctx context.Context, name string) (context.Context, *xray.Segment)
StartXRaySegment starts a new X-Ray segment
func (*PerformanceMonitor) StartXRaySubsegment ¶
func (pm *PerformanceMonitor) StartXRaySubsegment(ctx context.Context, name string) (context.Context, *xray.Segment)
StartXRaySubsegment starts a new X-Ray subsegment
func (*PerformanceMonitor) TraceDBQuery ¶
func (pm *PerformanceMonitor) TraceDBQuery(ctx context.Context, operation string, tableName string, fn func(context.Context) error) error
TraceDBQuery wraps a database query with X-Ray tracing
func (*PerformanceMonitor) TraceFederationCall ¶
func (pm *PerformanceMonitor) TraceFederationCall(ctx context.Context, domain string, operation string, fn func(context.Context) error) error
TraceFederationCall wraps a federation call with X-Ray tracing
func (*PerformanceMonitor) TraceGraphQLQuery ¶
func (pm *PerformanceMonitor) TraceGraphQLQuery(ctx context.Context, queryName string, complexity int, fn func(context.Context) error) error
TraceGraphQLQuery wraps a GraphQL query with X-Ray tracing
func (*PerformanceMonitor) TraceLambdaHandler ¶
func (pm *PerformanceMonitor) TraceLambdaHandler(ctx context.Context, functionName string, fn func(context.Context) error) error
TraceLambdaHandler wraps a Lambda handler with X-Ray tracing and cold start detection
type QueryAnalyzer ¶
type QueryAnalyzer struct {
// contains filtered or unexported fields
}
QueryAnalyzer tracks and analyzes query performance
func NewQueryAnalyzer ¶
func NewQueryAnalyzer(monitor MetricRecorder, slowQueryThreshold time.Duration) *QueryAnalyzer
NewQueryAnalyzer creates a new query analyzer
func (*QueryAnalyzer) DetectN1Queries ¶
func (qa *QueryAnalyzer) DetectN1Queries() []N1QueryPattern
DetectN1Queries analyzes patterns that might indicate N+1 query problems
func (*QueryAnalyzer) GetAverageQueryTime ¶
func (qa *QueryAnalyzer) GetAverageQueryTime(queryPattern string) (time.Duration, bool)
GetAverageQueryTime returns the average execution time for a query pattern
func (*QueryAnalyzer) GetQueryStats ¶
func (qa *QueryAnalyzer) GetQueryStats() map[string]QueryStats
GetQueryStats returns statistics for all tracked queries
func (*QueryAnalyzer) GetSlowQueries ¶
func (qa *QueryAnalyzer) GetSlowQueries(limit int) []SlowQuery
GetSlowQueries returns recent slow queries
func (*QueryAnalyzer) ResetStats ¶
func (qa *QueryAnalyzer) ResetStats()
ResetStats clears all query statistics
func (*QueryAnalyzer) StartQuery ¶
func (qa *QueryAnalyzer) StartQuery(queryPattern string, parameters map[string]any) *QueryExecution
StartQuery begins tracking a query execution
type QueryExecution ¶
type QueryExecution struct {
// contains filtered or unexported fields
}
QueryExecution tracks a query execution
type QueryPlan ¶
type QueryPlan struct {
QueryType string
IndexUsed string
EstimatedRCU float64
EstimatedItems int
Warnings []string
}
QueryPlan represents an analyzed query plan
type QueryStats ¶
type QueryStats struct {
QueryPattern string
ExecutionCount int64
TotalTime time.Duration
MinTime time.Duration
MaxTime time.Duration
LastExecution time.Time
ErrorCount int64
}
QueryStats tracks statistics for a specific query pattern
type SQSChecker ¶
type SQSChecker struct {
// contains filtered or unexported fields
}
SQSChecker implements health checking for SQS queues
func (*SQSChecker) Check ¶
func (s *SQSChecker) Check(ctx context.Context, queueName string) (*ComponentHealthResult, error)
Check performs a health check on an SQS queue
func (*SQSChecker) GetType ¶
func (s *SQSChecker) GetType() string
GetType returns the component type
type ServerlessHealthMonitor ¶
type ServerlessHealthMonitor struct {
// contains filtered or unexported fields
}
ServerlessHealthMonitor provides on-demand health checking for serverless environments
func NewServerlessHealthMonitor ¶
func NewServerlessHealthMonitor(db core.DB, logger *zap.Logger) *ServerlessHealthMonitor
NewServerlessHealthMonitor creates a new serverless health monitor
func (*ServerlessHealthMonitor) CreateHealthCheckSummary ¶
func (s *ServerlessHealthMonitor) CreateHealthCheckSummary(ctx context.Context, results []ComponentHealthResult) error
CreateHealthCheckSummary creates or updates hourly summary statistics
func (*ServerlessHealthMonitor) GetComponentHistory ¶
func (s *ServerlessHealthMonitor) GetComponentHistory(ctx context.Context, componentType, component string, limit int) ([]models.ComponentHealthHistory, error)
GetComponentHistory retrieves health history for a component
func (*ServerlessHealthMonitor) GetStoredResults ¶
func (s *ServerlessHealthMonitor) GetStoredResults(ctx context.Context, componentType, component string, limit int) ([]models.HealthCheckResult, error)
GetStoredResults retrieves stored health check results for a component
func (*ServerlessHealthMonitor) ProcessHealthCheckEvent ¶
func (s *ServerlessHealthMonitor) ProcessHealthCheckEvent(ctx context.Context, event HealthCheckEvent) (*HealthCheckResponse, error)
ProcessHealthCheckEvent processes a health check event synchronously
func (*ServerlessHealthMonitor) RegisterChecker ¶
func (s *ServerlessHealthMonitor) RegisterChecker(checker ComponentChecker)
RegisterChecker registers a component checker
func (*ServerlessHealthMonitor) SetMetricsPublisher ¶
func (s *ServerlessHealthMonitor) SetMetricsPublisher(publisher *CloudWatchMetrics)
SetMetricsPublisher sets the CloudWatch metrics publisher for the health monitor
type SlowQuery ¶
type SlowQuery struct {
QueryPattern string
Duration time.Duration
Timestamp time.Time
Parameters map[string]any
ConsumedRCU float64
ConsumedWCU float64
}
SlowQuery represents a slow query
type SlowQueryLog ¶
type SlowQueryLog struct {
// contains filtered or unexported fields
}
SlowQueryLog tracks slow queries
type WebhookConfig ¶
WebhookConfig contains webhook endpoint configuration
type XRaySegment ¶
XRaySegment represents an X-Ray trace segment
type XRayTracer ¶
type XRayTracer struct {
// contains filtered or unexported fields
}
XRayTracer provides comprehensive X-Ray tracing for the Lesser application
func NewXRayTracer ¶
func NewXRayTracer(serviceName, environment string, logger *zap.Logger) *XRayTracer
NewXRayTracer creates a new X-Ray tracer
func (*XRayTracer) AWSConfigLoadOptions ¶
func (xt *XRayTracer) AWSConfigLoadOptions() []func(*config.LoadOptions) error
AWSConfigLoadOptions returns AWS SDK v2 load options that enable X-Ray middleware.
This is useful for libraries (including TableTheory) that internally call config.LoadDefaultConfig and accept `[]func(*config.LoadOptions) error` as configuration hooks.
func (*XRayTracer) AddAnnotation ¶
func (xt *XRayTracer) AddAnnotation(ctx context.Context, key string, value interface{}) error
AddAnnotation adds an annotation to the current segment
func (*XRayTracer) AddMetadata ¶
func (xt *XRayTracer) AddMetadata(ctx context.Context, namespace string, data map[string]interface{}) error
AddMetadata adds metadata to the current segment
func (*XRayTracer) GetTraceID ¶
func (xt *XRayTracer) GetTraceID(ctx context.Context) string
GetTraceID returns the current X-Ray trace ID
func (*XRayTracer) InstrumentAWSConfig ¶
func (xt *XRayTracer) InstrumentAWSConfig(cfg aws.Config) aws.Config
InstrumentAWSConfig instruments AWS SDK v2 configuration for X-Ray tracing
func (*XRayTracer) InstrumentS3Client ¶
func (xt *XRayTracer) InstrumentS3Client(client *s3.Client) *s3.Client
InstrumentS3Client instruments an S3 client for X-Ray tracing
func (*XRayTracer) InstrumentSQSClient ¶
func (xt *XRayTracer) InstrumentSQSClient(client *sqs.Client) *sqs.Client
InstrumentSQSClient instruments an SQS client for X-Ray tracing
func (*XRayTracer) IsEnabled ¶
func (xt *XRayTracer) IsEnabled() bool
IsEnabled returns whether X-Ray tracing is enabled
func (*XRayTracer) RecordError ¶
func (xt *XRayTracer) RecordError(ctx context.Context, err error)
RecordError records an error in the current segment
func (*XRayTracer) TraceAuthOperation ¶
func (xt *XRayTracer) TraceAuthOperation(ctx context.Context, operation, authType string, fn func(context.Context) (bool, error)) (bool, error)
TraceAuthOperation traces authentication operations
func (*XRayTracer) TraceCostOperation ¶
func (xt *XRayTracer) TraceCostOperation(ctx context.Context, service string, costMicroCents int64, fn func(context.Context) error) error
TraceCostOperation traces cost tracking operations
func (*XRayTracer) TraceDynamoDBOperation ¶
func (xt *XRayTracer) TraceDynamoDBOperation(ctx context.Context, operation, tableName string, fn func(context.Context) error) error
TraceDynamoDBOperation traces a DynamoDB operation
func (*XRayTracer) TraceFederationCall ¶
func (xt *XRayTracer) TraceFederationCall(ctx context.Context, domain, operation, activityType string, fn func(context.Context) error) error
TraceFederationCall traces federation ActivityPub calls
func (*XRayTracer) TraceGraphQLResolver ¶
func (xt *XRayTracer) TraceGraphQLResolver(ctx context.Context, resolver, fieldName string, fn func(context.Context) error) error
TraceGraphQLResolver traces GraphQL resolver execution
func (*XRayTracer) TraceMediaProcessing ¶
func (xt *XRayTracer) TraceMediaProcessing(ctx context.Context, operation, mediaType string, size int64, fn func(context.Context) error) error
TraceMediaProcessing traces media processing operations
func (*XRayTracer) TraceS3Operation ¶
func (xt *XRayTracer) TraceS3Operation(ctx context.Context, operation, bucket, key string, fn func(context.Context) error) error
TraceS3Operation traces an S3 operation