Documentation
¶
Overview ¶
Package webhook is the L11 plugin that delivers core daemon events to an external HTTP(S) endpoint. Subscribes to the daemon's event bus through coreapi.Deps.Events and POSTs each event as a JSON payload. Owns the HTTP client, retry+circuit-breaker state, and the persisted-URL file (~/.pilot/webhook_url) — none of which pkg/daemon (L7) is allowed to know about.
Extracted from pkg/daemon/webhook.go in T4.1 (webhook-inversion). The daemon publishes; the plugin subscribes — the layered architecture's separation of "what happened" (core) from "tell the outside world" (plugin).
Index ¶
Constants ¶
const ( MaxRetries = 3 InitialBackoff = 1 * time.Second CircuitOpenThreshold = 5 CircuitCooldown = 30 * time.Second )
Tunable circuit-breaker + retry constants.
Variables ¶
This section is empty.
Functions ¶
func LoadPersistedURL ¶
LoadPersistedURL reads the previously-saved webhook URL. Returns empty string if no file exists or the contents don't pass validation.
func SavePersistedURL ¶
SavePersistedURL writes the URL to ~/.pilot/webhook_url, or deletes the file if url is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client dispatches events asynchronously to an HTTP(S) endpoint. If URL is empty, all methods are no-ops (zero overhead when disabled).
func (*Client) CircuitSkips ¶
CircuitSkips returns the number of events short-circuited because the breaker was open. Nil-safe.
func (*Client) Close ¶
func (wc *Client) Close()
Close drains the queue and stops the background goroutine. Idempotent. Waits up to 5 seconds for the queue to drain before abandoning remaining events.
type Event ¶
type Event struct {
EventID uint64 `json:"event_id"`
Event string `json:"event"`
NodeID uint32 `json:"node_id"`
Timestamp time.Time `json:"timestamp"`
Data interface{} `json:"data,omitempty"`
}
Event is the JSON payload POSTed to the webhook endpoint.
type Option ¶
type Option func(*Client)
Option configures a Client.
func WithCircuitCooldown ¶
WithCircuitCooldown overrides the default 30s circuit-breaker cooldown. Tests use a small value to exercise open→probe→reset cycles quickly.
func WithHTTPTimeout ¶
WithHTTPTimeout sets the HTTP client timeout (default 5s).
func WithRetryBackoff ¶
WithRetryBackoff sets the initial retry backoff (default 1s, doubles each retry).
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the L11 plugin that delivers core daemon events to an HTTP(S) endpoint. Implements coreapi.Service: on Start, subscribes to the bus ("*") and forwards every event to its internal Client. On Stop, cancels the subscription and drains the Client.
The URL can be hot-swapped at runtime via SetURL — that path is invoked from cmd/daemon when IPC's set-webhook handler fires.
func NewService ¶
NewService constructs a webhook plugin Service. initialURL is taken from the daemon's -webhook flag; if empty, the plugin tries the persisted URL file (~/.pilot/webhook_url) on Start.
func (*Service) Order ¶
Order: webhook starts AFTER core foundation (50-79: trust/identity) but BEFORE app services (100+) so it captures their startup events (node.registered, agent.registered, network.auto_joined). 90 is the observability slot per coreapi/lifecycle.go.
func (*Service) SetURL ¶
SetURL hot-swaps the webhook URL. Called from cmd/daemon's IPC adapter when `pilotctl set-webhook <url>` fires. An empty url disables webhook delivery (becomes a no-op until set again).