Documentation
¶
Overview ¶
Copyright The Prometheus Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright The Prometheus Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright The Prometheus Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright The Prometheus Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright The Prometheus Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright The Prometheus Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- Variables
- func ActiveTimeIntervalNames(ctx context.Context) ([]string, bool)
- func AggrGroupID(ctx context.Context) (string, bool)
- func Drain(r *http.Response)
- func FiringAlerts(ctx context.Context) ([]uint64, bool)
- func FlushID(ctx context.Context) (uint64, bool)
- func Get(ctx context.Context, client *http.Client, url string) (*http.Response, error)
- func GetTemplateData(ctx context.Context, tmpl *template.Template, alerts []*types.Alert, ...) *template.Data
- func GroupKey(ctx context.Context) (string, bool)
- func GroupLabels(ctx context.Context) (model.LabelSet, bool)
- func GroupMatchers(ctx context.Context) (labels.Matchers, bool)
- func MuteTimeIntervalNames(ctx context.Context) ([]string, bool)
- func MutedAlerts(ctx context.Context) (map[uint64]struct{}, bool)
- func NewAlertGroupedEvent(groupInfo *eventrecorderpb.AlertGroupInfo, alert *types.Alert) *eventrecorderpb.EventData
- func NewAlertResolvedEvent(groupInfo *eventrecorderpb.AlertGroupInfo, alert *types.Alert) *eventrecorderpb.EventData
- func NewClientWithTracing(cfg commoncfg.HTTPClientConfig, name string, ...) (*http.Client, error)
- func NewNotificationEvent(ctx context.Context, alerts []*types.Alert, integration Integration) *eventrecorderpb.EventData
- func NflogStore(ctx context.Context) (*nflog.Store, bool)
- func Now(ctx context.Context) (time.Time, bool)
- func PostJSON(ctx context.Context, client *http.Client, url string, body io.Reader) (*http.Response, error)
- func PostText(ctx context.Context, client *http.Client, url string, body io.Reader) (*http.Response, error)
- func ReceiverName(ctx context.Context) (string, bool)
- func RedactURL(err error) error
- func RepeatInterval(ctx context.Context) (time.Duration, bool)
- func ResolvedAlerts(ctx context.Context) ([]uint64, bool)
- func RouteID(ctx context.Context) (string, bool)
- func TmplHTML(tmpl *template.Template, data *template.Data, err *error) func(string) string
- func TmplText(tmpl *template.Template, data *template.Data, err *error) func(string) string
- func TruncateInBytes(s string, n int) (string, bool)
- func TruncateInRunes(s string, n int) (string, bool)
- func WithActiveTimeIntervals(ctx context.Context, at []string) context.Context
- func WithAggrGroupID(ctx context.Context, id string) context.Context
- func WithFiringAlerts(ctx context.Context, alerts []uint64) context.Context
- func WithFlushID(ctx context.Context, id uint64) context.Context
- func WithGroupKey(ctx context.Context, s string) context.Context
- func WithGroupLabels(ctx context.Context, lset model.LabelSet) context.Context
- func WithGroupMatchers(ctx context.Context, matchers labels.Matchers) context.Context
- func WithMuteTimeIntervals(ctx context.Context, mt []string) context.Context
- func WithMutedAlerts(ctx context.Context, alerts map[uint64]struct{}) context.Context
- func WithNflogStore(ctx context.Context, store *nflog.Store) context.Context
- func WithNotificationReason(ctx context.Context, reason NotifyReason) context.Context
- func WithNow(ctx context.Context, t time.Time) context.Context
- func WithReceiverName(ctx context.Context, rcv string) context.Context
- func WithRepeatInterval(ctx context.Context, t time.Duration) context.Context
- func WithResolvedAlerts(ctx context.Context, alerts []uint64) context.Context
- func WithRouteID(ctx context.Context, routeID string) context.Context
- type ClusterGossipSettleStage
- type ClusterWaitStage
- type DedupStage
- type ErrorWithReason
- type FanoutStage
- type Integration
- type Key
- type Metrics
- type MultiStage
- type MuteFunc
- type MuteStage
- type Muter
- type NotificationLog
- type Notifier
- type NotifyReason
- type Peer
- type PipelineBuilder
- type Reason
- type ResolvedSender
- type Retrier
- type RetryStage
- type RoutingStage
- type SetNotifiesStage
- type Stage
- type StageFunc
- type TimeActiveStage
- type TimeMuteStage
- type TimeMuter
Constants ¶
const ( SuppressedReasonSilence = "silence" SuppressedReasonInhibition = "inhibition" SuppressedReasonMuteTimeInterval = "mute_time_interval" SuppressedReasonActiveTimeInterval = "active_time_interval" )
const MinTimeout = 10 * time.Second
MinTimeout is the minimum timeout that is set for the context of a call to a notification pipeline.
Variables ¶
var UserAgentHeader = version.ComponentUserAgent("Alertmanager")
UserAgentHeader is the default User-Agent for notification requests.
Functions ¶
func ActiveTimeIntervalNames ¶ added in v0.24.0
ActiveTimeIntervalNames extracts a slice of active time names from the context. If none exists, the second argument is false.
func AggrGroupID ¶ added in v0.33.0
AggrGroupID extracts an aggregation group UUID from the context.
func Drain ¶ added in v0.18.0
Drain consumes and closes the response's body to make sure that the HTTP client can reuse existing connections.
func FiringAlerts ¶ added in v0.6.0
FiringAlerts extracts a slice of firing alerts from the context. Iff none exists, the second argument is false.
func GetTemplateData ¶ added in v0.18.0
func GetTemplateData(ctx context.Context, tmpl *template.Template, alerts []*types.Alert, l *slog.Logger) *template.Data
GetTemplateData creates the template data from the context and the alerts.
func GroupKey ¶
GroupKey extracts a group key from the context. Iff none exists, the second argument is false.
func GroupLabels ¶
GroupLabels extracts grouping label set from the context. Iff none exists, the second argument is false.
func GroupMatchers ¶ added in v0.33.0
GroupMatchers extracts the route's matchers from the context.
func MuteTimeIntervalNames ¶ added in v0.22.0
MuteTimeIntervalNames extracts a slice of mute time names from the context. If and only if none exists, the second argument is false.
func MutedAlerts ¶ added in v0.33.0
MutedAlerts extracts a set of muted alert hashes from the context.
func NewAlertGroupedEvent ¶ added in v0.33.0
func NewAlertGroupedEvent(groupInfo *eventrecorderpb.AlertGroupInfo, alert *types.Alert) *eventrecorderpb.EventData
func NewAlertResolvedEvent ¶ added in v0.33.0
func NewAlertResolvedEvent(groupInfo *eventrecorderpb.AlertGroupInfo, alert *types.Alert) *eventrecorderpb.EventData
func NewClientWithTracing ¶ added in v0.30.1
func NewClientWithTracing(cfg commoncfg.HTTPClientConfig, name string, httpOpts ...commoncfg.HTTPClientOption) (*http.Client, error)
NewClientWithTracing creates a new HTTP client with tracing included Clients are reused across requests, so tracing is configured once at creation rather than on each request.
func NewNotificationEvent ¶ added in v0.33.0
func NewNotificationEvent(ctx context.Context, alerts []*types.Alert, integration Integration) *eventrecorderpb.EventData
NewNotificationEvent constructs a NotificationEvent from the pipeline context after a successful notification delivery.
func NflogStore ¶ added in v0.31.0
NflogStore extracts the nflog.Store from the context. The returned NflogStore is a pointer to a mutable store which remains in the context.
func Now ¶
Now extracts a now timestamp from the context. Iff none exists, the second argument is false.
func PostJSON ¶ added in v0.18.0
func PostJSON(ctx context.Context, client *http.Client, url string, body io.Reader) (*http.Response, error)
PostJSON sends a POST request with JSON payload to the given URL.
func PostText ¶ added in v0.18.0
func PostText(ctx context.Context, client *http.Client, url string, body io.Reader) (*http.Response, error)
PostText sends a POST request with text payload to the given URL.
func ReceiverName ¶ added in v0.5.0
ReceiverName extracts a receiver name from the context. Iff none exists, the second argument is false.
func RepeatInterval ¶
RepeatInterval extracts a repeat interval from the context. Iff none exists, the second argument is false.
func ResolvedAlerts ¶ added in v0.6.0
ResolvedAlerts extracts a slice of resolved alerts from the context. Iff none exists, the second argument is false.
func RouteID ¶ added in v0.28.0
RouteID extracts a RouteID from the context. Iff none exists, the // second argument is false.
func TmplHTML ¶ added in v0.18.0
TmplHTML is using monadic error handling in order to make string templating less verbose. Use with care as the final error checking is easily missed.
func TmplText ¶ added in v0.18.0
TmplText is using monadic error handling in order to make string templating less verbose. Use with care as the final error checking is easily missed.
func TruncateInBytes ¶ added in v0.25.0
TruncateInBytes truncates a string to fit the given size in Bytes.
func TruncateInRunes ¶ added in v0.25.0
TruncateInRunes truncates a string to fit the given size in Runes.
func WithActiveTimeIntervals ¶ added in v0.24.0
WithActiveTimeIntervals populates a context with a slice of active time names.
func WithAggrGroupID ¶ added in v0.33.0
WithAggrGroupID populates a context with an aggregation group UUID.
func WithFiringAlerts ¶ added in v0.6.0
WithFiringAlerts populates a context with a slice of firing alerts.
func WithFlushID ¶ added in v0.33.0
WithFlushID populates a context with a flush identifier.
func WithGroupKey ¶
WithGroupKey populates a context with a group key.
func WithGroupLabels ¶
WithGroupLabels populates a context with grouping labels.
func WithGroupMatchers ¶ added in v0.33.0
WithGroupMatchers populates a context with the route's matchers.
func WithMuteTimeIntervals ¶ added in v0.22.0
WithMuteTimeIntervals populates a context with a slice of mute time names.
func WithMutedAlerts ¶ added in v0.33.0
WithMutedAlerts populates a context with a set of muted alert hashes.
func WithNflogStore ¶ added in v0.31.0
WithNflogStore populates a context with a reference to an nflog.Store.
func WithNotificationReason ¶ added in v0.32.0
func WithNotificationReason(ctx context.Context, reason NotifyReason) context.Context
WithNotificationReason populates a context with a NotifyReason.
func WithReceiverName ¶ added in v0.5.0
WithReceiverName populates a context with a receiver name.
func WithRepeatInterval ¶
WithRepeatInterval populates a context with a repeat interval.
func WithResolvedAlerts ¶ added in v0.6.0
WithResolvedAlerts populates a context with a slice of resolved alerts.
Types ¶
type ClusterGossipSettleStage ¶ added in v0.33.0
type ClusterGossipSettleStage struct {
// contains filtered or unexported fields
}
ClusterGossipSettleStage waits until the Gossip has settled to forward alerts.
func NewClusterGossipSettleStage ¶ added in v0.33.0
func NewClusterGossipSettleStage(p Peer) *ClusterGossipSettleStage
NewClusterGossipSettleStage returns a new ClusterGossipSettleStage.
type ClusterWaitStage ¶ added in v0.33.0
type ClusterWaitStage struct {
// contains filtered or unexported fields
}
ClusterWaitStage waits for a certain amount of time before continuing or until the context is done.
func NewClusterWaitStage ¶ added in v0.33.0
func NewClusterWaitStage(wait func() time.Duration) *ClusterWaitStage
NewClusterWaitStage returns a new ClusterWaitStage.
type DedupStage ¶ added in v0.5.0
type DedupStage struct {
// contains filtered or unexported fields
}
DedupStage filters alerts. Filtering happens based on a notification log.
func NewDedupStage ¶ added in v0.5.0
func NewDedupStage(rs ResolvedSender, l NotificationLog, recv *nflogpb.Receiver) *DedupStage
NewDedupStage wraps a DedupStage that runs against the given notification log.
type ErrorWithReason ¶ added in v0.26.0
func NewErrorWithReason ¶ added in v0.26.0
func NewErrorWithReason(reason Reason, err error) *ErrorWithReason
func (*ErrorWithReason) Error ¶ added in v0.26.0
func (e *ErrorWithReason) Error() string
type FanoutStage ¶ added in v0.5.0
type FanoutStage []Stage
FanoutStage executes its stages concurrently.
func (FanoutStage) Exec ¶ added in v0.5.0
func (fs FanoutStage) Exec(ctx context.Context, l *slog.Logger, alerts ...*alert.Alert) (context.Context, []*alert.Alert, error)
Exec attempts to execute all stages concurrently and discards the results. It returns its input alerts and an error if one or more stages fail.
type Integration ¶ added in v0.5.0
type Integration struct {
// contains filtered or unexported fields
}
Integration wraps a notifier and its configuration to be uniquely identified by name and index from its origin in the configuration.
func NewIntegration ¶ added in v0.18.0
func NewIntegration(notifier Notifier, rs ResolvedSender, name string, idx int, receiverName string) Integration
NewIntegration returns a new integration.
func (*Integration) Index ¶ added in v0.18.0
func (i *Integration) Index() int
Index returns the index of the integration.
func (*Integration) Name ¶ added in v0.18.0
func (i *Integration) Name() string
Name returns the name of the integration.
func (*Integration) Notify ¶ added in v0.5.0
func (i *Integration) Notify(ctx context.Context, alerts ...*alert.Alert) (recoverable bool, err error)
Notify implements the Notifier interface.
func (*Integration) SendResolved ¶ added in v0.18.0
func (i *Integration) SendResolved() bool
SendResolved implements the ResolvedSender interface.
func (*Integration) String ¶ added in v0.21.0
func (i *Integration) String() string
String implements the Stringer interface.
type Key ¶ added in v0.18.0
type Key string
Key is a string that can be hashed.
func ExtractGroupKey ¶ added in v0.18.0
ExtractGroupKey gets the group key from the context.
type Metrics ¶ added in v0.22.0
type Metrics struct {
// contains filtered or unexported fields
}
func NewMetrics ¶ added in v0.22.0
func NewMetrics(r prometheus.Registerer, ff featurecontrol.Flagger) *Metrics
func (*Metrics) InitializeFor ¶ added in v0.27.0
func (m *Metrics) InitializeFor(receiver map[string][]Integration)
type MultiStage ¶ added in v0.5.0
type MultiStage []Stage
A MultiStage executes a series of stages sequentially.
type MuteStage ¶ added in v0.17.0
type MuteStage struct {
// contains filtered or unexported fields
}
MuteStage filters alerts through a Muter.
func NewMuteStage ¶ added in v0.17.0
NewMuteStage return a new MuteStage.
type Muter ¶ added in v0.32.0
A Muter determines whether a given label set is muted. Implementers that maintain an underlying AlertMarker are expected to update it during a call of Mutes.
type NotificationLog ¶ added in v0.15.0
type Notifier ¶
Notifier notifies about alerts under constraints of the given context. It returns an error if unsuccessful and a flag whether the error is recoverable. This information is useful for a retry logic.
type NotifyReason ¶ added in v0.32.0
type NotifyReason int
const ( ReasonDoNotNotify NotifyReason = iota ReasonFirstNotification ReasonNewAlertsInGroup ReasonNewResolvedAlerts ReasonAllAlertsResolved ReasonRepeatIntervalElapsed ReasonUnknown )
func NotificationReason ¶ added in v0.32.0
func NotificationReason(ctx context.Context) (NotifyReason, bool)
NotificationReason extracts a NotifyReason from the context.
func (NotifyReason) String ¶ added in v0.32.0
func (r NotifyReason) String() string
type Peer ¶ added in v0.22.0
type Peer interface {
// WaitReady waits until the node silences and notifications have settled before attempting to send a notification.
WaitReady(context.Context) error
}
Peer represents the cluster node from where we are the sending the notification.
type PipelineBuilder ¶ added in v0.19.0
type PipelineBuilder struct {
// contains filtered or unexported fields
}
func NewPipelineBuilder ¶ added in v0.19.0
func NewPipelineBuilder(r prometheus.Registerer, ff featurecontrol.Flagger, recorder eventrecorder.Recorder) *PipelineBuilder
func (*PipelineBuilder) New ¶ added in v0.19.0
func (pb *PipelineBuilder) New( receivers map[string][]Integration, wait func() time.Duration, inhibitor *inhibit.Inhibitor, silencer *silence.Silencer, intervener *timeinterval.Intervener, marker marker.GroupMarker, notificationLog NotificationLog, peer Peer, ) RoutingStage
New returns a map of receivers to Stages.
type Reason ¶ added in v0.26.0
type Reason int
Reason is the failure reason.
func GetFailureReasonFromStatusCode ¶ added in v0.26.0
GetFailureReasonFromStatusCode returns the reason for the failure based on the status code provided.
type ResolvedSender ¶ added in v0.18.0
type ResolvedSender interface {
SendResolved() bool
}
ResolvedSender returns true if resolved notifications should be sent.
type Retrier ¶ added in v0.19.0
type Retrier struct {
// Function to return additional information in the error message.
CustomDetailsFunc func(code int, body io.Reader) string
// Additional HTTP status codes that should be retried.
RetryCodes []int
}
Retrier knows when to retry an HTTP request to a receiver. 2xx status codes are successful, anything else is a failure and only 5xx status codes should be retried.
type RetryStage ¶ added in v0.5.0
type RetryStage struct {
// contains filtered or unexported fields
}
RetryStage notifies via passed integration with exponential backoff until it succeeds. It aborts if the context is canceled or timed out.
func NewRetryStage ¶ added in v0.5.0
func NewRetryStage(i Integration, groupName string, metrics *Metrics, recorder eventrecorder.Recorder) *RetryStage
NewRetryStage returns a new instance of a RetryStage.
type RoutingStage ¶ added in v0.5.0
RoutingStage executes the inner stages based on the receiver specified in the context.
type SetNotifiesStage ¶ added in v0.5.0
type SetNotifiesStage struct {
// contains filtered or unexported fields
}
SetNotifiesStage sets the notification information about passed alerts. The passed alerts should have already been sent to the receivers.
func NewSetNotifiesStage ¶ added in v0.5.0
func NewSetNotifiesStage(l NotificationLog, recv *nflogpb.Receiver) *SetNotifiesStage
NewSetNotifiesStage returns a new instance of a SetNotifiesStage.
type Stage ¶ added in v0.5.0
type Stage interface {
Exec(ctx context.Context, l *slog.Logger, alerts ...*alert.Alert) (context.Context, []*alert.Alert, error)
}
A Stage processes alerts under the constraints of the given context.
type StageFunc ¶ added in v0.5.0
type StageFunc func(ctx context.Context, l *slog.Logger, alerts ...*alert.Alert) (context.Context, []*alert.Alert, error)
StageFunc wraps a function to represent a Stage.
type TimeActiveStage ¶ added in v0.24.0
type TimeActiveStage timeStage
func NewTimeActiveStage ¶ added in v0.24.0
func NewTimeActiveStage(muter TimeMuter, marker marker.GroupMarker, metrics *Metrics) *TimeActiveStage
func (TimeActiveStage) Exec ¶ added in v0.24.0
func (tas TimeActiveStage) Exec(ctx context.Context, l *slog.Logger, alerts ...*alert.Alert) (context.Context, []*alert.Alert, error)
Exec implements the stage interface for TimeActiveStage. TimeActiveStage is responsible for muting alerts whose route is not in an active time.
type TimeMuteStage ¶ added in v0.22.0
type TimeMuteStage timeStage
func NewTimeMuteStage ¶ added in v0.22.0
func NewTimeMuteStage(muter TimeMuter, marker marker.GroupMarker, metrics *Metrics) *TimeMuteStage
func (TimeMuteStage) Exec ¶ added in v0.22.0
func (tms TimeMuteStage) Exec(ctx context.Context, l *slog.Logger, alerts ...*alert.Alert) (context.Context, []*alert.Alert, error)
Exec implements the stage interface for TimeMuteStage. TimeMuteStage is responsible for muting alerts whose route is not in an active time.
type TimeMuter ¶ added in v0.32.0
type TimeMuter interface {
Mutes(timeIntervalNames []string, now time.Time) (bool, []string, error)
}
A TimeMuter determines if the time is muted by one or more active or mute time intervals. If the time is muted, it returns true and the names of the time intervals that muted it. Otherwise, it returns false and a nil slice.