alert

package
v0.0.0-...-02c6b06 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alert

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

func New

func New(log logr.Logger, cfg Config) *Alert

New creates a new instance of alert

func (*Alert) FindFailedAndRecoveredTests

func (alerter *Alert) FindFailedAndRecoveredTests() (map[string]TestDetails, map[string]TestDetails, error)

FindFailedAndRecoveredTests finds distinct, failed tests, that has not yet been posted on slack in recent n days

func (*Alert) PostAlertMessageToSlack

func (alerter *Alert) PostAlertMessageToSlack(client slack.Client, channel string, failedTests map[string]TestDetails) error

PostAlertMessageToSlack posts alerts to slack

func (*Alert) PostRecoverMessageToSlack

func (alerter *Alert) PostRecoverMessageToSlack(client slack.Client, channel string, recoveredTests map[string]TestDetails) error

PostRecoverMessageToSlack posts alerts to slack

type AlertDocs

type AlertDocs struct {
	Hits struct {
		AlertItems []struct {
			Source TestDetails `json:"_source"`
		} `json:"hits"`
	} `json:"hits"`
}

AlertDocs elasticsearch alert docs structure

type Config

type Config struct {
	EvalTimeDays                int // EvalTimeDays time range to consinder for evaluation in days (now - n days before)
	SuccessRateThresholdPercent int // SuccessRateThresholdPercent if test success rate falls below threshold post an alert
	ContinuousFailureThreshold  int // ContinuousFailureThreshold if test fails >=n times send alert
	ESClient                    elasticsearch.Client
	TestsSkip                   []string
	TestsFocus                  []string
}

Config represents alerting configuration

type ESTestmachineryDoc

type ESTestmachineryDoc struct {
	Source struct {
		Name          string `json:"name"`
		LastTimestamp string `json:"startTime"`
		TM            struct {
			Cloudprovider   string `json:"cloudprovider"`
			K8sVersion      string `json:"k8s_version"`
			OperatingSystem string `json:"operating_system"`
			Landscape       string `json:"landscape"`
			Testrun         struct {
				ID string `json:"id"`
			} `json:"tr"`
		} `json:"tm"`
	} `json:"_source"`
}

type ElasticsearchConfig

type ElasticsearchConfig struct {
	Endpoint *url.URL
	User     string
	Pass     string
}

ElasticsearchConfig represents the elasticsearch configuration

type TestContextAggregation

type TestContextAggregation struct {
	Aggs struct {
		TestContext struct {
			TestDetailsRaw []struct {
				Testcontext string `json:"key"`
				Details     struct {
					Hits struct {
						Docs []ESTestmachineryDoc `json:"hits"`
					} `json:"hits"`
				} `json:"details"`
				SuccessTrend struct {
					Hits struct {
						Hits []struct {
							Source struct {
								Pre struct {
									PhaseNum int `json:"phaseNum"`
								} `json:"pre"`
							} `json:"_source"`
						} `json:"hits"`
					} `json:"hits"`
				} `json:"success_trend"`
				SuccessRate struct {
					Value float64 `json:"value"`
				} `json:"success_rate"`
			} `json:"buckets"`
		} `json:"test_context"`
	} `json:"aggregations"`
}

TestContextAggregation elasticsearch distinct names aggregation structure

type TestDetails

type TestDetails struct {
	Name                string  `json:"name"`               //Name test name
	Context             string  `json:"testContext"`        //Context is the concatenation of name and several test dimensions
	FailedContinuously  bool    `json:"failedContinuously"` //FailedContinuously true if n recent test runs were failing in a row
	LastFailedTimestamp string  `json:"lastTimeFailed"`     //LastFailedTimestamp timestamp of last failed test execution
	SuccessRate         float64 `json:"successRate"`        //SuccessRate of recent n days
	FiledAlertDataTime  string  `json:"datetime"`           //FiledAlertDataTime is the timestamp when the alert has been filed in slack
	Successful          bool    `json:"-"`                  //Successful is true if success rate doesn't go below threshold and isn't failed continuously
	Cloudprovider       string  `json:"cloudprovider,omitempty"`
	OperatingSystem     string  `json:"operatingSystem,omitempty"`
	Landscape           string  `json:"landscape"`
	K8sVersion          string  `json:"k8sVersion,omitempty"`
	TestrunID           string  `json:"testrunID"`
}

TestDetails describes a test which is used for alert message

func (TestDetails) ElasticsearchBulkString

func (test TestDetails) ElasticsearchBulkString() (string, error)

ElasticsearchBulkString creates an elastic search bulk string for ingestion

Jump to

Keyboard shortcuts

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