func At(ts float64) float64
At is a convenience method to allow for declarative syntax of Acceptance test definitions.
func CompareCollectors(a, b *Collector, opts *AcceptanceOpts) (bool, error)
CompareCollectors compares two collectors based on their collected alerts
AcceptanceOpts defines configuration parameters for an acceptance test.
type AcceptanceOpts struct { RoutePrefix string Tolerance time.Duration // contains filtered or unexported fields }
AcceptanceTest provides declarative definition of given inputs and expected output of an Alertmanager setup.
type AcceptanceTest struct { *testing.T // contains filtered or unexported fields }
func NewAcceptanceTest(t *testing.T, opts *AcceptanceOpts) *AcceptanceTest
NewAcceptanceTest returns a new acceptance test with the base time set to the current time.
func (t *AcceptanceTest) AlertmanagerCluster(conf string, size int) *AlertmanagerCluster
AlertmanagerCluster returns a new AlertmanagerCluster that allows starting a cluster of Alertmanager instances on random ports.
func (t *AcceptanceTest) Collector(name string) *Collector
Collector returns a new collector bound to the test instance.
func (t *AcceptanceTest) Do(at float64, f func())
Do sets the given function to be executed at the given time.
func (t *AcceptanceTest) Run()
Run starts all Alertmanagers and runs queries against them. It then checks whether all expected notifications have arrived at the expected receiver.
Alertmanager encapsulates an Alertmanager process and allows declaring alerts being pushed to it at fixed points in time.
type Alertmanager struct {
// contains filtered or unexported fields
}
func (am *Alertmanager) Client() *apiclient.AlertmanagerAPI
Client returns a client to interact with the API v2 endpoint.
func (am *Alertmanager) DelSilence(at float64, sil *TestSilence)
DelSilence deletes the silence with the sid at the given time.
func (am *Alertmanager) Push(at float64, alerts ...*TestAlert)
Push declares alerts that are to be pushed to the Alertmanager server at a relative point in time.
func (am *Alertmanager) Reload()
Reload sends the reloading signal to the Alertmanager process.
func (am *Alertmanager) SetSilence(at float64, sil *TestSilence)
SetSilence updates or creates the given Silence.
func (am *Alertmanager) Start(additionalArg []string) error
Start the alertmanager and wait until it is ready to receive.
func (am *Alertmanager) Terminate()
Terminate kills the underlying Alertmanager process and remove intermediate data.
func (am *Alertmanager) UpdateConfig(conf string)
UpdateConfig rewrites the configuration file for the Alertmanager. It does not initiate config reloading.
func (am *Alertmanager) WaitForCluster(size int) error
WaitForCluster waits for the Alertmanager instance to join a cluster with the given size.
AlertmanagerCluster represents a group of Alertmanager instances acting as a cluster.
type AlertmanagerCluster struct {
// contains filtered or unexported fields
}
func (amc *AlertmanagerCluster) DelSilence(at float64, sil *TestSilence)
DelSilence deletes the silence with the sid at the given time.
func (amc *AlertmanagerCluster) Members() []*Alertmanager
Members returns the underlying slice of cluster members.
func (amc *AlertmanagerCluster) Push(at float64, alerts ...*TestAlert)
Push declares alerts that are to be pushed to the Alertmanager servers at a relative point in time.
func (amc *AlertmanagerCluster) Reload()
Reload sends the reloading signal to the Alertmanager instances.
func (amc *AlertmanagerCluster) SetSilence(at float64, sil *TestSilence)
SetSilence updates or creates the given Silence.
func (amc *AlertmanagerCluster) Start() error
Start the Alertmanager cluster and wait until it is ready to receive.
func (amc *AlertmanagerCluster) Terminate()
Terminate kills the underlying Alertmanager cluster processes and removes intermediate data.
func (amc *AlertmanagerCluster) UpdateConfig(conf string)
UpdateConfig rewrites the configuration file for the Alertmanager cluster. It does not initiate config reloading.
Collector gathers alerts received by a notification receiver and verifies whether all arrived and within the correct time boundaries.
type Collector struct {
// contains filtered or unexported fields
}
func (c *Collector) Check() string
func (c *Collector) Collected() map[float64][]models.GettableAlerts
Collected returns a map of alerts collected by the collector indexed with the receive timestamp.
func (c *Collector) String() string
func (c *Collector) Want(iv Interval, alerts ...*TestAlert)
Want declares that the Collector expects to receive the given alerts within the given time boundaries.
type Interval struct {
// contains filtered or unexported fields
}
func Between(start, end float64) Interval
Between is a convenience constructor for an interval for declarative syntax of Acceptance test definitions.
func (iv Interval) String() string
type MockWebhook struct { // Func is called early on when retrieving a notification by an // Alertmanager. If Func returns true, the given notification is dropped. // See sample usage in `send_test.go/TestRetry()`. Func func(timestamp float64) bool // contains filtered or unexported fields }
func NewWebhook(t *testing.T, c *Collector) *MockWebhook
func (ws *MockWebhook) Address() string
func (ws *MockWebhook) ServeHTTP(w http.ResponseWriter, req *http.Request)
TestAlert models a model.Alert with relative times.
type TestAlert struct {
// contains filtered or unexported fields
}
func Alert(keyval ...interface{}) *TestAlert
Alert creates a new alert declaration with the given key/value pairs as identifying labels.
func (a *TestAlert) Active(tss ...float64) *TestAlert
Active declares the relative activity time for this alert. It must be a single starting value or two values where the second value declares the resolved time.
func (a *TestAlert) Annotate(keyval ...interface{}) *TestAlert
Annotate the alert with the given key/value pairs.
TestSilence models a model.Silence with relative times.
type TestSilence struct {
// contains filtered or unexported fields
}
func Silence(start, end float64) *TestSilence
Silence creates a new TestSilence active for the relative interval given by start and end.
func (s *TestSilence) ID() string
ID gets the silence ID.
func (s *TestSilence) Match(v ...string) *TestSilence
Match adds a new plain matcher to the silence.
func (s *TestSilence) MatchRE(v ...string) *TestSilence
MatchRE adds a new regex matcher to the silence
func (s *TestSilence) SetID(ID string)
SetID sets the silence ID.