alerts

package
v0.0.0-...-fcfcbe3 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: BSD-3-Clause Imports: 13 Imported by: 5

Documentation

Index

Constants

View Source
const (
	// BadAlertID is the value of an Alert.ID if it is invalid, i.e. hasn't
	// been stored yet.
	//
	// TODO(jcgregorio) Make Alert.ID its own type and BadAlertID and
	// instance of that type.
	BadAlertID = int64(-1)

	// BadAlertIDAsString is the value of an Alert.ID if it is invalid, i.e.
	// hasn't been stored yet.
	BadAlertIDAsAsString = "-1"
)
View Source
const InvalidIssueTrackerComponent = 0

InvalidIssueTrackerComponent indicates the issue tracker component hasn't been set.

Variables

View Source
var AllConfigState = []ConfigState{
	ACTIVE,
	DELETED,
}

AllConfigState is a list of all possible ConfigState values.

View Source
var AllDirections = []Direction{
	UP,
	DOWN,
	BOTH,
}

AllDirections is a list of all possible Direction values.

View Source
var (
	// DefaultSparse is the default value for Config.Sparse.
	DefaultSparse = false
)

Functions

func ConfigStateToInt

func ConfigStateToInt(c ConfigState) int

ConfigStateToInt converts the string ConfigState into an int, which it used to be, used only when storing Alerts.

func IDAsStringToInt

func IDAsStringToInt(s string) int64

IDAsStringToInt returns the IDAsString as an int64.

An invalid alert id (-1) will be returned if the string can't be parsed.

func IDToString

func IDToString(id int64) string

IDToString returns the alerts ID formatted as a string.

Types

type Alert

type Alert struct {
	// We need to keep the int64 version of the ID around to support Cloud
	// Datastore. Once everyone migrates to SQL backed datastores it can be
	// removed.
	IDAsString            string                            `json:"id_as_string"    `
	DisplayName           string                            `json:"display_name"    `
	Query                 string                            `json:"query"           `                       // The query to perform on the trace store to select the traces to alert on.
	Alert                 string                            `json:"alert"           `                       // Email address to send alerts to.
	IssueTrackerComponent SerializesToString                `json:"issue_tracker_component" go2ts:"string"` // The issue tracker component to send alerts to.
	Interesting           float32                           `json:"interesting"     `                       // The regression interestingness threshold.
	BugURITemplate        string                            `json:"bug_uri_template"`                       // URI Template used for reporting bugs. Format TBD.
	Algo                  types.RegressionDetectionGrouping `json:"algo"            `                       // Which clustering algorithm to use.
	Step                  types.StepDetection               `json:"step"            `

	// Which algorithm to use to detect steps.
	StateAsString ConfigState `json:"state"       ` // The state of the config.
	Owner         string      `json:"owner"       ` // Email address of the person that owns this alert.
	StepUpOnly    bool        `json:"step_up_only"` // If true then only steps up will trigger an alert. [Deprecated, use DirectionAsString.]

	// Direction is here to support the legacy format of Alerts where Direction
	// was an integer enum, with 0 = BOTH, 1 = UP, and 2 = DOWN. This is only
	// needed for Cloud Datastore, not SQL backed stores. This can be deleted
	// after migrating away from Cloud Datastore.
	Direction         int       `json:"-"          `
	DirectionAsString Direction `json:"direction"  ` // Which direction will trigger an alert.
	Radius            int       `json:"radius"     ` // How many commits to each side of a commit to consider when looking for a step. 0 means use the server default.
	K                 int       `json:"k"          ` // The K in k-means clustering. 0 means use an algorithmically chosen value based on the data.
	GroupBy           string    `json:"group_by"   ` // A comma separated list of keys in the paramset that all Clustering should be broken up across. Keys must not appear in Query.
	Sparse            bool      `json:"sparse"     ` // Data is sparse, so only include commits that have data.
	MinimumNum        int       `json:"minimum_num"` // How many traces need to be found interesting before an alert is fired.
	Category          string    `json:"category"   ` // Which category this alert falls into.

	// Action to take for this alert. It could be none, report or bisect.
	Action types.AlertAction `json:"action,omitempty"` // What action should be taken by the detected anomalies.

	// Subscription fields.
	SubscriptionName     string `json:"sub_name,omitempty"`
	SubscriptionRevision string `json:"sub_revision,omitempty"`
}

Alert represents the configuration for one alert.

func NewConfig

func NewConfig() *Alert

NewConfig creates a new Config properly initialized.

func (*Alert) GroupCombinations

func (c *Alert) GroupCombinations(ps paramtools.ReadOnlyParamSet) ([]Combination, error)

GroupCombinations returns a slice of Combinations that represent all the GroupBy combinations possible for the given ParamSet.

I.e. for:

ps := paramtools.ParamSet{
	"model":  []string{"nexus4", "nexus6", "nexus6"},
	"config": []string{"565", "8888", "nvpr"},
	"arch":   []string{"ARM", "x86"},
}

the GroupCombinations for a GroupBy of "config, arch" would be:

