alertmanager

package
v1.11.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2021 License: Apache-2.0 Imports: 77 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// RingKey is the key under which we store the alertmanager ring in the KVStore.
	RingKey = "alertmanager"

	// RingNameForServer is the name of the ring used by the alertmanager server.
	RingNameForServer = "alertmanager"

	// RingNumTokens is a safe default instead of exposing to config option to the user
	// in order to simplify the config.
	RingNumTokens = 128
)

Variables

View Source
var RingOp = ring.NewOp([]ring.InstanceState{ring.ACTIVE}, func(s ring.InstanceState) bool {

	return s != ring.ACTIVE
})

RingOp is the operation used for reading/writing to the alertmanagers.

View Source
var SyncRingOp = ring.NewOp([]ring.InstanceState{ring.ACTIVE, ring.JOINING}, func(s ring.InstanceState) bool {
	return s != ring.ACTIVE
})

SyncRingOp is the operation used for checking if a user is owned by an alertmanager.

Functions

This section is empty.

Types

type Alertmanager

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

An Alertmanager manages the alerts for one user.

func New

func New(cfg *Config, reg *prometheus.Registry) (*Alertmanager, error)

New creates a new Alertmanager.

func (*Alertmanager) ApplyConfig

func (am *Alertmanager) ApplyConfig(userID string, conf *config.Config, rawCfg string) error

ApplyConfig applies a new configuration to an Alertmanager.

func (*Alertmanager) Stop

func (am *Alertmanager) Stop()

Stop stops the Alertmanager.

func (*Alertmanager) StopAndWait added in v1.8.0

func (am *Alertmanager) StopAndWait()

func (*Alertmanager) WaitInitialStateSync added in v1.10.0

func (am *Alertmanager) WaitInitialStateSync(ctx context.Context) error

type Client added in v1.8.0

type Client interface {
	alertmanagerpb.AlertmanagerClient

	// RemoteAddress returns the address of the remote alertmanager and is used to uniquely
	// identify an alertmanager instance.
	RemoteAddress() string
}

Client is the interface that should be implemented by any client used to read/write data to an alertmanager via GRPC.

type ClientConfig added in v1.8.0

type ClientConfig struct {
	RemoteTimeout time.Duration    `yaml:"remote_timeout"`
	TLSEnabled    bool             `yaml:"tls_enabled"`
	TLS           tls.ClientConfig `yaml:",inline"`
}

ClientConfig is the configuration struct for the alertmanager client.

func (*ClientConfig) RegisterFlagsWithPrefix added in v1.8.0

func (cfg *ClientConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet)

RegisterFlagsWithPrefix registers flags with prefix.

type ClientsPool added in v1.8.0

type ClientsPool interface {
	// GetClientFor returns the alertmanager client for the given address.
	GetClientFor(addr string) (Client, error)
}

ClientsPool is the interface used to get the client from the pool for a specified address.

type ClusterConfig added in v1.7.0

type ClusterConfig struct {
	ListenAddr       string                 `yaml:"listen_address"`
	AdvertiseAddr    string                 `yaml:"advertise_address"`
	Peers            flagext.StringSliceCSV `yaml:"peers"`
	PeerTimeout      time.Duration          `yaml:"peer_timeout"`
	GossipInterval   time.Duration          `yaml:"gossip_interval"`
	PushPullInterval time.Duration          `yaml:"push_pull_interval"`
}

func (*ClusterConfig) RegisterFlags added in v1.7.0

func (cfg *ClusterConfig) RegisterFlags(f *flag.FlagSet)

type Config

type Config struct {
	UserID      string
	Logger      log.Logger
	Peer        *cluster.Peer
	PeerTimeout time.Duration
	Retention   time.Duration
	ExternalURL *url.URL
	Limits      Limits

	// Tenant-specific local directory where AM can store its state (notifications, silences, templates). When AM is stopped, entire dir is removed.
	TenantDataDir string

	ShardingEnabled   bool
	ReplicationFactor int
	Replicator        Replicator
	Store             alertstore.AlertStore
	PersisterConfig   PersisterConfig
}

Config configures an Alertmanager.

type Distributor added in v1.8.0

type Distributor struct {
	services.Service
	// contains filtered or unexported fields
}

Distributor forwards requests to individual alertmanagers.

func NewDistributor added in v1.8.0

func NewDistributor(cfg ClientConfig, maxRecvMsgSize int64, alertmanagersRing *ring.Ring, alertmanagerClientsPool ClientsPool, logger log.Logger, reg prometheus.Registerer) (d *Distributor, err error)

NewDistributor constructs a new Distributor

