webhook

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package webhook owns the optional HTTP surface for health, metrics and provider webhooks.

Index

Constants

View Source
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

func (m *Metrics) Write(ctx context.Context, w io.Writer) error

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

type ProcessedCount struct {
	Type   string
	Result string
	Count  int64
}

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.

func (Readiness) Check

Check returns readiness failures without performing external network calls.

type ReadinessResult

type ReadinessResult struct {
	Ready  bool
	Failed []string
}

ReadinessResult is the machine-readable readiness decision.

type Server

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

Server is an optional HTTP runtime.

func NewServer

func NewServer(cfg Config) *Server

NewServer builds an HTTP server with only enabled routes mounted.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler exposes the route-gated mux for tests.

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

Run serves until ctx is cancelled, then performs graceful shutdown.

type TelegramErrorCount added in v0.2.0

type TelegramErrorCount struct {
	Method   string
	Category string
	Count    int64
}

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

type TelegramProcessor interface {
	HandleWebhookUpdate(ctx context.Context, raw []byte) error
}

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.

Jump to

Keyboard shortcuts

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