Documentation
¶
Overview ¶
Package health defines event types for federation health monitoring and EventBridge integration.
Index ¶
- Variables
- type AggregationDetail
- type AggregationEvent
- type CheckerConfig
- type DomainHealthCheckResult
- type HealthCheckDetail
- type HealthCheckError
- type HealthCheckEvent
- type HealthCheckResult
- type ScheduledEventDetail
- type ScheduledHealthCheckEvent
- type ServerlessHealthChecker
- func (c *ServerlessHealthChecker) GetHealthHistory(ctx context.Context, domain string, since time.Time, limit int) ([]*models.InstanceHealth, error)
- func (c *ServerlessHealthChecker) GetHealthStatus(ctx context.Context, domain string) (*models.InstanceHealth, error)
- func (c *ServerlessHealthChecker) GetHealthSummary(ctx context.Context, domain string, window time.Duration) (*models.InstanceHealthSummary, error)
- func (c *ServerlessHealthChecker) GetUnhealthyInstances(ctx context.Context, threshold float64) ([]string, error)
- func (c *ServerlessHealthChecker) ProcessHealthCheckEvent(ctx context.Context, event *HealthCheckEvent) (*HealthCheckResult, error)
Constants ¶
This section is empty.
Variables ¶
var ( // Event processing errors ErrUnknownAction = errors.NewFederationError(errors.CodeInvalidInput, "unknown action") // Health check errors ErrNoDomains = errors.NewFederationError(errors.CodeRequiredFieldMissing, "no domains specified for health check") // Aggregation errors ErrAggregationRequired = errors.NewFederationError(errors.CodeRequiredFieldMissing, "domains and windows are required for aggregation") ErrUnsupportedWindow = errors.NewFederationError(errors.CodeInvalidInput, "unsupported window") // Event validation errors ErrActionRequired = errors.NewValidationError("action", "required") ErrDomainsOrInstanceIDsRequired = errors.NewValidationError("domains_or_instance_ids", "required") ErrBatchSizeMustBePositive = errors.NewValidationError("batch_size", "must be positive") ErrTimeoutMustBePositive = errors.NewValidationError("timeout", "must be positive") ErrDomainsRequiredForAggregation = errors.NewValidationError("domains", "required for aggregation") ErrWindowsRequiredForAggregation = errors.NewValidationError("windows", "required for aggregation") ErrInvalidWindowFormat = errors.NewValidationError("window", "invalid format") // Serverless health checker errors ErrHealthCheckEventValidationFailed = errors.ValidationFailedWithField("health check event") ErrServerlessHealthCheckFailed = errors.ProcessingFailed("serverless health check", stdErrors.New("serverless health check failed")) ErrHealthDataCleanupFailed = errors.ProcessingFailed("health data cleanup", stdErrors.New("health data cleanup failed")) )
Error constants for federation health package
Functions ¶
This section is empty.
Types ¶
type AggregationDetail ¶
type AggregationDetail struct {
Action string `json:"action"` // "aggregate_summaries"
Domains []string `json:"domains"` // Domains to aggregate
Windows []string `json:"windows"` // Time windows: ["1h", "24h", "7d"]
ForceRecalculate bool `json:"force_recalculate,omitempty"` // Recalculate even if recent summary exists
}
AggregationDetail contains aggregation configuration
type AggregationEvent ¶
type AggregationEvent struct {
Source string `json:"source"`
DetailType string `json:"detail-type"`
Time time.Time `json:"time"`
Detail AggregationDetail `json:"detail"`
}
AggregationEvent represents an EventBridge event for summary aggregation
func NewAggregationEvent ¶
func NewAggregationEvent(domains []string, windows []string) *AggregationEvent
NewAggregationEvent creates a new aggregation event
func (*AggregationEvent) FromJSON ¶
func (e *AggregationEvent) FromJSON(data []byte) error
FromJSON parses JSON bytes into an AggregationEvent
func (*AggregationEvent) ToJSON ¶
func (e *AggregationEvent) ToJSON() ([]byte, error)
ToJSON converts the aggregation event to JSON bytes
func (*AggregationEvent) Validate ¶
func (e *AggregationEvent) Validate() error
Validate checks if the aggregation event is valid
type CheckerConfig ¶
type CheckerConfig struct {
// HTTP configuration
RequestTimeout time.Duration `json:"request_timeout"`
MaxIdleConns int `json:"max_idle_conns"`
MaxIdleConnsPerHost int `json:"max_idle_conns_per_host"`
IdleConnTimeout time.Duration `json:"idle_conn_timeout"`
FollowRedirects bool `json:"follow_redirects"`
UserAgent string `json:"user_agent"`
// Concurrency configuration
MaxConcurrentChecks int `json:"max_concurrent_checks"`
// Retry configuration
MaxRetries int `json:"max_retries"`
RetryBackoff time.Duration `json:"retry_backoff"`
// Validation configuration
RequiredHeaders map[string]string `json:"required_headers"`
ValidStatusCodes []int `json:"valid_status_codes"`
}
CheckerConfig contains configuration for the health checker
func DefaultConfig ¶
func DefaultConfig() CheckerConfig
DefaultConfig returns a sensible default configuration
type DomainHealthCheckResult ¶
type DomainHealthCheckResult struct {
Domain string `json:"domain"`
Success bool `json:"success"`
Reachable bool `json:"reachable"`
StatusCode int `json:"status_code"`
ResponseTime time.Duration `json:"response_time"`
ErrorMessage string `json:"error_message,omitempty"`
HealthScore float64 `json:"health_score"`
CheckedAt time.Time `json:"checked_at"`
// Federation-specific metrics
InboxBacklog int `json:"inbox_backlog,omitempty"`
ProcessingDelay time.Duration `json:"processing_delay,omitempty"`
}
DomainHealthCheckResult represents health check result for a single domain
type HealthCheckDetail ¶
type HealthCheckDetail struct {
// Action type
Action string `json:"action"` // "check_health", "aggregate_summary", "cleanup"
// Instance configuration
InstanceIDs []string `json:"instance_ids,omitempty"` // Specific instances to check
Domains []string `json:"domains,omitempty"` // Domains to check
BatchSize int `json:"batch_size,omitempty"` // Number of instances per batch
// Time window configuration
WindowHours int `json:"window_hours,omitempty"` // Hours to look back for aggregation
// Check configuration
Timeout int `json:"timeout,omitempty"` // Request timeout in seconds
FollowRedirects bool `json:"follow_redirects,omitempty"` // Whether to follow HTTP redirects
UserAgent string `json:"user_agent,omitempty"` // Custom user agent
// Aggregation configuration
SummaryWindows []string `json:"summary_windows,omitempty"` // ["1h", "24h", "7d"]
// Cleanup configuration
RetentionDays int `json:"retention_days,omitempty"` // Days to keep health data
}
HealthCheckDetail contains the specifics of what to check
type HealthCheckError ¶
type HealthCheckError struct {
Domain string `json:"domain,omitempty"`
ErrorType string `json:"error_type"` // "network", "timeout", "invalid_response", "database"
ErrorMessage string `json:"error_message"`
Timestamp time.Time `json:"timestamp"`
}
HealthCheckError represents an error during health checking
type HealthCheckEvent ¶
type HealthCheckEvent struct {
// Event metadata
Source string `json:"source"` // "lesser.federation.health"
DetailType string `json:"detail-type"` // "Health Check Request"
Time time.Time `json:"time"`
Region string `json:"region"`
Account string `json:"account"`
// Event detail
Detail HealthCheckDetail `json:"detail"`
}
HealthCheckEvent represents an EventBridge event for triggering health checks
func NewHealthCheckEvent ¶
func NewHealthCheckEvent(domains []string, batchSize int) *HealthCheckEvent
NewHealthCheckEvent creates a new health check event
func (*HealthCheckEvent) FromJSON ¶
func (e *HealthCheckEvent) FromJSON(data []byte) error
FromJSON parses JSON bytes into a HealthCheckEvent
func (*HealthCheckEvent) GetBatchedDomains ¶
func (e *HealthCheckEvent) GetBatchedDomains() [][]string
GetBatchedDomains splits domains into batches based on batch size
func (*HealthCheckEvent) ToJSON ¶
func (e *HealthCheckEvent) ToJSON() ([]byte, error)
ToJSON converts the event to JSON bytes
func (*HealthCheckEvent) Validate ¶
func (e *HealthCheckEvent) Validate() error
Validate checks if the health check event is valid
type HealthCheckResult ¶
type HealthCheckResult struct {
// Event metadata
EventID string `json:"event_id"`
Source string `json:"source"`
Timestamp time.Time `json:"timestamp"`
// Results
CheckedDomains []string `json:"checked_domains"`
SuccessfulChecks int `json:"successful_checks"`
FailedChecks int `json:"failed_checks"`
Results []DomainHealthCheckResult `json:"results"`
// Performance metrics
TotalDuration time.Duration `json:"total_duration"`
AvgDuration time.Duration `json:"avg_duration"`
// Errors
Errors []HealthCheckError `json:"errors,omitempty"`
}
HealthCheckResult represents the result of health checking operation
type ScheduledEventDetail ¶
type ScheduledEventDetail struct {
// Schedule information
ScheduleName string `json:"schedule_name"` // Name of the EventBridge rule
ScheduleType string `json:"schedule_type"` // "health_check", "aggregation", "cleanup"
// Configuration
BatchSize int `json:"batch_size,omitempty"` // Instances per invocation
MaxInstances int `json:"max_instances,omitempty"` // Total instances to check
Windows []string `json:"windows,omitempty"` // Time windows for aggregation
}
ScheduledEventDetail contains configuration for scheduled health checks
type ScheduledHealthCheckEvent ¶
type ScheduledHealthCheckEvent struct {
// Standard EventBridge scheduled event fields
Source string `json:"source"` // "aws.events"
DetailType string `json:"detail-type"` // "Scheduled Event"
Time time.Time `json:"time"`
Account string `json:"account"`
Region string `json:"region"`
// Custom detail for health checking
Detail ScheduledEventDetail `json:"detail"`
}
ScheduledHealthCheckEvent represents a scheduled health check trigger
type ServerlessHealthChecker ¶
type ServerlessHealthChecker struct {
// contains filtered or unexported fields
}
ServerlessHealthChecker performs stateless health checks triggered by EventBridge
func NewServerlessHealthChecker ¶
func NewServerlessHealthChecker(db core.DB, tableName string, logger *zap.Logger, config CheckerConfig) *ServerlessHealthChecker
NewServerlessHealthChecker creates a new serverless health checker
func (*ServerlessHealthChecker) GetHealthHistory ¶
func (c *ServerlessHealthChecker) GetHealthHistory(ctx context.Context, domain string, since time.Time, limit int) ([]*models.InstanceHealth, error)
GetHealthHistory retrieves health history for a domain
func (*ServerlessHealthChecker) GetHealthStatus ¶
func (c *ServerlessHealthChecker) GetHealthStatus(ctx context.Context, domain string) (*models.InstanceHealth, error)
GetHealthStatus retrieves the latest health status for a domain
func (*ServerlessHealthChecker) GetHealthSummary ¶
func (c *ServerlessHealthChecker) GetHealthSummary(ctx context.Context, domain string, window time.Duration) (*models.InstanceHealthSummary, error)
GetHealthSummary retrieves an aggregated health summary
func (*ServerlessHealthChecker) GetUnhealthyInstances ¶
func (c *ServerlessHealthChecker) GetUnhealthyInstances(ctx context.Context, threshold float64) ([]string, error)
GetUnhealthyInstances returns a list of currently unhealthy instances
func (*ServerlessHealthChecker) ProcessHealthCheckEvent ¶
func (c *ServerlessHealthChecker) ProcessHealthCheckEvent(ctx context.Context, event *HealthCheckEvent) (*HealthCheckResult, error)
ProcessHealthCheckEvent processes an EventBridge health check event