func (*Distributor) DistributeRequest added in v1.8.0

func (d *Distributor) DistributeRequest(w http.ResponseWriter, r *http.Request)

DistributeRequest shards the writes and returns as soon as the quorum is satisfied. In case of reads, it proxies the request to one of the alertmanagers. DistributeRequest assumes that the caller has verified IsPathSupported returns true for the route.

func (*Distributor) IsPathSupported added in v1.8.0

func (d *Distributor) IsPathSupported(p string) bool

IsPathSupported returns true if the given route is currently supported by the Distributor.

type Limits added in v1.10.0

type Limits interface {
	// AlertmanagerReceiversBlockCIDRNetworks returns the list of network CIDRs that should be blocked
	// in the Alertmanager receivers for the given user.
	AlertmanagerReceiversBlockCIDRNetworks(user string) []flagext.CIDR

	// AlertmanagerReceiversBlockPrivateAddresses returns true if private addresses should be blocked
	// in the Alertmanager receivers for the given user.
	AlertmanagerReceiversBlockPrivateAddresses(user string) bool

	// NotificationRateLimit methods return limit used by rate-limiter for given integration.
	// If set to 0, no notifications are allowed.
	// rate.Inf = all notifications are allowed.
	//
	// Note that when negative or zero values specified by user are translated to rate.Limit by Overrides,
	// and may have different meaning there.
	NotificationRateLimit(tenant string, integration string) rate.Limit

	// NotificationBurstSize returns burst-size for rate limiter for given integration type. If 0, no notifications are allowed except
	// when limit == rate.Inf.
	NotificationBurstSize(tenant string, integration string) int

	// AlertmanagerMaxConfigSize returns max size of configuration file that user is allowed to upload. If 0, there is no limit.
	AlertmanagerMaxConfigSize(tenant string) int

	// AlertmanagerMaxTemplatesCount returns max number of templates that tenant can use in the configuration. 0 = no limit.
	AlertmanagerMaxTemplatesCount(tenant string) int

	// AlertmanagerMaxTemplateSize returns max size of individual template. 0 = no limit.
	AlertmanagerMaxTemplateSize(tenant string) int

	// AlertmanagerMaxDispatcherAggregationGroups returns maximum number of aggregation groups in Alertmanager's dispatcher that a tenant can have.
	// Each aggregation group consumes single goroutine. 0 = unlimited.
	AlertmanagerMaxDispatcherAggregationGroups(t string) int

	// AlertmanagerMaxAlertsCount returns max number of alerts that tenant can have active at the same time. 0 = no limit.
	AlertmanagerMaxAlertsCount(tenant string) int

	// AlertmanagerMaxAlertsSizeBytes returns total max size of alerts that tenant can have active at the same time. 0 = no limit.
	// Size of the alert is computed from alert labels, annotations and generator URL.
	AlertmanagerMaxAlertsSizeBytes(tenant string) int
}

Limits defines limits used by Alertmanager.

type MultitenantAlertmanager

type MultitenantAlertmanager struct {
	services.Service
	// contains filtered or unexported fields
}

A MultitenantAlertmanager manages Alertmanager instances for multiple organizations.

func NewMultitenantAlertmanager

func NewMultitenantAlertmanager(cfg *MultitenantAlertmanagerConfig, store alertstore.AlertStore, limits Limits, logger log.Logger, registerer prometheus.Registerer) (*MultitenantAlertmanager, error)

NewMultitenantAlertmanager creates a new MultitenantAlertmanager.

func (*MultitenantAlertmanager) DeleteUserConfig added in v1.3.0

func (am *MultitenantAlertmanager) DeleteUserConfig(w http.ResponseWriter, r *http.Request)

DeleteUserConfig is exposed via user-visible API (if enabled, uses DELETE method), but also as an internal endpoint using POST method. Note that if no config exists for a user, StatusOK is returned.

func (*MultitenantAlertmanager) GetPositionForUser added in v1.9.0

func (am *MultitenantAlertmanager) GetPositionForUser(userID string) int

GetPositionForUser returns the position this Alertmanager instance holds in the ring related to its other replicas for an specific user.

func (*MultitenantAlertmanager) GetStatusHandler

func (am *MultitenantAlertmanager) GetStatusHandler() StatusHandler

GetStatusHandler returns the status handler for this multi-tenant alertmanager.

func (*MultitenantAlertmanager) GetUserConfig added in v1.3.0

func (am *MultitenantAlertmanager) GetUserConfig(w http.ResponseWriter, r *http.Request)

func (*MultitenantAlertmanager) HandleRequest added in v1.8.0