[]Combination{
	Combination{KeyValue{"arch", "ARM"}, KeyValue{"config", "565"}},
	Combination{KeyValue{"arch", "ARM"}, KeyValue{"config", "8888"}},
	Combination{KeyValue{"arch", "ARM"}, KeyValue{"config", "nvpr"}},
	Combination{KeyValue{"arch", "x86"}, KeyValue{"config", "565"}},
	Combination{KeyValue{"arch", "x86"}, KeyValue{"config", "8888"}},
	Combination{KeyValue{"arch", "x86"}, KeyValue{"config", "nvpr"}},
}

func (*Alert) GroupedBy

func (c *Alert) GroupedBy() []string

GroupedBy returns the parsed GroupBy value as a slice of strings.

func (*Alert) IDAsStringToInt

func (c *Alert) IDAsStringToInt() int64

IDAsStringToInt returns the IDAsString as an int64.

An invalid alert id (-1) will be returned if the string can't be parsed.

func (*Alert) QueriesFromParamset

func (c *Alert) QueriesFromParamset(paramset paramtools.ReadOnlyParamSet) ([]string, error)

QueriesFromParamset uses GroupCombinations to produce the full set of queries that this Config represents.

func (*Alert) SetIDFromInt64

func (c *Alert) SetIDFromInt64(id int64)

SetIDFromInt64 sets both the integer and string IDs.

func (*Alert) SetIDFromString

func (c *Alert) SetIDFromString(s string)

SetIDFromString sets the Alerts ID to the parsed value of the string.

An invalid alert id (-1) will be set if the string can't be parsed.

func (*Alert) StateToInt

func (c *Alert) StateToInt() int

StateToInt converts the State into an int which is used when storing Alerts.

func (*Alert) Validate

func (c *Alert) Validate() error

Validate returns true if the Alert is valid.

type AlertsStatus

type AlertsStatus struct {
	Alerts int `json:"alerts"`
}

type Combination

type Combination []KeyValue

Combination is a slice of KeyValue's, returned from GroupCombinations.

type ConfigProvider

type ConfigProvider interface {
	// GetAllAlertConfigs returns all alert configs.
	GetAllAlertConfigs(ctx context.Context, includeDeleted bool) ([]*Alert, error)

	// GetAlertConfig returns a specific alert config.
	GetAlertConfig(alertId int64) (*Alert, error)

	// Refresh resets the configs and forces a fresh update.
	Refresh(ctx context.Context) error
}

ConfigProvider is an interface to retrieve alert configs.

func NewConfigProvider

func NewConfigProvider(ctx context.Context, alertStore Store, refreshIntervalInSeconds int) (ConfigProvider, error)

NewConfigProvider returns a new instance of ConfigProvider interface.

type ConfigState

type ConfigState string

ConfigState is the current state of an alerts.Config.

const (
	ACTIVE  ConfigState = "ACTIVE"
	DELETED ConfigState = "DELETED"
)

The values for the AlertConfigState enum. Run 'go generate' if you add/remove/update these values. You must have 'stringer' installed, i.e.

go get golang.org/x/tools/cmd/stringer

type Direction

type Direction string

Direction a step takes that will cause an alert.

const (
	BOTH Direction = "BOTH"
	UP   Direction = "UP"
	DOWN Direction = "DOWN"
)

The values for the Direction enum. Run 'go generate' if you add/remove/update these values. You must have 'stringer' installed, i.e.

go get golang.org/x/tools/cmd/stringer

type KeyValue

type KeyValue struct {
	Key   string
	Value string
}

KeyValue holds a single Params key and value, used in 'Combination'.

type SaveRequest

type SaveRequest struct {
	Cfg    *Alert
	SubKey *SubKey
}

type SerializesToString

type SerializesToString int64

SerializesToString adds custom JSON marshalling to an int64 so it serializes to/from a string, which is needed when sending int64's to the browser, including serializing int64(0) to the empty string "".

Needed because: https://github.com/golang/go/issues/47102

func (SerializesToString) MarshalJSON

func (s SerializesToString) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*SerializesToString) UnmarshalJSON

func (s *SerializesToString) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler

type Store

type Store interface {
	// Save can write a new, or update an existing, Config. New Configs will
	// have an ID of -1. On insert the ID of the Alert will be updated.
	Save(ctx context.Context, req *SaveRequest) error

	// ReplaceAll will remove all existing Alerts, then it'll insert the
	// new input alerts and mark them as active.
	ReplaceAll(ctx context.Context, req []*SaveRequest) error

	// Delete removes the Alert with the given id.
	Delete(ctx context.Context, id int) error

	// List retrieves all the Alerts.
	//
	// If includeDeleted is true then deleted Alerts are also included in the
	// response.
	List(ctx context.Context, includeDeleted bool) ([]*Alert, error)
}

Store is the interface used to persist Alerts.

type SubKey

type SubKey struct {
	SubName     string
	SubRevision string
}

type WhatToInclude

type WhatToInclude bool
const (
	ReadAlertsTimeout   time.Duration = time.Minute
	IncludeDeleted      WhatToInclude = true
	DoNotIncludeDeleted WhatToInclude = false
)

Directories

Path Synopsis
Package sqlalertstore implements alerts.Store using SQL.
Package sqlalertstore implements alerts.Store using SQL.

Jump to

Keyboard shortcuts

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