Documentation
¶
Overview ¶
nolint
Index ¶
- Constants
- func AlertmanagerFromGroup(tg *targetgroup.Group, cfg *config.AlertmanagerConfig) ([]alertmanager, []alertmanager, error)
- type Alert
- type AlertsRouter
- func (d *AlertsRouter) AlertmanagersFor(orgID int64) []*url.URL
- func (d *AlertsRouter) DroppedAlertmanagersFor(orgID int64) []*url.URL
- func (d *AlertsRouter) Run(ctx context.Context) error
- func (d *AlertsRouter) Send(ctx context.Context, key models.AlertRuleKey, ...)
- func (d *AlertsRouter) SyncAndApplyConfigFromDatabase(ctx context.Context) error
- type ExternalAMOptions
- type ExternalAMcfg
- type ExternalAlertmanager
- func (s *ExternalAlertmanager) Alertmanagers() []*url.URL
- func (s *ExternalAlertmanager) ApplyConfig(orgId, id int64, alertmanagers []ExternalAMcfg) error
- func (s *ExternalAlertmanager) DroppedAlertmanagers() []*url.URL
- func (s *ExternalAlertmanager) Run()
- func (s *ExternalAlertmanager) SendAlerts(alerts apimodels.PostableAlerts)
- func (s *ExternalAlertmanager) Stop()
- type FakeExternalAlertmanager
- func (am *FakeExternalAlertmanager) AlertNamesCompare(expected []string) bool
- func (am *FakeExternalAlertmanager) Alerts() amv2.PostableAlerts
- func (am *FakeExternalAlertmanager) AlertsCount() int
- func (am *FakeExternalAlertmanager) Close()
- func (am *FakeExternalAlertmanager) Handler() func(w http.ResponseWriter, r *http.Request)
- func (am *FakeExternalAlertmanager) URL() string
- type InfraLoggerHandler
- type Manager
- func (n *Manager) Alertmanagers() []*url.URL
- func (n *Manager) ApplyConfig(conf *config.Config, headers map[string]http.Header) error
- func (n *Manager) DroppedAlertmanagers() []*url.URL
- func (n *Manager) Run(tsets <-chan map[string][]*targetgroup.Group)
- func (n *Manager) Send(alerts ...*Alert)
- func (n *Manager) Stop()
- type Option
- type Options
- type SlogAdapter
Constants ¶
const (
// DefaultMaxBatchSize is the default maximum number of alerts to send in a single request to the alertmanager.
DefaultMaxBatchSize = 256
)
Variables ¶
This section is empty.
Functions ¶
func AlertmanagerFromGroup ¶
func AlertmanagerFromGroup(tg *targetgroup.Group, cfg *config.AlertmanagerConfig) ([]alertmanager, []alertmanager, error)
AlertmanagerFromGroup extracts a list of alertmanagers from a target group and an associated AlertmanagerConfig.
Types ¶
type Alert ¶
type Alert struct {
// Label value pairs for purpose of aggregation, matching, and disposition
// dispatching. This must minimally include an "alertname" label.
Labels labels.Labels `json:"labels"`
// Extra key/value information which does not define alert identity.
Annotations labels.Labels `json:"annotations"`
// The known time range for this alert. Both ends are optional.
StartsAt time.Time `json:"startsAt,omitempty"`
EndsAt time.Time `json:"endsAt,omitempty"`
GeneratorURL string `json:"generatorURL,omitempty"`
}
Alert is a generic representation of an alert in the Prometheus eco-system.
func (*Alert) ResolvedAt ¶
ResolvedAt returns true iff the activity interval ended before the given timestamp.
type AlertsRouter ¶
type AlertsRouter struct {
// contains filtered or unexported fields
}
AlertsRouter handles alerts generated during alert rule evaluation. Based on rule's orgID and the configuration for that organization, it determines whether an alert needs to be sent to an external Alertmanager and\or internal notifier.Alertmanager
After creating a AlertsRouter, you must call Run to keep the AlertsRouter's state synchronized with the alerting configuration.
func NewAlertsRouter ¶
func NewAlertsRouter(multiOrgNotifier *notifier.MultiOrgAlertmanager, store store.AdminConfigurationStore, clk clock.Clock, appURL *url.URL, disabledOrgs map[int64]struct{}, configPollInterval time.Duration, datasourceService datasources.DataSourceService, secretService secrets.Service, featureManager featuremgmt.FeatureToggles) *AlertsRouter
func (*AlertsRouter) AlertmanagersFor ¶
func (d *AlertsRouter) AlertmanagersFor(orgID int64) []*url.URL
AlertmanagersFor returns all the discovered Alertmanager(s) for a particular organization.
func (*AlertsRouter) DroppedAlertmanagersFor ¶
func (d *AlertsRouter) DroppedAlertmanagersFor(orgID int64) []*url.URL
DroppedAlertmanagersFor returns all the dropped Alertmanager(s) for a particular organization.
func (*AlertsRouter) Run ¶
func (d *AlertsRouter) Run(ctx context.Context) error
Run starts regular updates of the configuration.
func (*AlertsRouter) Send ¶
func (d *AlertsRouter) Send(ctx context.Context, key models.AlertRuleKey, alerts definitions.PostableAlerts)
func (*AlertsRouter) SyncAndApplyConfigFromDatabase ¶
func (d *AlertsRouter) SyncAndApplyConfigFromDatabase(ctx context.Context) error
SyncAndApplyConfigFromDatabase looks for the admin configuration in the database and adjusts the sender(s) and alert handling mechanism accordingly.
type ExternalAMOptions ¶
type ExternalAMOptions struct {
Options
// contains filtered or unexported fields
}
type ExternalAMcfg ¶
func (*ExternalAMcfg) SHA256 ¶
func (cfg *ExternalAMcfg) SHA256() string
type ExternalAlertmanager ¶
type ExternalAlertmanager struct {
// contains filtered or unexported fields
}
ExternalAlertmanager is responsible for dispatching alert notifications to an external Alertmanager service.
func NewExternalAlertmanagerSender ¶
func NewExternalAlertmanagerSender(l log.Logger, reg prometheus.Registerer, opts ...Option) (*ExternalAlertmanager, error)
func (*ExternalAlertmanager) Alertmanagers ¶
func (s *ExternalAlertmanager) Alertmanagers() []*url.URL
Alertmanagers returns a list of the discovered Alertmanager(s).
func (*ExternalAlertmanager) ApplyConfig ¶
func (s *ExternalAlertmanager) ApplyConfig(orgId, id int64, alertmanagers []ExternalAMcfg) error
ApplyConfig syncs a configuration with the sender.
func (*ExternalAlertmanager) DroppedAlertmanagers ¶
func (s *ExternalAlertmanager) DroppedAlertmanagers() []*url.URL
DroppedAlertmanagers returns a list of Alertmanager(s) we no longer send alerts to.
func (*ExternalAlertmanager) Run ¶
func (s *ExternalAlertmanager) Run()
func (*ExternalAlertmanager) SendAlerts ¶
func (s *ExternalAlertmanager) SendAlerts(alerts apimodels.PostableAlerts)
SendAlerts sends a set of alerts to the configured Alertmanager(s).
func (*ExternalAlertmanager) Stop ¶
func (s *ExternalAlertmanager) Stop()
Stop shuts down the sender.
type FakeExternalAlertmanager ¶
type FakeExternalAlertmanager struct {
Server *httptest.Server
// contains filtered or unexported fields
}
func NewFakeExternalAlertmanager ¶
func NewFakeExternalAlertmanager(t *testing.T) *FakeExternalAlertmanager
func (*FakeExternalAlertmanager) AlertNamesCompare ¶
func (am *FakeExternalAlertmanager) AlertNamesCompare(expected []string) bool
func (*FakeExternalAlertmanager) Alerts ¶
func (am *FakeExternalAlertmanager) Alerts() amv2.PostableAlerts
func (*FakeExternalAlertmanager) AlertsCount ¶
func (am *FakeExternalAlertmanager) AlertsCount() int
func (*FakeExternalAlertmanager) Close ¶
func (am *FakeExternalAlertmanager) Close()
func (*FakeExternalAlertmanager) Handler ¶
func (am *FakeExternalAlertmanager) Handler() func(w http.ResponseWriter, r *http.Request)
func (*FakeExternalAlertmanager) URL ¶
func (am *FakeExternalAlertmanager) URL() string
type InfraLoggerHandler ¶
type InfraLoggerHandler struct {
// contains filtered or unexported fields
}
InfraLoggerHandler adapts infra's log.Logger to an slog.Handler
func (*InfraLoggerHandler) Handle ¶
Handle processes a log record and routes it to infra's log.Logger
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager is responsible for dispatching alert notifications to an alert manager service.
func NewManager ¶
NewManager is the manager constructor.
func (*Manager) Alertmanagers ¶
Alertmanagers returns a slice of Alertmanager URLs.
func (*Manager) ApplyConfig ¶
ApplyConfig updates the status state as the new config requires. Extension: add new parameter headers.
func (*Manager) DroppedAlertmanagers ¶
DroppedAlertmanagers returns a slice of Alertmanager URLs.
func (*Manager) Run ¶
func (n *Manager) Run(tsets <-chan map[string][]*targetgroup.Group)
Run dispatches notifications continuously, returning once Stop has been called and all pending notifications have been drained from the queue (if draining is enabled).
Dispatching of notifications occurs in parallel to processing target updates to avoid one starving the other. Refer to https://github.com/prometheus/prometheus/issues/13676 for more details.
func (*Manager) Send ¶
Send queues the given notification requests for processing. Panics if called on a handler that is not running.
func (*Manager) Stop ¶
func (n *Manager) Stop()
Stop signals the notification manager to shut down and immediately returns.
Run will return once the notification manager has successfully shut down.
The manager will optionally drain any queued notifications before shutting down.
Stop is safe to call multiple times.
type Option ¶
type Option func(*ExternalAMOptions)
func WithDoFunc ¶
func WithDoFunc(doFunc doFunc) Option
WithDoFunc receives a function to use when making HTTP requests from the Manager.
func WithMaxBatchSize ¶
WithMaxBatchSize sets the maximum batch size for sending alerts to the external Alertmanager(s).
func WithMaxQueueCapacity ¶
WithMaxQueueCapacity sets the maximum capacity of the queue used by the sender.
func WithUTF8Labels ¶
func WithUTF8Labels() Option
WithUTF8Labels skips sanitizing labels and annotations before sending alerts to the external Alertmanager(s). It assumes UTF-8 label names are supported by the Alertmanager(s).
type Options ¶
type Options struct {
QueueCapacity int
DrainOnShutdown bool
ExternalLabels labels.Labels
RelabelConfigs []*relabel.Config
// Used for sending HTTP requests to the Alertmanager.
Do func(ctx context.Context, client *http.Client, req *http.Request) (*http.Response, error)
Registerer prometheus.Registerer
// MaxBatchSize determines the maximum number of alerts to send in a single request to the alertmanager.
MaxBatchSize int
}
Options are the configurable parameters of a Handler.
type SlogAdapter ¶
type SlogAdapter struct {
// contains filtered or unexported fields
}
func (*SlogAdapter) Log ¶
func (s *SlogAdapter) Log(keyvals ...interface{}) error
Log implements the Log method to satisfy the log.Logger interface.