alert

package
v0.85.1-rc2 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2024 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package alert defines Alert object definitions.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alert

type Alert 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"`
}

Alert represents triggered 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/alert"
)

func main() {
	alertInstance := alert.New(
		alert.Metadata{
			Name:    "my-alert",
			Project: "default",
		},
		alert.Spec{
			AlertPolicy: alert.ObjectMetadata{
				Name:    "burn-rate-is-4x-immediately",
				Project: "alerting-test",
			},
			Service: alert.ObjectMetadata{
				Name:    "triggering-alerts-service",
				Project: "alerting-test",
			},
			SLO: alert.ObjectMetadata{
				Name:    "prometheus-rolling-timeslices-threshold",
				Project: "alerting-test",
			},
			Objective: alert.Objective{
				Name:        "ok",
				DisplayName: "ok",
				Value:       99,
			},
			Severity:           "Medium",
			Status:             "Triggered",
			TriggeredClockTime: "2022-01-16T00:28:05Z",
		},
	)
	// Apply the object:
	client := examples.GetOfflineEchoClient()
	if err := client.Objects().V1().Apply(context.Background(), []manifest.Object{alertInstance}); err != nil {
		log.Fatal("failed to apply alert err: %w", err)
	}
}
Output:

apiVersion: n9/v1alpha
kind: Alert
metadata:
  name: my-alert
  project: default
spec:
  alertPolicy:
    name: burn-rate-is-4x-immediately
    project: alerting-test
  slo:
    name: prometheus-rolling-timeslices-threshold
    project: alerting-test
  service:
    name: triggering-alerts-service
    project: alerting-test
  objective:
    value: 99.0
    name: ok
    displayName: ok
  severity: Medium
  status: Triggered
  triggeredMetricTime: ""
  triggeredClockTime: 2022-01-16T00:28:05Z
  coolDown: ""
  conditions: []

func New

func New(metadata Metadata, spec Spec) Alert

New creates a new Alert based on provided Metadata nad Spec.

func (Alert) GetKind

func (a Alert) GetKind() manifest.Kind

func (Alert) GetManifestSource

func (a Alert) GetManifestSource() string

func (Alert) GetName

func (a Alert) GetName() string

func (Alert) GetOrganization

func (a Alert) GetOrganization() string

func (Alert) GetProject

func (a Alert) GetProject() string

func (Alert) GetValidator added in v0.82.0

func (a Alert) GetValidator() govy.Validator[Alert]

func (Alert) GetVersion

func (a Alert) GetVersion() manifest.Version

func (Alert) SetManifestSource

func (a Alert) SetManifestSource(src string) manifest.Object

func (Alert) SetOrganization

func (a Alert) SetOrganization(org string) manifest.Object

func (Alert) SetProject

func (a Alert) SetProject(project string) manifest.Object

func (Alert) Validate

func (a Alert) Validate() error

type Condition

type Condition struct {
	Measurement      string           `json:"measurement"`
	Value            interface{}      `json:"value"`
	AlertingWindow   string           `json:"alertingWindow,omitempty"`
	LastsForDuration string           `json:"lastsFor,omitempty"`
	Operator         string           `json:"op,omitempty"`
	Status           *ConditionStatus `json:"status,omitempty"`
}

type ConditionStatus added in v0.82.0

type ConditionStatus struct {
	FirstMetMetricTime   string  `json:"firstMetMetricTime,omitempty"`
	LastMetMetricTime    *string `json:"lastMetMetricTime,omitempty"`
	LastForMetMetricTime *string `json:"lastsForMetMetricTime,omitempty"`
}

type Metadata

type Metadata struct {
	Name    string `json:"name" validate:"required,objectName"`
	Project string `json:"project,omitempty" validate:"objectName"`
}

type ObjectMetadata

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

type Objective

type Objective struct {
	Value       float64 `json:"value"`
	Name        string  `json:"name"`
	DisplayName string  `json:"displayName"`
}

type Spec

type Spec struct {
	AlertPolicy                 ObjectMetadata `json:"alertPolicy"`
	SLO                         ObjectMetadata `json:"slo"`
	Service                     ObjectMetadata `json:"service"`
	Objective                   Objective      `json:"objective"`
	Severity                    string         `json:"severity"`
	Status                      string         `json:"status"`
	TriggeredMetricTime         string         `json:"triggeredMetricTime"`
	TriggeredClockTime          string         `json:"triggeredClockTime"`
	ResolvedClockTime           *string        `json:"resolvedClockTime,omitempty"`
	ResolvedMetricTime          *string        `json:"resolvedMetricTime,omitempty"`
	CoolDown                    string         `json:"coolDown"`
	Conditions                  []Condition    `json:"conditions"`
	CoolDownStartedAtMetricTime *string        `json:"coolDownStartedAtMetricTime,omitempty"`
	ResolutionReason            *string        `json:"resolutionReason,omitempty"`
}

Spec represents content of Alert's Spec

Jump to

Keyboard shortcuts

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