eventsink

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package eventsink implements the optional webhook notification layer for BubbleFish Nexus. It tails the write path via a lossy buffered channel and delivers event payloads to configured HTTP sinks with per-sink exponential backoff retry.

INVARIANT: The event sink NEVER blocks the write path. The channel is lossy by design — if the channel is full, events are dropped and a metric is incremented.

Reference: Tech Spec Section 10.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	MaxInFlight         int
	RetryBackoffSeconds []int
	Sinks               []SinkConfig
	Metrics             Metrics
	Logger              *slog.Logger
}

Config holds the Sink configuration.

type Event

type Event struct {
	EventType   string          `json:"event_type"`
	PayloadID   string          `json:"payload_id"`
	Source      string          `json:"source"`
	Subject     string          `json:"subject"`
	Destination string          `json:"destination"`
	Timestamp   time.Time       `json:"timestamp"`
	ActorType   string          `json:"actor_type"`
	ActorID     string          `json:"actor_id"`
	Content     json.RawMessage `json:"content,omitempty"` // only when sink content="full"
}

Event is the payload sent to webhook sinks after a successful WAL append. Reference: Tech Spec Section 10.2.

type Metrics

type Metrics interface {
	IncDropped()
	IncDelivered()
	IncFailed()
}

Metrics is the interface for event sink Prometheus counters.

type Sink

type Sink struct {
	// contains filtered or unexported fields
}

Sink is the event sink engine. Call Emit from the write path (non-blocking). Call Stop during shutdown to drain pending events.

func New

func New(cfg Config) *Sink

New creates a Sink but does not start any goroutines. Call Start() next.

func (*Sink) Emit

func (s *Sink) Emit(e Event)

Emit sends an event to the sink channel. It NEVER blocks — if the channel is full, the event is dropped and bubblefish_events_dropped_total is incremented.

INVARIANT: This function is called on the write hot path. It must be non-blocking. Reference: Tech Spec Section 10.1.

func (*Sink) Start

func (s *Sink) Start()

Start launches a dispatcher goroutine that fans out events to per-sink delivery goroutines.

func (*Sink) Stop

func (s *Sink) Stop()

Stop signals the dispatcher to drain remaining events and stop. It blocks until all pending deliveries complete or the channel is drained. Safe to call multiple times (sync.Once).

type SinkConfig

type SinkConfig struct {
	Name           string
	URL            string
	TimeoutSeconds int
	MaxRetries     int
	Content        string // "summary" or "full"
}

SinkConfig describes a single webhook sink.

Jump to

Keyboard shortcuts

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