alertpolicy

package
v0.79.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: MPL-2.0 Imports: 8 Imported by: 1

Documentation

Overview

Package alertpolicy defines AlertPolicy object definitions and validation.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetExpectedOperatorForMeasurement

func GetExpectedOperatorForMeasurement(measurement Measurement) (v1alpha.Operator, error)

GetExpectedOperatorForMeasurement returns the operator that should be paired with a given measurement.

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 AlertMethodRefMetadata struct {
	Name    string `json:"name"`
	Project string `json:"project,omitempty"`
}

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) 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 Metadata

type Metadata struct {
	Name        string         `json:"name"`
	DisplayName string         `json:"displayName,omitempty"`
	Project     string         `json:"project,omitempty"`
	Labels      v1alpha.Labels `json:"labels,omitempty"`
}

type Severity

type Severity int16

Severity level describe importance of triggered alert

const (
	SeverityLow Severity = iota + 1
	SeverityMedium
	SeverityHigh
)

func ParseSeverity

func ParseSeverity(value string) (Severity, error)

ParseSeverity parses string to Severity

func (Severity) String

func (m Severity) String() string

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

Jump to

Keyboard shortcuts

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