Documentation
¶
Index ¶
- type EventHub
- func (h *EventHub) BroadcastLog(l LogEntry)
- func (h *EventHub) BroadcastMetric(m MetricEntry)
- func (h *EventHub) HandleWebSocket(w http.ResponseWriter, r *http.Request)
- func (h *EventHub) NotifyRefresh()
- func (h *EventHub) Start(ctx context.Context, snapshotInterval, batchInterval time.Duration)
- func (h *EventHub) Stop()
- type Hub
- type HubBatch
- type LiveSnapshot
- type LogEntry
- type MetricEntry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EventHub ¶
type EventHub struct {
// contains filtered or unexported fields
}
EventHub manages WebSocket clients and pushes live data snapshots filtered per-client's selected service. Debounces rapid ingestion bursts and only computes snapshots every flush interval.
func NewEventHub ¶
func NewEventHub(repo *storage.Repository, onConnect, onDisconnect func()) *EventHub
NewEventHub creates a new event notification hub.
func (*EventHub) BroadcastLog ¶
BroadcastLog adds a log entry to the real-time buffer.
func (*EventHub) BroadcastMetric ¶
func (h *EventHub) BroadcastMetric(m MetricEntry)
BroadcastMetric adds a metric entry to the real-time buffer.
func (*EventHub) HandleWebSocket ¶
func (h *EventHub) HandleWebSocket(w http.ResponseWriter, r *http.Request)
HandleWebSocket upgrades an HTTP request to a WebSocket connection, registers it as an event client, and listens for filter messages.
func (*EventHub) NotifyRefresh ¶
func (h *EventHub) NotifyRefresh()
notifyRefresh marks that new data has arrived. The actual snapshot happens on the next snapshotTicker flush.
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub is a buffered WebSocket broadcast hub.
Instead of broadcasting each log individually (which would freeze the UI at high throughput), it buffers logs and flushes them as a JSON array when either:
- Buffer size >= maxBufferSize (default: 100)
- Flush ticker fires (default: every 500ms)
func (*Hub) BroadcastMetric ¶
func (h *Hub) BroadcastMetric(entry MetricEntry)
BroadcastMetric adds a metric entry to the broadcast buffer.
func (*Hub) HandleWebSocket ¶
func (h *Hub) HandleWebSocket(w http.ResponseWriter, r *http.Request)
HandleWebSocket is the HTTP handler that upgrades connections to WebSocket.
type HubBatch ¶
type HubBatch struct {
Type string `json:"type"` // "logs" or "metrics"
Data interface{} `json:"data"` // Slice of entries
}
HubBatch is a unified payload for WebSocket broadcasts.
type LiveSnapshot ¶
type LiveSnapshot struct {
Type string `json:"type"`
Dashboard *storage.DashboardStats `json:"dashboard"`
Traffic []storage.TrafficPoint `json:"traffic"`
Traces *storage.TracesResponse `json:"traces"`
ServiceMap *storage.ServiceMapMetrics `json:"service_map"`
}
LiveSnapshot is the data payload pushed to all event WS clients.
type LogEntry ¶
type LogEntry struct {
ID uint `json:"id"`
TraceID string `json:"trace_id"`
SpanID string `json:"span_id"`
Severity string `json:"severity"`
Body string `json:"body"`
ServiceName string `json:"service_name"`
AttributesJSON string `json:"attributes_json"`
AIInsight string `json:"ai_insight,omitempty"`
Timestamp time.Time `json:"timestamp"`
}
LogEntry is a lightweight struct for WebSocket broadcast payloads.
type MetricEntry ¶
type MetricEntry struct {
Name string `json:"name"`
ServiceName string `json:"service_name"`
Value float64 `json:"value"`
Timestamp time.Time `json:"timestamp"`
Attributes map[string]interface{} `json:"attributes"`
}
MetricEntry represents a raw metric point for real-time visualization.