api

package
v0.35.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 27 Imported by: 55

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCORSHandler added in v0.34.2

func NewCORSHandler(origin string) (func(http.Handler) http.Handler, error)

NewCORSHandler allows origins matching the fully anchored regex origin.

Types

type API

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

API represents all APIs of Alertmanager.

func New

func New(opts Options) (*API, error)

New creates a new API object combining all API versions. Note that an Update call is also needed to get the APIs into an operational state.

func (*API) Register

func (api *API) Register(r *route.Router, routePrefix string) *http.ServeMux

Register API. As APIv2 works on the http.Handler level, this method also creates a new http.ServeMux and then uses it to register both the provided router (to handle "/") and APIv2 (to handle "<routePrefix>/api/v2"). The method returns the newly created http.ServeMux. Configured timeouts apply to regular HTTP requests and Connect unary RPCs. Regular HTTP GETs and Connect RPCs use independent concurrency limits; streams also have a separate limit.

func (*API) Shutdown added in v0.35.0

func (api *API) Shutdown()

Shutdown rejects new Connect RPCs and cancels active RPCs.

func (*API) Update

func (api *API) Update(cfg *config.Config, setAlertStatus func(ctx context.Context, labels labelset.LabelSet))

Update config and resolve timeout of each API. APIv2 also needs setAlertStatus to be updated.

type Options added in v0.17.0

type Options struct {
	// Alerts to be used by the API. Mandatory.
	Alerts provider.Alerts
	// Silences to be used by the API. Mandatory.
	Silences *silence.Silences
	// Peer from the gossip cluster. If nil, no clustering will be used.
	Peer cluster.ClusterPeer
	// Timeout for HTTP requests and Connect unary RPCs. The zero value and
	// negative values result in no timeout.
	Timeout time.Duration
	// Concurrency is the limit for GET requests. The zero value and negative
	// values result in a limit of GOMAXPROCS or 8, whichever is larger. Status
	// code 503 is served for requests that would exceed the limit.
	Concurrency int
	// ConnectUnaryConcurrency is the independent limit for Connect unary RPCs.
	// Non-positive values inherit Concurrency. Calls that exceed the limit
	// receive ResourceExhausted.
	ConnectUnaryConcurrency int
	// ConnectStreamConcurrency is the independent limit for Connect streams.
	// Non-positive values inherit Concurrency. Calls that exceed the limit
	// receive ResourceExhausted.
	ConnectStreamConcurrency int
	// ConnectUnaryTimeout is the timeout for Connect unary RPCs. Zero inherits
	// Timeout. A negative value disables the Connect unary timeout.
	ConnectUnaryTimeout time.Duration
	// ConnectStreamIdleTimeout limits the time between messages on a Connect
	// stream. Non-positive values disable the timeout.
	ConnectStreamIdleTimeout time.Duration
	// ConnectStreamLifetime limits the total lifetime of a Connect stream.
	// Non-positive values disable the timeout.
	ConnectStreamLifetime time.Duration
	// ConnectReadMaxBytes limits each incoming Connect protobuf message.
	// Non-positive values do not set a limit.
	ConnectReadMaxBytes int
	// ConnectSendMaxBytes limits each outgoing Connect protobuf message.
	// Non-positive values do not set a limit.
	ConnectSendMaxBytes int
	// ConnectMaxRequestBodyBytes limits the wire size of a Connect unary request
	// body before decoding. Non-positive values do not set a limit.
	ConnectMaxRequestBodyBytes int64
	// CORSHandler is created by NewCORSHandler. If nil, no CORS headers are
	// sent.
	CORSHandler func(http.Handler) http.Handler
	// Logger is used for logging, if nil, no logging will happen.
	Logger *slog.Logger
	// Registry is used to register Prometheus metrics. If nil, no metrics
	// registration will happen.
	Registry prometheus.Registerer
	// RequestDuration is used to measure the duration of HTTP requests.
	RequestDuration *prometheus.HistogramVec
	// GroupFunc returns a list of alert groups. The alerts are grouped
	// according to the current active configuration. Alerts returned are
	// filtered by the arguments provided to the function.
	GroupFunc func(context.Context, func(*dispatch.Route) bool, dispatch.AlertFilter) (dispatch.AlertGroups, map[model.Fingerprint][]string, error)
}

Options for the creation of an API object. Alerts, Silences and GroupFunc are mandatory. The zero value for everything else is a safe default.

type V1DeprecationRouter added in v0.27.0

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

V1DeprecationRouter is the router to signal v1 users that the API v1 is now removed.

func NewV1DeprecationRouter added in v0.27.0

func NewV1DeprecationRouter(l *slog.Logger) *V1DeprecationRouter

NewV1DeprecationRouter returns a new V1DeprecationRouter.

func (*V1DeprecationRouter) Register added in v0.27.0

func (dr *V1DeprecationRouter) Register(r *route.Router)

Register registers all the API v1 routes with an endpoint that returns a JSON deprecation notice and a logs a warning.

Directories

Path Synopsis
Package apiconnect implements the experimental ConnectRPC-based Alertmanager API.
Package apiconnect implements the experimental ConnectRPC-based Alertmanager API.
status
v2
restapi
Package restapi Alertmanager API
Package restapi Alertmanager API

Jump to

Keyboard shortcuts

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