HandleRequest implements gRPC Alertmanager service, which receives request from AlertManager-Distributor.

func (*MultitenantAlertmanager) ListAllConfigs added in v1.9.0

func (am *MultitenantAlertmanager) ListAllConfigs(w http.ResponseWriter, r *http.Request)

func (*MultitenantAlertmanager) OnRingInstanceHeartbeat added in v1.7.0

func (r *MultitenantAlertmanager) OnRingInstanceHeartbeat(_ *ring.BasicLifecycler, _ *ring.Desc, _ *ring.InstanceDesc)

func (*MultitenantAlertmanager) OnRingInstanceRegister added in v1.7.0

func (r *MultitenantAlertmanager) OnRingInstanceRegister(_ *ring.BasicLifecycler, ringDesc ring.Desc, instanceExists bool, instanceID string, instanceDesc ring.InstanceDesc) (ring.InstanceState, ring.Tokens)

func (*MultitenantAlertmanager) OnRingInstanceStopping added in v1.7.0

func (r *MultitenantAlertmanager) OnRingInstanceStopping(_ *ring.BasicLifecycler)

func (*MultitenantAlertmanager) OnRingInstanceTokens added in v1.7.0

func (r *MultitenantAlertmanager) OnRingInstanceTokens(_ *ring.BasicLifecycler, _ ring.Tokens)

func (*MultitenantAlertmanager) ReadFullStateForUser added in v1.9.0

func (am *MultitenantAlertmanager) ReadFullStateForUser(ctx context.Context, userID string) ([]*clusterpb.FullState, error)

ReadFullStateForUser attempts to read the full state from each replica for user. Note that it will try to obtain and return state from all replicas, but will consider it a success if state is obtained from at least one replica.

func (*MultitenantAlertmanager) ReadState added in v1.9.0

UpdateState implements the Alertmanager service.

func (*MultitenantAlertmanager) ReplicateStateForUser added in v1.9.0

func (am *MultitenantAlertmanager) ReplicateStateForUser(ctx context.Context, userID string, part *clusterpb.Part) error

ReplicateStateForUser attempts to replicate a partial state sent by an alertmanager to its other replicas through the ring.

func (*MultitenantAlertmanager) RingHandler added in v1.7.0

func (am *MultitenantAlertmanager) RingHandler(w http.ResponseWriter, req *http.Request)

func (*MultitenantAlertmanager) ServeHTTP

func (am *MultitenantAlertmanager) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP serves the Alertmanager's web UI and API.

func (*MultitenantAlertmanager) SetUserConfig added in v1.3.0

func (am *MultitenantAlertmanager) SetUserConfig(w http.ResponseWriter, r *http.Request)

func (*MultitenantAlertmanager) UpdateState added in v1.9.0

UpdateState implements the Alertmanager service.

type MultitenantAlertmanagerConfig

type MultitenantAlertmanagerConfig struct {
	DataDir        string           `yaml:"data_dir"`
	Retention      time.Duration    `yaml:"retention"`
	ExternalURL    flagext.URLValue `yaml:"external_url"`
	PollInterval   time.Duration    `yaml:"poll_interval"`
	MaxRecvMsgSize int64            `yaml:"max_recv_msg_size"`

	// Enable sharding for the Alertmanager
	ShardingEnabled bool       `yaml:"sharding_enabled"`
	ShardingRing    RingConfig `yaml:"sharding_ring"`

	FallbackConfigFile string `yaml:"fallback_config_file"`
	AutoWebhookRoot    string `yaml:"auto_webhook_root"`

	Store   alertstore.LegacyConfig `` /* 132-byte string literal not displayed */
	Cluster ClusterConfig           `yaml:"cluster"`

	EnableAPI bool `yaml:"enable_api"`

	// For distributor.
	AlertmanagerClient ClientConfig `yaml:"alertmanager_client"`

	// For the state persister.
	Persister PersisterConfig `yaml:",inline"`
}

MultitenantAlertmanagerConfig is the configuration for a multitenant Alertmanager.

func (*MultitenantAlertmanagerConfig) RegisterFlags

func (cfg *MultitenantAlertmanagerConfig) RegisterFlags(f *flag.FlagSet)

RegisterFlags adds the flags required to config this to the given FlagSet.

func (*MultitenantAlertmanagerConfig) Validate added in v1.6.0

func (cfg *MultitenantAlertmanagerConfig) Validate(storageCfg alertstore.Config) error

Validate config and returns error on failure

type NilChannel added in v1.8.0

type NilChannel struct{}

func (*NilChannel) Broadcast added in v1.8.0

func (c *NilChannel) Broadcast([]byte)

