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 ¶
- func MountWebhooks(mux *http.ServeMux, built []Built, auth func(*http.Request) bool, ...)
- func Register(d Descriptor)
- func RunWatchers(ctx context.Context, built []Built, enq investigate.Enqueuer, ...)
- type Admission
- type Built
- type DecodeResult
- type Deps
- type Descriptor
- type Kind
- type Pipeline
- type Resolution
- type ResolveFunc
- type WatcherSource
- type WebhookSource
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.
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 ¶
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; 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).
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.
type Resolution ¶
Resolution records that a previously firing alert has resolved.
type ResolveFunc ¶
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). |