test

package
v0.25.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2022 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func At

func At(ts float64) float64

At is a convenience method to allow for declarative syntax of Acceptance test definitions.

Types

type APIV1Alert added in v0.24.0

type APIV1Alert struct {
	Labels       LabelSet  `json:"labels"`
	Annotations  LabelSet  `json:"annotations"`
	StartsAt     time.Time `json:"startsAt,omitempty"`
	EndsAt       time.Time `json:"endsAt,omitempty"`
	GeneratorURL string    `json:"generatorURL"`
}

APIV1Alert represents an alert as expected by the AlertManager's push alert API.

type AcceptanceOpts

type AcceptanceOpts struct {
	RoutePrefix string
	Tolerance   time.Duration
	// contains filtered or unexported fields
}

AcceptanceOpts defines configuration parameters for an acceptance test.

type AcceptanceTest

type AcceptanceTest struct {
	*testing.T
	// contains filtered or unexported fields
}

AcceptanceTest provides declarative definition of given inputs and expected output of an Alertmanager setup.

func NewAcceptanceTest

func NewAcceptanceTest(t *testing.T, opts *AcceptanceOpts) *AcceptanceTest

NewAcceptanceTest returns a new acceptance test with the base time set to the current time.

func (*AcceptanceTest) Alertmanager

func (t *AcceptanceTest) Alertmanager(conf string) *Alertmanager

Alertmanager returns a new structure that allows starting an instance of Alertmanager on a random port.

func (*AcceptanceTest) Collector

func (t *AcceptanceTest) Collector(name string) *Collector

Collector returns a new collector bound to the test instance.

func (*AcceptanceTest) Do

func (t *AcceptanceTest) Do(at float64, f func())

Do sets the given function to be executed at the given time.

func (*AcceptanceTest) Run

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.

type AlertAPI added in v0.24.0

type AlertAPI interface {
	// List returns all the active alerts.
	List(ctx context.Context, filter, receiver string, silenced, inhibited, active, unprocessed bool) ([]*ExtendedAlert, error)
	// Push sends a list of alerts to the Alertmanager.
	Push(ctx context.Context, alerts ...APIV1Alert) error
}

AlertAPI provides bindings for the Alertmanager's alert API.

func NewAlertAPI added in v0.24.0

func NewAlertAPI(c api.Client) AlertAPI

NewAlertAPI returns a new AlertAPI for the client.

type Alertmanager

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

Alertmanager encapsulates an Alertmanager process and allows declaring alerts being pushed to it at fixed points in time.

func (*Alertmanager) DelSilence

func (am *Alertmanager) DelSilence(at float64, sil *TestSilence)

DelSilence deletes the silence with the sid at the given time.

func (*Alertmanager) Push

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 (*Alertmanager) Reload

func (am *Alertmanager) Reload()

Reload sends the reloading signal to the Alertmanager process.

func (*Alertmanager) SetSilence

func (am *Alertmanager) SetSilence(at float64, sil *TestSilence)

SetSilence updates or creates the given Silence.

func (*Alertmanager) Start

func (am *Alertmanager) Start()

Start the alertmanager and wait until it is ready to receive.

func (*Alertmanager) Terminate

func (am *Alertmanager) Terminate()

Terminate kills the underlying Alertmanager process and remove intermediate data.

func (*Alertmanager) UpdateConfig

func (am *Alertmanager) UpdateConfig(conf string)

UpdateConfig rewrites the configuration file for the Alertmanager. It does not initiate config reloading.

type ClusterStatus added in v0.24.0

type ClusterStatus struct {
	Name   string       `json:"name"`
	Status string       `json:"status"`
	Peers  []PeerStatus `json:"peers"`
}

ClusterStatus represents the status of the cluster.

type Collector

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

Collector gathers alerts received by a notification receiver and verifies whether all arrived and within the correct time boundaries.

func (*Collector) String

func (c *Collector) String() string

func (*Collector) Want

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 ExtendedAlert added in v0.24.0

