webhookapi

package
v1.147.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package webhookapi is the admin REST surface for inbound webhook sources (#1870): list, create, read with status, change, and delete, and the status of every source in one response (#1979). Secrets are write-only: a view says whether one is set and until when the previous one is still accepted, and never carries either.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(mux *http.ServeMux, wrap func(http.Handler) http.Handler, cfg Config)

Register mounts the webhook source routes, each behind wrap, the admin API's authentication.

Types

type AuthInput

type AuthInput struct {
	Mode             string `json:"mode" example:"hmac"`
	Secret           string `json:"secret,omitempty" example:"whsec_example"`
	Algorithm        string `json:"algorithm,omitempty" example:"sha256"`
	SignatureHeader  string `json:"signature_header,omitempty" example:"X-Signature"`
	Encoding         string `json:"encoding,omitempty" example:"hex"`
	Prefix           string `json:"prefix,omitempty" example:"sha256="`
	TimestampHeader  string `json:"timestamp_header,omitempty" example:"X-Timestamp"`
	ToleranceSeconds int    `json:"tolerance_seconds,omitempty" example:"300"`
	Signed           string `json:"signed,omitempty" example:"body"`
	IDHeader         string `json:"id_header,omitempty" example:"webhook-id"`
	HeaderFormat     string `json:"header_format,omitempty" example:"stripe"`
	Header           string `json:"header,omitempty" example:"X-Webhook-Token"`
	Username         string `json:"username,omitempty" example:"sender"`
}

AuthInput is how a request proves it came from the sender. secret is write-only; on an update, an empty secret keeps the stored one.

type AuthView

type AuthView struct {
	Mode             string     `json:"mode"`
	SecretSet        bool       `json:"secret_set"`
	PreviousUntil    *time.Time `json:"previous_secret_until,omitempty"`
	Algorithm        string     `json:"algorithm,omitempty"`
	SignatureHeader  string     `json:"signature_header,omitempty"`
	Encoding         string     `json:"encoding,omitempty"`
	Prefix           string     `json:"prefix,omitempty"`
	TimestampHeader  string     `json:"timestamp_header,omitempty"`
	ToleranceSeconds int        `json:"tolerance_seconds,omitempty"`
	Signed           string     `json:"signed,omitempty"`
	IDHeader         string     `json:"id_header,omitempty"`
	HeaderFormat     string     `json:"header_format,omitempty"`
	Header           string     `json:"header,omitempty"`
	Username         string     `json:"username,omitempty"`
}

AuthView is a source's authentication without its secrets.

type Config

type Config struct {
	// Service manages sources. nil mounts nothing.
	Service Service
	// Author resolves the acting admin.
	Author func(*http.Request) string
}

Config carries the service and the parent-owned helpers.

type LargestWindow added in v1.147.0

type LargestWindow struct {
	Source       string    `json:"source"`
	WindowStart  time.Time `json:"window_start"`
	DecodedBytes int64     `json:"decoded_bytes"`
	InputBytes   int64     `json:"input_bytes"`
	Events       int64     `json:"events"`
	// PercentOfLimit is DecodedBytes as a percent of the memory limit, 0
	// when there is no limit.
	PercentOfLimit float64 `json:"percent_of_limit"`
}

LargestWindow is the window that took the most memory to compact.

type ReplicaSpool added in v1.146.0

type ReplicaSpool struct {
	Replica string `json:"replica"`
	Dir     string `json:"dir"`
	Bytes   int64  `json:"bytes"`
	Events  int64  `json:"events"`
	Files   int    `json:"files"`
	// OldestAt is when the oldest event waiting was received; null when the
	// spool is empty.
	OldestAt *time.Time `json:"oldest_at"`
	// MaxBytes and MaxAgeSeconds are the bounds past which the receiver
	// answers 503 with Retry-After.
	MaxBytes      int64 `json:"max_bytes"`
	MaxAgeSeconds int64 `json:"max_age_seconds"`
	// DrainedEvents and DrainFailures count since the receiver started.
	DrainedEvents int64      `json:"drained_events"`
	DrainFailures int64      `json:"drain_failures"`
	LastDrainAt   *time.Time `json:"last_drain_at"`
	// LastError is the newest drain failure, cleared by a drain that
	// succeeds.
	LastError string    `json:"last_error"`
	StartedAt time.Time `json:"started_at"`
	UpdatedAt time.Time `json:"updated_at"`
	// Reporting is false for a receiver that has not reported for two
	// minutes: it stopped, and what it holds waits for it to start again.
	Reporting bool `json:"reporting"`
}

ReplicaSpool is one receiver's local spool as it last reported it (#2121): the events it acknowledged and has not yet drained to object storage, and how its drain is going.

type Service

type Service interface {
	List(ctx context.Context) ([]whsource.Source, error)
	Get(ctx context.Context, name string) (whsource.Source, whstore.Status, error)
	Create(ctx context.Context, src whsource.Source) (whsource.Source, error)
	Update(ctx context.Context, name string, u whadmin.Update) (whsource.Source, error)
	Delete(ctx context.Context, name string) error
	Overview(ctx context.Context, source string, span whadmin.Span) (whadmin.Overview, error)
	SyncPartitions(ctx context.Context, name string) error
	Warnings(ctx context.Context, src whsource.Source) []string
}

Service is what the routes act through. whadmin.Service satisfies it.

type SourceDetail

type SourceDetail struct {
	Source SourceView     `json:"source"`
	Status whstore.Status `json:"status"`
}

SourceDetail is one source with its status.

type SourceInput

type SourceInput struct {
	Name       string          `json:"name,omitempty" example:"esp-events"`
	Enabled    *bool           `json:"enabled,omitempty" example:"true"`
	Connection string          `json:"connection,omitempty" example:"scratch"`
	Auth       AuthInput       `json:"auth"`
	Config     whsource.Config `json:"config"`
	// RotationOverlapSeconds keeps the previous secret valid this long when
	// auth.secret replaces it. Zero ends it at once.
	RotationOverlapSeconds int `json:"rotation_overlap_seconds,omitempty" example:"86400"`
}

SourceInput is the write shape. name and connection are read on create only: the table was created on that connection under a name derived from the source's.

type SourceList

type SourceList struct {
	Sources []SourceView `json:"sources"`
}

SourceList is the collection response.

type SourceRejection added in v1.138.2

type SourceRejection struct {
	Source  string    `json:"source"`
	At      time.Time `json:"at"`
	FirstAt time.Time `json:"first_at"`
	Count   int64     `json:"count"`
	Outcome string    `json:"outcome"`
	Reason  string    `json:"reason"`
	// RequestHash is the SHA-256 of the refused request's body and EventIDs
	// the ids of its first 20 events, when its events were read; empty for a
	// request refused before that.
	RequestHash string   `json:"request_hash"`
	EventIDs    []string `json:"event_ids"`
}

SourceRejection is a run of refused requests of one source with one outcome and reason (#2001): the latest at At, the first at FirstAt, Count in all.

type SourceStatus added in v1.138.2

type SourceStatus struct {
	Name    string `json:"name"`
	Enabled bool   `json:"enabled"`
	// Health is the source's overall state. When more than one applies, the
	// first of disabled, failing, silent, receiving is reported.
	Health     string `json:"health" enums:"receiving,silent,failing,disabled"`
	AuthMode   string `json:"auth_mode"`
	Connection string `json:"connection"`
	Table      string `json:"table"`
	// LastEventAt is when the source last received an event; null when it
	// never has, or not within the windows it still holds.
	LastEventAt *time.Time `json:"last_event_at"`
	// LastHour and LastDay are request counts by outcome.
	LastHour map[string]int64 `json:"last_hour"`
	LastDay  map[string]int64 `json:"last_day"`
	// Pending counts windows owed a compaction; Failing, those whose last
	// attempt failed, with the newest one's error in LastError.
	Pending   int    `json:"pending"`
	Failing   int    `json:"failing"`
	LastError string `json:"last_error,omitempty"`
	// AckLastHour and AckLastDay are how long the deliveries answered 202
	// waited for that answer.
	AckLastHour whstore.AckLatency `json:"ack_last_hour"`
	AckLastDay  whstore.AckLatency `json:"ack_last_day"`
	// SegmentsOpenWindow is how many segments were recorded against the
	// source's open window, and SegmentsPerWindowP95 the 95th percentile of
	// that count over the windows that started in the last day (#2132). Each
	// is an object a reader of the window reads until the window is
	// compacted; a count can exceed the segments written by one per replica.
	SegmentsOpenWindow   int64 `json:"segments_open_window" example:"412"`
	SegmentsPerWindowP95 int64 `json:"segments_per_window_p95" example:"3650"`
}

SourceStatus is one source's line on the overview.

type SourceView

type SourceView struct {
	Name       string `json:"name"`
	Enabled    bool   `json:"enabled"`
	Connection string `json:"connection"`
	// Path is where the sender posts, relative to the platform's address:
	// /hooks/{name}, with the token as a further segment for path_token.
	Path string `json:"path" example:"/hooks/esp-events"`
	// Table is what readers query, in the connection's scratch schema.
	Table     string          `json:"table" example:"webhook_esp_events"`
	Auth      AuthView        `json:"auth"`
	Config    whsource.Config `json:"config"`
	CreatedBy string          `json:"created_by,omitempty"`
	CreatedAt time.Time       `json:"created_at"`
	UpdatedAt time.Time       `json:"updated_at"`
	// Warnings is what a create or change answers with besides the source,
	// without refusing it: a slow read of its partitions, which an uncached
	// file metastore causes (#2134). Absent from a list or a read.
	Warnings []string `json:"warnings,omitempty"`
}

SourceView is the read shape.

type StatusHistory added in v1.147.0

type StatusHistory struct {
	// Statuses counts requests by the HTTP status they were answered with.
	Statuses []whstore.StatusPoint `json:"statuses"`
	// Replicas is each receiver's events received and written to object
	// storage per bucket, and its spool's depth and oldest age.
	Replicas []whstore.ReplicaMinute `json:"replicas"`
	// Ack is the acknowledgement latency per bucket with each stage's
	// average.
	Ack []whstore.AckPoint `json:"ack"`
	// Compactions is each window's compaction in the range, newest first.
	Compactions []whstore.CompactionRun `json:"compactions"`
	// Storage is each source's raw and compacted bytes now.
	Storage []whstore.SourceStorage `json:"storage"`
	Sizing  WindowSizing            `json:"sizing"`
}

StatusHistory is the telemetry the webhooks page charts over the range (#2150).

type StatusOverview added in v1.138.2

type StatusOverview struct {
	GeneratedAt time.Time `json:"generated_at"`
	// Range is the span the series covers: hour, day, week or custom.
	Range string `json:"range" enums:"hour,day,week,custom" example:"hour"`
	// From is the series' lower bound: a minute's counts are in the series
	// when the minute is at or after it. Until is its upper bound, exclusive.
	From  time.Time `json:"from"`
	Until time.Time `json:"until"`
	// BucketSeconds is the length of one bucket of the series.
	BucketSeconds int `json:"bucket_seconds" example:"60"`
	// SilentAfterSeconds is how long an enabled source may go without an
	// event before it is reported silent.
	SilentAfterSeconds int               `json:"silent_after_seconds" example:"86400"`
	Sources            []SourceStatus    `json:"sources"`
	Volume             []VolumePoint     `json:"volume"`
	Rejections         []SourceRejection `json:"rejections"`
	// Spools is every receiver's local spool, by replica: empty where no
	// receiver spools (#2121).
	Spools []ReplicaSpool `json:"spools"`
	// History is the telemetry over the range (#2150).
	History StatusHistory `json:"history"`
}

StatusOverview is the status of every source in one response (#1979): each source's health and counts, the request series over the range, and the newest rejections of every source.

type VolumePoint added in v1.138.2

type VolumePoint struct {
	At      time.Time `json:"at"`
	Source  string    `json:"source"`
	Outcome string    `json:"outcome"`
	Count   int64     `json:"count"`
}

VolumePoint is the number of requests of one source with one outcome in the bucket starting at At. A bucket with no requests has no point.

type WindowSizing added in v1.147.0

type WindowSizing struct {
	// MemoryLimitBytes is the memory this replica may use, 0 when it has no
	// limit.
	MemoryLimitBytes int64 `json:"memory_limit_bytes"`
	// Largest is the window that took the most memory, null when none was
	// compacted in the range.
	Largest *LargestWindow `json:"largest"`
	// WarnAtPercent is the share of the limit Warning is raised at.
	WarnAtPercent int  `json:"warn_at_percent"`
	Warning       bool `json:"warning"`
}

WindowSizing sets the largest window compacted in the range against this replica's memory limit.

Jump to

Keyboard shortcuts

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