Documentation ¶
Overview ¶
Package alertpolicy defines AlertPolicy object definitions and validation.
Index ¶
- func GetDefaultOperatorForMeasurement(measurement Measurement) (v1alpha.Operator, error)
- type AlertCondition
- type AlertMethodRef
- type AlertMethodRefMetadata
- type AlertPolicy
- func (a AlertPolicy) GetKind() manifest.Kind
- func (a AlertPolicy) GetManifestSource() string
- func (a AlertPolicy) GetName() string
- func (a AlertPolicy) GetOrganization() string
- func (a AlertPolicy) GetProject() string
- func (a AlertPolicy) GetValidator() validation.Validator[AlertPolicy]
- func (a AlertPolicy) GetVersion() manifest.Version
- func (a AlertPolicy) SetManifestSource(src string) manifest.Object
- func (a AlertPolicy) SetOrganization(org string) manifest.Object
- func (a AlertPolicy) SetProject(project string) manifest.Object
- func (a AlertPolicy) Validate() error
- type Measurement
- type Metadata
- type Severity
- type Spec
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetDefaultOperatorForMeasurement ¶ added in v0.82.0
func GetDefaultOperatorForMeasurement(measurement Measurement) (v1alpha.Operator, error)
GetDefaultOperatorForMeasurement returns the default operator when operator is undefined.
Types ¶
type AlertCondition ¶
type AlertCondition struct { Measurement string `json:"measurement"` Value interface{} `json:"value"` AlertingWindow string `json:"alertingWindow,omitempty"` LastsForDuration string `json:"lastsFor,omitempty"` Operator string `json:"op,omitempty"` }
AlertCondition represents a condition to meet to trigger an alert.
type AlertMethodRef ¶
type AlertMethodRef struct { Metadata AlertMethodRefMetadata `json:"metadata"` // contains filtered or unexported fields }
func (*AlertMethodRef) EmbedAlertMethodRef ¶
func (a *AlertMethodRef) EmbedAlertMethodRef(ref interface{})
EmbedAlertMethodRef sets AlertMethodRef to an arbitrary value. Deprecated: Temporary solution to keep backward compatibility to return AlertMethod details. These objects and their details will be dropped.
func (*AlertMethodRef) MarshalJSON ¶
func (a *AlertMethodRef) MarshalJSON() ([]byte, error)
type AlertMethodRefMetadata ¶
type AlertPolicy ¶
type AlertPolicy struct { APIVersion manifest.Version `json:"apiVersion"` Kind manifest.Kind `json:"kind"` Metadata Metadata `json:"metadata"` Spec Spec `json:"spec"` Organization string `json:"organization,omitempty"` ManifestSource string `json:"manifestSrc,omitempty"` }
AlertPolicy represents a set of conditions that can trigger an alert.
Example ¶
package main import ( "context" "log" "github.com/nobl9/nobl9-go/internal/examples" "github.com/nobl9/nobl9-go/manifest" "github.com/nobl9/nobl9-go/manifest/v1alpha" "github.com/nobl9/nobl9-go/manifest/v1alpha/alertpolicy" ) func main() { // Create the object: myAlertPolicy := alertpolicy.New( alertpolicy.Metadata{ Name: "my-alert-policy", DisplayName: "My Alert Policy", Project: "default", Labels: v1alpha.Labels{ "team": []string{"green", "orange"}, "region": []string{"eu-central-1"}, }, }, alertpolicy.Spec{ Description: "Example alert policy", Severity: alertpolicy.SeverityHigh.String(), CoolDownDuration: "5m", Conditions: []alertpolicy.AlertCondition{ { Measurement: alertpolicy.MeasurementBurnedBudget.String(), Value: 0.8, }, }, AlertMethods: []alertpolicy.AlertMethodRef{ { Metadata: alertpolicy.AlertMethodRefMetadata{ Name: "my-alert-method", Project: "my-project", }, }, }, }, ) // Verify the object: if err := myAlertPolicy.Validate(); err != nil { log.Fatalf("alert policy validation failed, err: %v", err) } // Apply the object: client := examples.GetOfflineEchoClient() if err := client.Objects().V1().Apply(context.Background(), []manifest.Object{myAlertPolicy}); err != nil { log.Fatalf("failed to apply alert policy, err: %v", err) } }
Output: apiVersion: n9/v1alpha kind: AlertPolicy metadata: name: my-alert-policy displayName: My Alert Policy project: default labels: region: - eu-central-1 team: - green - orange spec: description: Example alert policy severity: High coolDown: 5m conditions: - measurement: burnedBudget value: 0.8 alertMethods: - metadata: name: my-alert-method project: my-project
func New ¶
func New(metadata Metadata, spec Spec) AlertPolicy
func (AlertPolicy) GetKind ¶
func (a AlertPolicy) GetKind() manifest.Kind
func (AlertPolicy) GetManifestSource ¶
func (a AlertPolicy) GetManifestSource() string
func (AlertPolicy) GetName ¶
func (a AlertPolicy) GetName() string
func (AlertPolicy) GetOrganization ¶
func (a AlertPolicy) GetOrganization() string
func (AlertPolicy) GetProject ¶
func (a AlertPolicy) GetProject() string
func (AlertPolicy) GetValidator ¶ added in v0.82.0
func (a AlertPolicy) GetValidator() validation.Validator[AlertPolicy]
func (AlertPolicy) GetVersion ¶
func (a AlertPolicy) GetVersion() manifest.Version
func (AlertPolicy) SetManifestSource ¶
func (a AlertPolicy) SetManifestSource(src string) manifest.Object
func (AlertPolicy) SetOrganization ¶
func (a AlertPolicy) SetOrganization(org string) manifest.Object
func (AlertPolicy) SetProject ¶
func (a AlertPolicy) SetProject(project string) manifest.Object
func (AlertPolicy) Validate ¶
func (a AlertPolicy) Validate() error
type Measurement ¶
type Measurement int16
Measurement is allowed measurement types used for comparing values and triggering alerts
const ( MeasurementBurnedBudget Measurement = iota + 1 MeasurementAverageBurnRate MeasurementTimeToBurnBudget MeasurementTimeToBurnEntireBudget )
func ParseMeasurement ¶
func ParseMeasurement(value string) (Measurement, error)
ParseMeasurement parses string to Measurement
func (Measurement) String ¶
func (m Measurement) String() string
type Severity ¶
type Severity int16
Severity level describe importance of triggered alert
func ParseSeverity ¶
ParseSeverity parses string to Severity
type Spec ¶
type Spec struct { Description string `json:"description"` Severity string `json:"severity"` CoolDownDuration string `json:"coolDown,omitempty"` Conditions []AlertCondition `json:"conditions"` AlertMethods []AlertMethodRef `json:"alertMethods"` }
Spec represents content of AlertPolicy's Spec.
func (Spec) GetAlertMethods ¶
func (spec Spec) GetAlertMethods() []AlertMethodRef