Documentation
¶
Index ¶
- Constants
- Variables
- func ParseUUIDFromString(uuidStr string) (*openapi_types.UUID, error)
- type AllowAllFilter
- type BaseEvent
- type BotEvent
- func CreateBotRegisteredEvent(botID openapi_types.UUID, botName string, capabilities []string) *BotEvent
- func CreateBotStatusChangedEvent(botID openapi_types.UUID, oldStatus, newStatus string) *BotEvent
- func NewBotEvent(eventType string, botID openapi_types.UUID, data map[string]interface{}) *BotEvent
- type CampaignEvent
- type Client
- type ClientConfig
- type ClientInfo
- type CompoundFilter
- type Config
- type ConnectionInfo
- type CorpusEvent
- type CrashEvent
- type Event
- type EventHistory
- type Filter
- type FilterBuilder
- func (fb *FilterBuilder) AddPatternFilter(pattern string) *FilterBuilder
- func (fb *FilterBuilder) AddResourceFilter(resourceType, resourceID string) *FilterBuilder
- func (fb *FilterBuilder) AddSeverityFilter(minSeverity string) *FilterBuilder
- func (fb *FilterBuilder) AddTypeFilter(types string) *FilterBuilder
- func (fb *FilterBuilder) Build() Filter
- func (fb *FilterBuilder) BuildOr() Filter
- type HealthStatus
- type JobEvent
- type Manager
- func (m *Manager) Broadcast(event Event) error
- func (m *Manager) BroadcastToTopic(topic string, event Event) error
- func (m *Manager) GetClients() []ClientInfo
- func (m *Manager) GetMetrics() *Metrics
- func (m *Manager) Register(client *Client) error
- func (m *Manager) Start(ctx context.Context) error
- func (m *Manager) Stop() error
- func (m *Manager) Subscribe(clientID string, topic string) error
- func (m *Manager) Unregister(client *Client) error
- func (m *Manager) Unsubscribe(clientID string, topic string) error
- type ManagerStats
- type Metrics
- func (m *Metrics) DecrementActiveClients()
- func (m *Metrics) GetActiveClients() int64
- func (m *Metrics) GetEventsDropped() int64
- func (m *Metrics) GetEventsPerSecond() float64
- func (m *Metrics) GetEventsSent() int64
- func (m *Metrics) GetTotalClients() int64
- func (m *Metrics) GetUptime() time.Duration
- func (m *Metrics) IncrementActiveClients()
- func (m *Metrics) IncrementEventsDropped()
- func (m *Metrics) IncrementEventsSent()
- func (m *Metrics) Snapshot() MetricsSnapshot
- type MetricsSnapshot
- type PatternFilter
- type ResourceFilter
- type SeverityFilter
- type StoredEvent
- type SystemEvent
- type TopicStats
- type TypeFilter
Constants ¶
const ( // Bot events EventBotRegistered = "bot.registered" EventBotUnregistered = "bot.unregistered" EventBotHeartbeat = "bot.heartbeat" EventBotStatusChanged = "bot.status_changed" EventBotJobAssigned = "bot.job_assigned" EventBotJobCompleted = "bot.job_completed" EventBotError = "bot.error" // Job events EventJobCreated = "job.created" EventJobStarted = "job.started" EventJobProgress = "job.progress" EventJobCompleted = "job.completed" EventJobFailed = "job.failed" EventJobCancelled = "job.cancelled" EventJobTimeout = "job.timeout" EventJobRestarted = "job.restarted" // Campaign events EventCampaignCreated = "campaign.created" EventCampaignStarted = "campaign.started" EventCampaignPaused = "campaign.paused" EventCampaignResumed = "campaign.resumed" EventCampaignCompleted = "campaign.completed" EventCampaignFailed = "campaign.failed" EventCampaignDeleted = "campaign.deleted" EventCampaignUpdated = "campaign.updated" // Corpus events EventCorpusSync = "corpus.sync" EventCorpusUpdated = "corpus.updated" EventCorpusQuarantined = "corpus.quarantined" EventCorpusRestored = "corpus.restored" EventCorpusDeleted = "corpus.deleted" EventCorpusCreated = "corpus.created" // Crash events EventCrashDetected = "crash.detected" EventCrashAnalyzed = "crash.analyzed" EventCrashDuplicate = "crash.duplicate" EventCrashMinimized = "crash.minimized" EventCrashReproduced = "crash.reproduced" EventCrashClassified = "crash.classified" // System events EventSystemHeartbeat = "system.heartbeat" EventSystemAlert = "system.alert" EventSystemMaintenance = "system.maintenance" EventClientConnected = "client.connected" EventClientDisconnected = "client.disconnected" EventClientReconnected = "client.reconnected" )
Event type constants for consistency
Variables ¶
var ( ErrManagerAlreadyRunning = errors.New("SSE manager is already running") ErrManagerNotRunning = errors.New("SSE manager is not running") ErrManagerStopped = errors.New("SSE manager has been stopped") ErrMaxClientsReached = errors.New("maximum number of clients reached") ErrRegistrationQueueFull = errors.New("client registration queue is full") ErrUnregistrationQueueFull = errors.New("client unregistration queue is full") ErrBroadcastQueueFull = errors.New("broadcast queue is full") ErrClientNotFound = errors.New("client not found") ErrClientClosed = errors.New("client connection is closed") ErrRateLimited = errors.New("event dropped due to rate limiting") ErrBufferFull = errors.New("client buffer is full") )
Common errors
Functions ¶
func ParseUUIDFromString ¶
func ParseUUIDFromString(uuidStr string) (*openapi_types.UUID, error)
ParseUUIDFromString safely parses a UUID string
Types ¶
type AllowAllFilter ¶
type AllowAllFilter struct{}
AllowAllFilter is a filter that allows all events
func (*AllowAllFilter) Matches ¶
func (f *AllowAllFilter) Matches(event Event) bool
Matches always returns true
func (*AllowAllFilter) String ¶
func (f *AllowAllFilter) String() string
String returns a string representation of the filter
type BaseEvent ¶
type BaseEvent struct {
ID string `json:"id"`
Type string `json:"type"`
Timestamp time.Time `json:"timestamp"`
Data map[string]interface{} `json:"data"`
}
BaseEvent provides common functionality for all events
func NewBaseEvent ¶
NewBaseEvent creates a new base event with generated ID and current timestamp
type BotEvent ¶
type BotEvent struct {
*BaseEvent
BotID openapi_types.UUID `json:"bot_id"`
BotName string `json:"bot_name,omitempty"`
CampaignID *openapi_types.UUID `json:"campaign_id,omitempty"`
}
BotEvent represents bot-related events
func CreateBotRegisteredEvent ¶
func CreateBotRegisteredEvent(botID openapi_types.UUID, botName string, capabilities []string) *BotEvent
CreateBotRegisteredEvent creates a bot registration event
func CreateBotStatusChangedEvent ¶
func CreateBotStatusChangedEvent(botID openapi_types.UUID, oldStatus, newStatus string) *BotEvent
CreateBotStatusChangedEvent creates a bot status change event
func NewBotEvent ¶
func NewBotEvent(eventType string, botID openapi_types.UUID, data map[string]interface{}) *BotEvent
NewBotEvent creates a new bot event
type CampaignEvent ¶
type CampaignEvent struct {
*BaseEvent
CampaignID openapi_types.UUID `json:"campaign_id"`
State string `json:"state,omitempty"`
}
CampaignEvent represents campaign-related events
func CreateCampaignStateChangeEvent ¶
func CreateCampaignStateChangeEvent(campaignID openapi_types.UUID, oldState, newState string) *CampaignEvent
CreateCampaignStateChangeEvent creates a campaign state change event
func NewCampaignEvent ¶
func NewCampaignEvent(eventType string, campaignID openapi_types.UUID, data map[string]interface{}) *CampaignEvent
NewCampaignEvent creates a new campaign event
type Client ¶
type Client struct {
// Identity
ID string
// HTTP connection
ResponseWriter http.ResponseWriter
Request *http.Request
// Event channel
Send chan Event
// Subscriptions and filters
Topics map[string]bool
Filters []Filter
// SSE state
LastEventID string
Connected time.Time
// contains filtered or unexported fields
}
Client represents an SSE client connection
func NewClient ¶
func NewClient(id string, w http.ResponseWriter, r *http.Request, config ClientConfig, logger logrus.FieldLogger) *Client
NewClient creates a new SSE client with the given configuration
func (*Client) GetInfo ¶
func (c *Client) GetInfo() ClientInfo
GetInfo returns client information for monitoring
func (*Client) RemoveFilter ¶
RemoveFilter removes an event filter from the client
type ClientConfig ¶
type ClientConfig struct {
BufferSize int `json:"buffer_size" yaml:"buffer_size"`
WriteTimeout time.Duration `json:"write_timeout" yaml:"write_timeout"`
MaxEventsPerSec int `json:"max_events_per_sec" yaml:"max_events_per_sec"`
BurstSize int `json:"burst_size" yaml:"burst_size"`
EnableCompression bool `json:"enable_compression" yaml:"enable_compression"`
}
ClientConfig holds per-client configuration
func DefaultClientConfig ¶
func DefaultClientConfig() ClientConfig
DefaultClientConfig returns sensible defaults for SSE clients
type ClientInfo ¶
type ClientInfo struct {
ID string `json:"id"`
Connected time.Time `json:"connected"`
LastEventID string `json:"last_event_id"`
Topics []string `json:"topics"`
IsAlive bool `json:"is_alive"`
EventsSent int64 `json:"events_sent"`
}
ClientInfo provides information about a client for status purposes
type CompoundFilter ¶
CompoundFilter combines multiple filters with AND logic
func NewCompoundFilter ¶
func NewCompoundFilter(logic string, filters ...Filter) *CompoundFilter
NewCompoundFilter creates a new compound filter
func (*CompoundFilter) Matches ¶
func (f *CompoundFilter) Matches(event Event) bool
Matches checks if the event passes all filters (AND) or any filter (OR)
func (*CompoundFilter) String ¶
func (f *CompoundFilter) String() string
String returns a string representation of the filter
type Config ¶
type Config struct {
// Client configuration
MaxClients int `json:"max_clients" yaml:"max_clients"`
ClientTimeout time.Duration `json:"client_timeout" yaml:"client_timeout"`
WriteTimeout time.Duration `json:"write_timeout" yaml:"write_timeout"`
HeartbeatInterval time.Duration `json:"heartbeat_interval" yaml:"heartbeat_interval"`
// Buffer configuration
EventBufferSize int `json:"event_buffer_size" yaml:"event_buffer_size"`
ClientBufferSize int `json:"client_buffer_size" yaml:"client_buffer_size"`
BroadcastBufferSize int `json:"broadcast_buffer_size" yaml:"broadcast_buffer_size"`
// Rate limiting
MaxEventsPerSecond int `json:"max_events_per_second" yaml:"max_events_per_second"`
BurstSize int `json:"burst_size" yaml:"burst_size"`
// Cleanup configuration
CleanupInterval time.Duration `json:"cleanup_interval" yaml:"cleanup_interval"`
MaxEventHistory int `json:"max_event_history" yaml:"max_event_history"`
}
Config holds SSE manager configuration
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns sensible defaults for SSE manager
type ConnectionInfo ¶
type ConnectionInfo struct {
RemoteAddr string `json:"remote_addr"`
UserAgent string `json:"user_agent"`
Headers map[string]string `json:"headers"`
ConnectedAt time.Time `json:"connected_at"`
LastEventID string `json:"last_event_id"`
BytesSent int64 `json:"bytes_sent"`
EventsSent int64 `json:"events_sent"`
}
ConnectionInfo provides detailed connection information
type CorpusEvent ¶
type CorpusEvent struct {
*BaseEvent
CorpusID *openapi_types.UUID `json:"corpus_id,omitempty"`
JobID *openapi_types.UUID `json:"job_id,omitempty"`
CampaignID *openapi_types.UUID `json:"campaign_id,omitempty"`
Operation string `json:"operation,omitempty"`
}
CorpusEvent represents corpus-related events
func CreateCorpusSyncEvent ¶
func CreateCorpusSyncEvent(jobID, campaignID openapi_types.UUID, operation string, count int) *CorpusEvent
CreateCorpusSyncEvent creates a corpus synchronization event
func NewCorpusEvent ¶
func NewCorpusEvent(eventType string, data map[string]interface{}) *CorpusEvent
NewCorpusEvent creates a new corpus event
type CrashEvent ¶
type CrashEvent struct {
*BaseEvent
CrashID openapi_types.UUID `json:"crash_id"`
JobID openapi_types.UUID `json:"job_id"`
CampaignID openapi_types.UUID `json:"campaign_id"`
CrashType string `json:"crash_type,omitempty"`
Severity string `json:"severity,omitempty"`
}
CrashEvent represents crash-related events
func CreateCrashDetectedEvent ¶
func CreateCrashDetectedEvent(crashID, jobID, campaignID openapi_types.UUID, crashType, stackTrace string) *CrashEvent
CreateCrashDetectedEvent creates a crash detection event
func NewCrashEvent ¶
func NewCrashEvent(eventType string, crashID, jobID, campaignID openapi_types.UUID, data map[string]interface{}) *CrashEvent
NewCrashEvent creates a new crash event
type EventHistory ¶
type EventHistory struct {
// contains filtered or unexported fields
}
EventHistory stores recent events for replay functionality
func NewEventHistory ¶
func NewEventHistory(maxSize int) *EventHistory
NewEventHistory creates a new event history with specified size
func (*EventHistory) Add ¶
func (eh *EventHistory) Add(event Event)
Add stores an event in the history
func (*EventHistory) GetEventsAfter ¶
func (eh *EventHistory) GetEventsAfter(eventID string) []StoredEvent
GetEventsAfter returns events after the specified event ID
type Filter ¶
Filter represents an event filtering interface
func ParseFiltersFromParams ¶
ParseFiltersFromParams parses filters from HTTP query parameters
type FilterBuilder ¶
type FilterBuilder struct {
// contains filtered or unexported fields
}
FilterBuilder helps build complex filters from query parameters
func NewFilterBuilder ¶
func NewFilterBuilder() *FilterBuilder
NewFilterBuilder creates a new filter builder
func (*FilterBuilder) AddPatternFilter ¶
func (fb *FilterBuilder) AddPatternFilter(pattern string) *FilterBuilder
AddPatternFilter adds a pattern filter
func (*FilterBuilder) AddResourceFilter ¶
func (fb *FilterBuilder) AddResourceFilter(resourceType, resourceID string) *FilterBuilder
AddResourceFilter adds a resource filter
func (*FilterBuilder) AddSeverityFilter ¶
func (fb *FilterBuilder) AddSeverityFilter(minSeverity string) *FilterBuilder
AddSeverityFilter adds a severity filter
func (*FilterBuilder) AddTypeFilter ¶
func (fb *FilterBuilder) AddTypeFilter(types string) *FilterBuilder
AddTypeFilter adds a type filter from comma-separated event types
func (*FilterBuilder) Build ¶
func (fb *FilterBuilder) Build() Filter
Build creates a compound filter with AND logic
func (*FilterBuilder) BuildOr ¶
func (fb *FilterBuilder) BuildOr() Filter
BuildOr creates a compound filter with OR logic
type HealthStatus ¶
type HealthStatus struct {
Status string `json:"status"` // "healthy", "degraded", "unhealthy"
Timestamp time.Time `json:"timestamp"`
Uptime string `json:"uptime"`
Metrics MetricsSnapshot `json:"metrics"`
Issues []string `json:"issues,omitempty"`
Details map[string]any `json:"details,omitempty"`
}
HealthStatus represents the health of the SSE system
type JobEvent ¶
type JobEvent struct {
*BaseEvent
JobID openapi_types.UUID `json:"job_id"`
BotID *openapi_types.UUID `json:"bot_id,omitempty"`
CampaignID openapi_types.UUID `json:"campaign_id"`
Status string `json:"status,omitempty"`
}
JobEvent represents job-related events
func CreateJobCompletedEvent ¶
func CreateJobCompletedEvent(jobID, campaignID openapi_types.UUID, duration time.Duration, results map[string]interface{}) *JobEvent
CreateJobCompletedEvent creates a job completion event
func CreateJobProgressEvent ¶
func CreateJobProgressEvent(jobID, campaignID openapi_types.UUID, progress float64, details map[string]interface{}) *JobEvent
CreateJobProgressEvent creates a job progress event
func NewJobEvent ¶
func NewJobEvent(eventType string, jobID, campaignID openapi_types.UUID, data map[string]interface{}) *JobEvent
NewJobEvent creates a new job event
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles SSE client connections and event broadcasting
func NewManager ¶
func NewManager(config Config, logger logrus.FieldLogger) *Manager
NewManager creates a new SSE manager with the given configuration
func (*Manager) BroadcastToTopic ¶
BroadcastToTopic sends an event to all clients subscribed to a specific topic
func (*Manager) GetClients ¶
func (m *Manager) GetClients() []ClientInfo
GetClients returns information about all connected clients
func (*Manager) GetMetrics ¶
GetMetrics returns current metrics
func (*Manager) Unregister ¶
Unregister removes an SSE client from the manager
type ManagerStats ¶
type ManagerStats struct {
Status string `json:"status"`
Uptime string `json:"uptime"`
Metrics MetricsSnapshot `json:"metrics"`
Topics []TopicStats `json:"topics"`
Clients []ClientInfo `json:"clients"`
Configuration Config `json:"configuration"`
Health HealthStatus `json:"health"`
}
ManagerStats provides comprehensive statistics about the SSE manager
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
Metrics holds various metrics for the SSE manager
func (*Metrics) DecrementActiveClients ¶
func (m *Metrics) DecrementActiveClients()
DecrementActiveClients decrements the active clients counter
func (*Metrics) GetActiveClients ¶
GetActiveClients returns the current number of active clients
func (*Metrics) GetEventsDropped ¶
GetEventsDropped returns the total number of events dropped
func (*Metrics) GetEventsPerSecond ¶
GetEventsPerSecond returns the average events per second
func (*Metrics) GetEventsSent ¶
GetEventsSent returns the total number of events sent
func (*Metrics) GetTotalClients ¶
GetTotalClients returns the total number of clients that have connected
func (*Metrics) IncrementActiveClients ¶
func (m *Metrics) IncrementActiveClients()
IncrementActiveClients increments the active clients counter
func (*Metrics) IncrementEventsDropped ¶
func (m *Metrics) IncrementEventsDropped()
IncrementEventsDropped increments the events dropped counter
func (*Metrics) IncrementEventsSent ¶
func (m *Metrics) IncrementEventsSent()
IncrementEventsSent increments the events sent counter
func (*Metrics) Snapshot ¶
func (m *Metrics) Snapshot() MetricsSnapshot
Snapshot creates a metrics snapshot
type MetricsSnapshot ¶
type MetricsSnapshot struct {
ActiveClients int64 `json:"active_clients"`
TotalClients int64 `json:"total_clients"`
EventsSent int64 `json:"events_sent"`
EventsDropped int64 `json:"events_dropped"`
EventsPerSecond float64 `json:"events_per_second"`
Uptime string `json:"uptime"`
Timestamp time.Time `json:"timestamp"`
}
MetricsSnapshot represents a point-in-time snapshot of metrics
type PatternFilter ¶
PatternFilter filters events using regex patterns on event types
func NewPatternFilter ¶
func NewPatternFilter(pattern string) (*PatternFilter, error)
NewPatternFilter creates a new pattern filter with the given regex
func (*PatternFilter) Matches ¶
func (f *PatternFilter) Matches(event Event) bool
Matches checks if the event type matches the pattern
func (*PatternFilter) String ¶
func (f *PatternFilter) String() string
String returns a string representation of the filter
type ResourceFilter ¶
type ResourceFilter struct {
ResourceType string // "bot", "job", "campaign", "crash", "corpus"
ResourceID string
}
ResourceFilter filters events by resource ID (bot, job, campaign, etc.)
func NewResourceFilter ¶
func NewResourceFilter(resourceType, resourceID string) *ResourceFilter
NewResourceFilter creates a new resource filter
func (*ResourceFilter) Matches ¶
func (f *ResourceFilter) Matches(event Event) bool
Matches checks if the event relates to the specified resource
func (*ResourceFilter) String ¶
func (f *ResourceFilter) String() string
String returns a string representation of the filter
type SeverityFilter ¶
SeverityFilter filters events by severity level
func NewSeverityFilter ¶
func NewSeverityFilter(minSeverity string) *SeverityFilter
NewSeverityFilter creates a new severity filter
func (*SeverityFilter) Matches ¶
func (f *SeverityFilter) Matches(event Event) bool
Matches checks if the event severity meets the minimum level
func (*SeverityFilter) String ¶
func (f *SeverityFilter) String() string
String returns a string representation of the filter
type StoredEvent ¶
type StoredEvent struct {
Event Event `json:"event"`
Timestamp time.Time `json:"timestamp"`
ID string `json:"id"`
}
StoredEvent represents an event stored in history
type SystemEvent ¶
type SystemEvent struct {
*BaseEvent
Component string `json:"component,omitempty"`
Severity string `json:"severity,omitempty"`
}
SystemEvent represents system-level events
func CreateSystemAlertEvent ¶
func CreateSystemAlertEvent(component, severity, message string, details map[string]interface{}) *SystemEvent
CreateSystemAlertEvent creates a system alert event
func NewSystemEvent ¶
func NewSystemEvent(eventType string, data map[string]interface{}) *SystemEvent
NewSystemEvent creates a new system event
type TopicStats ¶
type TopicStats struct {
Name string `json:"name"`
Subscribers int `json:"subscribers"`
EventsSent int64 `json:"events_sent"`
LastActivity time.Time `json:"last_activity"`
}
TopicStats provides statistics for a topic
type TypeFilter ¶
TypeFilter filters events by their type
func NewTypeFilter ¶
func NewTypeFilter(eventTypes []string) *TypeFilter
NewTypeFilter creates a new type filter with the given event types
func (*TypeFilter) Matches ¶
func (f *TypeFilter) Matches(event Event) bool
Matches checks if the event type is in the allowed types
func (*TypeFilter) String ¶
func (f *TypeFilter) String() string
String returns a string representation of the filter