realtime

package
v0.0.8-beta Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

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

func (h *EventHub) BroadcastLog(l LogEntry)

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.

func (*EventHub) Start

func (h *EventHub) Start(ctx context.Context, snapshotInterval, batchInterval time.Duration)

Start begins the periodic flush loops. Call in a goroutine.

func (*EventHub) Stop

func (h *EventHub) Stop()

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 NewHub

func NewHub(onConnectionChange func(count int)) *Hub

NewHub creates a new buffered WebSocket hub.

func (*Hub) Broadcast

func (h *Hub) Broadcast(entry LogEntry)

Broadcast adds a log entry to the broadcast buffer.

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.

func (*Hub) Run

func (h *Hub) Run()

Run starts the hub's main event loop. Should be called in a goroutine.

func (*Hub) Stop

func (h *Hub) Stop()

Stop gracefully shuts down the hub.

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.

Jump to

Keyboard shortcuts

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