type ExtendedAlert struct {
	APIV1Alert
	Status      types.AlertStatus `json:"status"`
	Receivers   []string          `json:"receivers"`
	Fingerprint string            `json:"fingerprint"`
}

ExtendedAlert represents an alert as returned by the AlertManager's list alert API.

type Interval

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

func Between

func Between(start, end float64) Interval

Between is a convenience constructor for an interval for declarative syntax of Acceptance test definitions.

func (Interval) String

func (iv Interval) String() string

type LabelName added in v0.24.0

type LabelName string

LabelName represents the name of a label.

type LabelSet added in v0.24.0

type LabelSet map[LabelName]LabelValue

LabelSet represents a collection of label names and values as a map.

type LabelValue added in v0.24.0

type LabelValue string

LabelValue represents the value of a label.

type MockWebhook

type MockWebhook struct {
	Func func(timestamp float64) bool
	// contains filtered or unexported fields
}

func NewWebhook

func NewWebhook(c *Collector) *MockWebhook

func (*MockWebhook) Address

func (ws *MockWebhook) Address() string

func (*MockWebhook) ServeHTTP

func (ws *MockWebhook) ServeHTTP(w http.ResponseWriter, req *http.Request)

type PeerStatus added in v0.24.0

type PeerStatus struct {
	Name    string `json:"name"`
	Address string `json:"address"`
}

PeerStatus represents the status of a peer in the cluster.

type ServerStatus added in v0.24.0

type ServerStatus struct {
	ConfigYAML    string            `json:"configYAML"`
	ConfigJSON    *config.Config    `json:"configJSON"`
	VersionInfo   map[string]string `json:"versionInfo"`
	Uptime        time.Time         `json:"uptime"`
	ClusterStatus *ClusterStatus    `json:"clusterStatus"`
}

ServerStatus represents the status of the AlertManager endpoint.

type SilenceAPI added in v0.24.0

type SilenceAPI interface {
	// Get returns the silence associated with the given ID.
	Get(ctx context.Context, id string) (*types.Silence, error)
	// Set updates or creates the given silence and returns its ID.
	Set(ctx context.Context, sil types.Silence) (string, error)
	// Expire expires the silence with the given ID.
	Expire(ctx context.Context, id string) error
	// List returns silences matching the given filter.
	List(ctx context.Context, filter string) ([]*types.Silence, error)
}

SilenceAPI provides bindings for the Alertmanager's silence API.

func NewSilenceAPI added in v0.24.0

func NewSilenceAPI(c api.Client) SilenceAPI

NewSilenceAPI returns a new SilenceAPI for the client.

type StatusAPI added in v0.24.0

type StatusAPI interface {
	// Get returns the server's configuration, version, uptime and cluster information.
	Get(ctx context.Context) (*ServerStatus, error)
}

StatusAPI provides bindings for the Alertmanager's status API.

func NewStatusAPI added in v0.24.0

func NewStatusAPI(c api.Client) StatusAPI

NewStatusAPI returns a status API client.

type TestAlert

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

TestAlert models a model.Alert with relative times.

func Alert

func Alert(keyval ...interface{}) *TestAlert

Alert creates a new alert declaration with the given key/value pairs as identifying labels.

func (*TestAlert) Active

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 (*TestAlert) Annotate

func (a *TestAlert) Annotate(keyval ...interface{}) *TestAlert

Annotate the alert with the given key/value pairs.

type TestSilence

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

TestSilence models a model.Silence with relative times.

func Silence

func Silence(start, end float64) *TestSilence

Silence creates a new TestSilence active for the relative interval given by start and end.

func (*TestSilence) ID

func (s *TestSilence) ID() string

ID gets the silence ID.

func (*TestSilence) Match

func (s *TestSilence) Match(v ...string) *TestSilence

Match adds a new plain matcher to the silence.

func (*TestSilence) MatchRE

func (s *TestSilence) MatchRE(v ...string) *TestSilence

MatchRE adds a new regex matcher to the silence

func (*TestSilence) SetID

func (s *TestSilence) SetID(ID string)

SetID sets the silence ID.

Jump to

Keyboard shortcuts

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