source

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package source registers event-source adapters and runs their core-owned transports. An adapter implements Webhook (push) or Watcher (pull) and self-registers via Register in an init() func; the core owns HTTP auth, body-cap, routing, the watcher runner, and the ingest pipeline.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MountWebhooks

func MountWebhooks(mux *http.ServeMux, built []Built, auth func(*http.Request) bool, pipe *Pipeline)

MountWebhooks registers every Webhook-kind source at its Path on mux.

func Register

func Register(d Descriptor)

Register adds a source adapter to the global registry. It panics on duplicate names and is intended to be called from adapter init() functions.

func RunWatchers

func RunWatchers(ctx context.Context, built []Built, enq investigate.Enqueuer, dedup *trigger.Deduper, deb *investigate.Debouncer, log *slog.Logger)

RunWatchers starts each Watcher source and drains its Requests into enq, applying the same dedup + debounce as the legacy gitops-failure path: dedup (when non-nil) suppresses repeated failures for the same workload (key "namespace/name"); deb (when non-nil) delays enqueue until the failure persists (a zero-window debouncer enqueues immediately). A watch error is logged and that source skipped, without affecting siblings.

Types

type Admission

type Admission int

Admission is the gate policy applied to events admitted through the pipeline.

const (
	MatchGated Admission = iota
	EnableGated
)

MatchGated events must pass the triggers.incidents match policy (alertmanager). EnableGated events are admitted whenever the source is enabled (gitops failures).

type Authenticator added in v0.3.0

type Authenticator interface {
	Authenticate(body []byte, h http.Header) bool
}

Authenticator is implemented by a webhook source that authenticates each delivery from the request body itself (e.g. an HMAC signature over the raw body) rather than via the shared bearer token. When a source implements it, the core calls Authenticate after reading the body and skips the shared auth: a source that signs its own requests (PagerDuty) cannot present the operator's bearer token, so it owns authentication end-to-end.

type Built

type Built struct {
	Desc Descriptor
	Impl any // WebhookSource or WatcherSource
}

Built pairs a Descriptor with the concrete adapter instance returned by its Build function. The core uses it to mount webhooks and run watchers.

func BuildEnabled

func BuildEnabled(deps Deps) ([]Built, error)

BuildEnabled calls each registered adapter's Build function and returns the non-nil results. A nil return from Build means the adapter is disabled (no config); an error aborts startup.

func (Built) Handler

func (b Built) Handler(auth func(*http.Request) bool, bodyCap int64, pipe *Pipeline) http.HandlerFunc

Handler builds the HTTP handler for a webhook source: shared auth, body cap, decode, and ingest. auth (may be nil) authenticates the request via the shared bearer token; a source implementing Authenticator authenticates itself from the body instead (shared auth is skipped for it). bodyCap is the max body size in bytes; pipe ingests the decoded result.

type DecodeResult

type DecodeResult struct {
	Requests []investigate.Request
	Resolved []Resolution
}

DecodeResult is returned by WebhookSource.Decode: a set of investigation requests (firing alerts) and a set of resolutions (resolved alerts).

type Deps

type Deps struct {
	Cfg    *config.Config
	GitOps providers.GitOpsProvider
	Log    *slog.Logger
	Raw    map[string]yaml.Node // raw `sources:` config, keyed by the source's short name (Descriptor.Name)
}

Deps carries the shared dependencies passed to each adapter's Build function.

type Descriptor

type Descriptor struct {
	Name      string
	Kind      Kind
	Admission Admission
	Path      string // webhook only
	Build     func(Deps) (any, error)
}

Descriptor is the self-registration record an adapter supplies to Register. An adapter reads its own config from Deps.Raw[Name].

func Registered

func Registered() []Descriptor

Registered returns all registered source descriptors in deterministic (alphabetical) order.

type Kind

type Kind int

Kind identifies whether a source adapter is push (Webhook) or pull (Watcher).

const (
	Webhook Kind = iota
	Watcher
)

Webhook is a push source driven by inbound HTTP calls; Watcher is a pull source that runs a long-lived goroutine to produce events.

type Pipeline

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

Pipeline admits inbound events from all source adapters, applies the configured gate policy (MatchGated or EnableGated), deduplicates within the configured window, and forwards survivors to the investigation enqueuer.

func NewPipeline

func NewPipeline(cfg *config.Config, enq investigate.Enqueuer, resolve ResolveFunc, log *slog.Logger) *Pipeline

NewPipeline creates a Pipeline. resolve may be nil to disable resolved-alert handling; metrics may be attached later via WithMetrics.

func (*Pipeline) Ingest

func (p *Pipeline) Ingest(ctx context.Context, adm Admission, res DecodeResult)

Ingest admits each Request per the admission mode and invokes resolve for each Resolution. Cascade-suppression and debounce for EnableGated sources are applied at the watcher edge (see Task 6) during Phase 1.

func (*Pipeline) WithContext added in v0.4.0

func (p *Pipeline) WithContext(ctx context.Context) *Pipeline

WithContext binds the lifetime of background debounce holds to ctx (typically the app/work context) so they stop cleanly on shutdown instead of running to their window end. Chains off NewPipeline; a nil ctx is ignored.

func (*Pipeline) WithMetrics

func (p *Pipeline) WithMetrics(m *telemetry.Metrics) *Pipeline

WithMetrics attaches the OTel metrics instance so admitted alerts (MatchGated) increment AlertsReceived and debounced self-resolving alerts increment IncidentsDebounced. Chains off NewPipeline; nil m is a no-op.

type Resolution

type Resolution struct {
	Fingerprint string
	At          time.Time
}

Resolution records that a previously firing alert has resolved.

type ResolveFunc

type ResolveFunc func(fingerprint string, at time.Time)

ResolveFunc records a resolved alert. main supplies a closure over the outcome.Ledger (+ metrics), so the pipeline stays decoupled from the ledger's concrete episode type. A nil ResolveFunc disables resolved-alert handling.

type WatcherSource

type WatcherSource interface {
	Watch(ctx context.Context) (<-chan investigate.Request, error)
}

WatcherSource is implemented by pull sources: the core calls Watch once and drains the returned channel for the lifetime of the leader term.

type WebhookSource

type WebhookSource interface {
	Decode(body []byte, h http.Header) (DecodeResult, error)
}

WebhookSource is implemented by push sources: the core calls Decode for each inbound HTTP request after authentication and body-capping.

Directories

Path Synopsis
Package alertmanager is the Alertmanager/VMAlert webhook source adapter.
Package alertmanager is the Alertmanager/VMAlert webhook source adapter.
Package gitops is the GitOps-failure watcher source adapter (Flux/Argo CD).
Package gitops is the GitOps-failure watcher source adapter (Flux/Argo CD).
Package pagerduty is the PagerDuty V3 webhook source adapter.
Package pagerduty is the PagerDuty V3 webhook source adapter.

Jump to

Keyboard shortcuts

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