type NilPeer added in v1.8.0

type NilPeer struct{}

NilPeer and NilChannel implements the Alertmanager clustering interface used by the API to expose cluster information. In a multi-tenant environment, we choose not to expose these to tenants and thus are not implemented.

func (*NilPeer) AddState added in v1.8.0

func (*NilPeer) Name added in v1.8.0

func (p *NilPeer) Name() string

func (*NilPeer) Peers added in v1.8.0

func (p *NilPeer) Peers() []cluster.ClusterMember

func (*NilPeer) Position added in v1.8.0

func (p *NilPeer) Position() int

func (*NilPeer) Status added in v1.8.0

func (p *NilPeer) Status() string

func (*NilPeer) WaitReady added in v1.8.0

func (p *NilPeer) WaitReady(context.Context) error

type PersistableState added in v1.9.0

type PersistableState interface {
	State
	GetFullState() (*clusterpb.FullState, error)
}

type PersisterConfig added in v1.9.0

type PersisterConfig struct {
	Interval time.Duration `yaml:"persist_interval"`
}

func (*PersisterConfig) RegisterFlagsWithPrefix added in v1.9.0

func (cfg *PersisterConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet)

func (*PersisterConfig) Validate added in v1.9.0

func (cfg *PersisterConfig) Validate() error

type Replicator added in v1.9.0

type Replicator interface {
	// ReplicateStateForUser writes the given partial state to the necessary replicas.
	ReplicateStateForUser(ctx context.Context, userID string, part *clusterpb.Part) error
	// The alertmanager replication protocol relies on a position related to other replicas.
	// This position is then used to identify who should notify about the alert first.
	GetPositionForUser(userID string) int
	// ReadFullStateForUser obtains the full state from other replicas in the cluster.
	ReadFullStateForUser(context.Context, string) ([]*clusterpb.FullState, error)
}

Replicator is used to exchange state with peers via the ring when sharding is enabled.

type RingConfig added in v1.7.0

type RingConfig struct {
	KVStore              kv.Config     `yaml:"kvstore" doc:"description=The key-value store used to share the hash ring across multiple instances."`
	HeartbeatPeriod      time.Duration `yaml:"heartbeat_period"`
	HeartbeatTimeout     time.Duration `yaml:"heartbeat_timeout"`
	ReplicationFactor    int           `yaml:"replication_factor"`
	ZoneAwarenessEnabled bool          `yaml:"zone_awareness_enabled"`

	// Instance details
	InstanceID             string   `yaml:"instance_id" doc:"hidden"`
	InstanceInterfaceNames []string `yaml:"instance_interface_names"`
	InstancePort           int      `yaml:"instance_port" doc:"hidden"`
	InstanceAddr           string   `yaml:"instance_addr" doc:"hidden"`
	InstanceZone           string   `yaml:"instance_availability_zone"`

	// Injected internally
	ListenPort      int           `yaml:"-"`
	RingCheckPeriod time.Duration `yaml:"-"`

	// Used for testing
	SkipUnregister bool `yaml:"-"`
}

RingConfig masks the ring lifecycler config which contains many options not really required by the alertmanager ring. This config is used to strip down the config to the minimum, and avoid confusion to the user.

func (*RingConfig) RegisterFlags added in v1.7.0

func (cfg *RingConfig) RegisterFlags(f *flag.FlagSet)

RegisterFlags adds the flags required to config this to the given FlagSet

func (*RingConfig) ToLifecyclerConfig added in v1.7.0

func (cfg *RingConfig) ToLifecyclerConfig() (ring.BasicLifecyclerConfig, error)

ToLifecyclerConfig returns a LifecyclerConfig based on the alertmanager ring config.

func (*RingConfig) ToRingConfig added in v1.7.0

func (cfg *RingConfig) ToRingConfig() ring.Config

type State added in v1.9.0

type State interface {
	AddState(string, cluster.State, prometheus.Registerer) cluster.ClusterChannel
	Position() int
	WaitReady(context.Context) error
}

State helps with replication and synchronization of notifications and silences across several alertmanager replicas.

type StatusHandler

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

StatusHandler shows the status of the alertmanager.

func (StatusHandler) ServeHTTP

func (s StatusHandler) ServeHTTP(w http.ResponseWriter, _ *http.Request)

ServeHTTP serves the status of the alertmanager.

type UserConfig added in v1.3.0

type UserConfig struct {
	TemplateFiles      map[string]string `yaml:"template_files"`
	AlertmanagerConfig string            `yaml:"alertmanager_config"`
}

UserConfig is used to communicate a users alertmanager configs

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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