Documentation
¶
Overview ¶
Package webhook owns the optional HTTP surface for health, metrics and provider webhooks.
Index ¶
Constants ¶
const (
DefaultMaxBodyBytes = 64 * 1024
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
ListenAddr string
MetricsEnabled bool
TributeEnabled bool
TelegramEnabled bool
TributePath string
TelegramPath string
MaxBodyBytes int64
ReadHeaderTimeout time.Duration
ReadTimeout time.Duration
ShutdownTimeout time.Duration
Readiness Readiness
Metrics *Metrics
Tribute http.Handler
Telegram http.Handler
Logger *slog.Logger
}
Config controls the optional HTTP server.
type EnforcerStats ¶ added in v0.2.0
type EnforcerStats struct {
WorkersConfigured int
WorkersAlive int
WorkersStale int
MaxCycleAge time.Duration
Restarts int64
// Processed is the throughput counter: how many actions reached each
// terminal outcome since the process started.
Processed []ProcessedCount
}
EnforcerStats is the outbox worker pool's state as the metrics endpoint needs it.
The shape is declared here and filled by a closure supplied from main, so this package never imports internal/enforcer — the same arrangement as Readiness.GetMeOK and Readiness.EnforcerAlive.
type Metrics ¶
type Metrics struct {
Ops *store.Ops
// Now supplies the instant every age metric is measured against. Nil means
// time.Now.
Now func() time.Time
// ProcessStart is when this process began. Before any reconcile pass has
// ever completed it is the source of
// `gatekeeper_reconcile_last_run_age_seconds`: the time since start is
// exactly how long this deployment has gone without a pass. The zero value
// falls back to processLoadedAt.
ProcessStart time.Time
// Enforcer, when set, reports the outbox worker pool. A nil func means the
// pool is not supervised here and its whole family is omitted rather than
// declared with no samples.
Enforcer func() EnforcerStats
// TelegramErrors, when set, reports normalized Telegram API failures.
TelegramErrors func() []TelegramErrorCount
}
Metrics writes a small Prometheus text exposition from durable state and from in-process counters.
func (*Metrics) Write ¶
Write emits metrics with bounded labels only.
The in-process families go out before the database-backed ones on purpose: a failing store read aborts the rest of the body, and the worker-pool state is exactly what an operator needs when the database is the thing misbehaving.
A store failure is reported in the body rather than by failing the scrape. Answering 5xx would discard the in-process families above at the one moment they are most valuable, so the response stays a 200 whose `gatekeeper_metrics_store_scrape_success` reads 0. The returned error is for the caller's log; the gauge is what Prometheus can alert on.
type ProcessedCount ¶ added in v0.2.0
ProcessedCount is one action-throughput counter slot.
type Readiness ¶
type Readiness struct {
DB *sql.DB
HealthKeys []string
ReconcileInterval time.Duration
GetMeOK func() bool
RequireTelegramWebhookRegistration bool
TelegramWebhookRegistered func() bool
Now func() time.Time
// EnforcerAlive reports whether the outbox worker pool is still turning
// its loop. Unlike get_me or reconcile freshness, a stopped worker pool is
// never transient, so it belongs in readiness. A nil func means the
// enforcer is not supervised here and the input is skipped.
EnforcerAlive func() bool
}
Readiness contains dependencies used by /readyz.
type ReadinessResult ¶
ReadinessResult is the machine-readable readiness decision.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is an optional HTTP runtime.
type TelegramErrorCount ¶ added in v0.2.0
TelegramErrorCount is one normalized Telegram API failure counter.
type TelegramHandler ¶
type TelegramHandler struct {
Secret string
Processor TelegramProcessor
}
TelegramHandler accepts Telegram webhook updates.
func NewTelegramHandler ¶
func NewTelegramHandler(secret string, processor TelegramProcessor) *TelegramHandler
NewTelegramHandler returns a Telegram webhook handler.
func (*TelegramHandler) ServeHTTP ¶
func (h *TelegramHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP verifies Telegram's secret token before reading the update.
type TelegramProcessor ¶
TelegramProcessor is the durable Telegram webhook processing surface.
type TributeHandler ¶
type TributeHandler struct {
DB *sql.DB
APIKey string
Engine *engine.Engine
CancelImmediate bool
OwnerIDs []int64
AdminLogChatID *int64
OperatorLog *operatorlog.Writer
Logger *slog.Logger
}
TributeHandler accepts Tribute webhooks.
func (*TributeHandler) ServeHTTP ¶
func (h *TributeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP validates and processes one Tribute webhook.