slo

package
v0.63.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2023 License: MPL-2.0 Imports: 13 Imported by: 1

Documentation

Overview

Package slo defines SLO object definitions.

Index

Examples

Constants

View Source
const (
	LightstepMetricDataType     = "metric"
	LightstepLatencyDataType    = "latency"
	LightstepErrorRateDataType  = "error_rate"
	LightstepTotalCountDataType = "total"
	LightstepGoodCountDataType  = "good"
)
View Source
const (
	PingdomTypeUptime      = "uptime"
	PingdomTypeTransaction = "transaction"
)
View Source
const (
	ThousandEyesNetLatency              = "net-latency"
	ThousandEyesNetLoss                 = "net-loss"
	ThousandEyesWebPageLoad             = "web-page-load"
	ThousandEyesWebDOMLoad              = "web-dom-load"
	ThousandEyesHTTPResponseTime        = "http-response-time"
	ThousandEyesServerAvailability      = "http-server-availability"
	ThousandEyesServerThroughput        = "http-server-throughput"
	ThousandEyesServerTotalTime         = "http-server-total-time"
	ThousandEyesDNSServerResolutionTime = "dns-server-resolution-time"
	ThousandEyesDNSSECValid             = "dns-dnssec-valid"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AmazonPrometheusMetric

type AmazonPrometheusMetric struct {
	PromQL *string `json:"promql"`
}

AmazonPrometheusMetric represents metric from Amazon Managed Prometheus

type AnomalyConfig

type AnomalyConfig struct {
	NoData *AnomalyConfigNoData `json:"noData"`
}

AnomalyConfig represents relationship between anomaly type and selected notification methods. This will be removed (moved into Anomaly Policy) in PC-8502

type AnomalyConfigAlertMethod

type AnomalyConfigAlertMethod struct {
	Name    string `json:"name"`
	Project string `json:"project,omitempty"`
}

AnomalyConfigAlertMethod represents a single alert method used in AnomalyConfig defined by name and project.

type AnomalyConfigNoData

type AnomalyConfigNoData struct {
	AlertMethods []AnomalyConfigAlertMethod `json:"alertMethods"`
}

AnomalyConfigNoData contains alertMethods used for No Data anomaly type.

type AppDynamicsMetric

type AppDynamicsMetric struct {
	ApplicationName *string `json:"applicationName"`
	MetricPath      *string `json:"metricPath"`
}

AppDynamicsMetric represents metric from AppDynamics

type Attachment

type Attachment struct {
	URL         string  `json:"url"`
	DisplayName *string `json:"displayName,omitempty"`
}

Attachment represents user defined URL attached to SLO

type AzureMonitorMetric

type AzureMonitorMetric struct {
	ResourceID      string                        `json:"resourceId"`
	MetricName      string                        `json:"metricName"`
	Aggregation     string                        `json:"aggregation"`
	Dimensions      []AzureMonitorMetricDimension `json:"dimensions,omitempty"`
	MetricNamespace string                        `json:"metricNamespace,omitempty"`
}

AzureMonitorMetric represents metric from AzureMonitor

type AzureMonitorMetricDimension

type AzureMonitorMetricDimension struct {
	Name  *string `json:"name"`
	Value *string `json:"value"`
}

AzureMonitorMetricDimension represents name/value pair that is part of the identity of a metric.

type BigQueryMetric

type BigQueryMetric struct {
	Query     string `json:"query"`
	ProjectID string `json:"projectId"`
	Location  string `json:"location"`
}

BigQueryMetric represents metric from BigQuery

type BudgetingMethod

type BudgetingMethod int

BudgetingMethod indicates algorithm to calculate error budget

const (
	// BudgetingMethodOccurrences method uses ratio of counts of good events and total count of event
	BudgetingMethodOccurrences BudgetingMethod = iota + 1
	// BudgetingMethodTimeslices method uses ratio of good time slices vs. total time slices in a budgeting period
	BudgetingMethodTimeslices
)

func ParseBudgetingMethod

func ParseBudgetingMethod(value string) (BudgetingMethod, error)

func (BudgetingMethod) String

func (m BudgetingMethod) String() string

type Calendar

type Calendar struct {
	StartTime string `json:"startTime"`
	TimeZone  string `json:"timeZone"`
}

Calendar struct represents calendar time window

type CloudWatchMetric

type CloudWatchMetric struct {
	Region     *string                     `json:"region"`
	Namespace  *string                     `json:"namespace,omitempty"`
	MetricName *string                     `json:"metricName,omitempty"`
	Stat       *string                     `json:"stat,omitempty"`
	Dimensions []CloudWatchMetricDimension `json:"dimensions,omitempty"`
	AccountID  *string                     `json:"accountId,omitempty"`
	SQL        *string                     `json:"sql,omitempty"`
	JSON       *string                     `json:"json,omitempty"`
}

CloudWatchMetric represents metric from CloudWatch.

func (CloudWatchMetric) IsJSONConfiguration

func (c CloudWatchMetric) IsJSONConfiguration() bool

IsJSONConfiguration returns true if the struct represents CloudWatch JSON configuration.

func (CloudWatchMetric) IsSQLConfiguration

func (c CloudWatchMetric) IsSQLConfiguration() bool

IsSQLConfiguration returns true if the struct represents CloudWatch SQL configuration.

func (CloudWatchMetric) IsStandardConfiguration

func (c CloudWatchMetric) IsStandardConfiguration() bool

IsStandardConfiguration returns true if the struct represents CloudWatch standard configuration.

type CloudWatchMetricDimension

type CloudWatchMetricDimension struct {
	Name  *string `json:"name"`
	Value *string `json:"value"`
}

CloudWatchMetricDimension represents name/value pair that is part of the identity of a metric.

type Composite

type Composite struct {
	BudgetTarget      *float64                    `json:"target"`
	BurnRateCondition *CompositeBurnRateCondition `json:"burnRateCondition,omitempty"`
}

Composite represents configuration for Composite SLO.

type CompositeBurnRateCondition

type CompositeBurnRateCondition struct {
	Value    float64 `json:"value"`
	Operator string  `json:"op"`
}

CompositeBurnRateCondition represents configuration for Composite SLO with occurrences budgeting method.

type CompositeVersion

type CompositeVersion struct {
	Version      int32
	Created      string
	Dependencies []string
}

CompositeVersion represents composite version history stored for restoring process.

type CountMetricsSpec

type CountMetricsSpec struct {
	Incremental *bool       `json:"incremental"`
	GoodMetric  *MetricSpec `json:"good,omitempty"`
	BadMetric   *MetricSpec `json:"bad,omitempty"`
	TotalMetric *MetricSpec `json:"total"`
}

CountMetricsSpec represents set of two time series of good and total counts

type DatadogMetric

type DatadogMetric struct {
	Query *string `json:"query"`
}

DatadogMetric represents metric from Datadog

type DynatraceMetric

type DynatraceMetric struct {
	MetricSelector *string `json:"metricSelector"`
}

DynatraceMetric represents metric from Dynatrace.

type ElasticsearchMetric

type ElasticsearchMetric struct {
	Index *string `json:"index"`
	Query *string `json:"query"`
}

ElasticsearchMetric represents metric from Elasticsearch.

type GCMMetric

type GCMMetric struct {
	Query     string `json:"query"`
	ProjectID string `json:"projectId"`
}

GCMMetric represents metric from GCM

type GenericMetric

type GenericMetric struct {
	Query *string `json:"query"`
}

type GrafanaLokiMetric

type GrafanaLokiMetric struct {
	Logql *string `json:"logql"`
}

GrafanaLokiMetric represents metric from GrafanaLokiMetric.

type GraphiteMetric

type GraphiteMetric struct {
	MetricPath *string `json:"metricPath"`
}

GraphiteMetric represents metric from Graphite.

type HoneycombMetric

type HoneycombMetric struct {
	Dataset     string `json:"dataset"`
	Calculation string `json:"calculation"`
	Attribute   string `json:"attribute"`
}

HoneycombMetric represents metric from Honeycomb. To access this integration, contact support@nobl9.com.

type Indicator

type Indicator struct {
	MetricSource MetricSourceSpec `json:"metricSource"`
	RawMetric    *MetricSpec      `json:"rawMetric,omitempty"`
}

Indicator represents integration with metric source can be. e.g. Prometheus, Datadog, for internal usage

type InfluxDBMetric

type InfluxDBMetric struct {
	Query *string `json:"query"`
}

InfluxDBMetric represents metric from InfluxDB

type InstanaApplicationMetricGroupBy

type InstanaApplicationMetricGroupBy struct {
	Tag               string  `json:"tag"`
	TagEntity         string  `json:"tagEntity"`
	TagSecondLevelKey *string `json:"tagSecondLevelKey,omitempty"`
}

type InstanaApplicationMetricType

type InstanaApplicationMetricType struct {
	MetricID         string                          `json:"metricId"`
	Aggregation      string                          `json:"aggregation"`
	GroupBy          InstanaApplicationMetricGroupBy `json:"groupBy"`
	APIQuery         string                          `json:"apiQuery"`
	IncludeInternal  bool                            `json:"includeInternal,omitempty"`
	IncludeSynthetic bool                            `json:"includeSynthetic,omitempty"`
}

type InstanaInfrastructureMetricType

type InstanaInfrastructureMetricType struct {
	MetricRetrievalMethod string  `json:"metricRetrievalMethod"`
	Query                 *string `json:"query,omitempty"`
	SnapshotID            *string `json:"snapshotId,omitempty"`
	MetricID              string  `json:"metricId"`
	PluginID              string  `json:"pluginId"`
}

type InstanaMetric

type InstanaMetric struct {
	MetricType     string                           `json:"metricType"`
	Infrastructure *InstanaInfrastructureMetricType `json:"infrastructure,omitempty"`
	Application    *InstanaApplicationMetricType    `json:"application,omitempty"`
}

InstanaMetric represents metric from Redshift.

type LightstepMetric

type LightstepMetric struct {
	StreamID   *string  `json:"streamId,omitempty"`
	TypeOfData *string  `json:"typeOfData"`
	Percentile *float64 `json:"percentile,omitempty"`
	UQL        *string  `json:"uql,omitempty"`
}

LightstepMetric represents metric from Lightstep

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

Metadata provides identity information for SLO.

type MetricSourceSpec

type MetricSourceSpec struct {
	Name    string        `json:"name"`
	Project string        `json:"project,omitempty"`
	Kind    manifest.Kind `json:"kind,omitempty"`
}

type MetricSpec

type MetricSpec struct {
	Prometheus          *PrometheusMetric          `json:"prometheus,omitempty"`
	Datadog             *DatadogMetric             `json:"datadog,omitempty"`
	NewRelic            *NewRelicMetric            `json:"newRelic,omitempty"`
	AppDynamics         *AppDynamicsMetric         `json:"appDynamics,omitempty"`
	Splunk              *SplunkMetric              `json:"splunk,omitempty"`
	Lightstep           *LightstepMetric           `json:"lightstep,omitempty"`
	SplunkObservability *SplunkObservabilityMetric `json:"splunkObservability,omitempty"`
	Dynatrace           *DynatraceMetric           `json:"dynatrace,omitempty"`
	Elasticsearch       *ElasticsearchMetric       `json:"elasticsearch,omitempty"`
	ThousandEyes        *ThousandEyesMetric        `json:"thousandEyes,omitempty"`
	Graphite            *GraphiteMetric            `json:"graphite,omitempty"`
	BigQuery            *BigQueryMetric            `json:"bigQuery,omitempty"`
	OpenTSDB            *OpenTSDBMetric            `json:"opentsdb,omitempty"`
	GrafanaLoki         *GrafanaLokiMetric         `json:"grafanaLoki,omitempty"`
	CloudWatch          *CloudWatchMetric          `json:"cloudWatch,omitempty"`
	Pingdom             *PingdomMetric             `json:"pingdom,omitempty"`
	AmazonPrometheus    *AmazonPrometheusMetric    `json:"amazonPrometheus,omitempty"`
	Redshift            *RedshiftMetric            `json:"redshift,omitempty"`
	SumoLogic           *SumoLogicMetric           `json:"sumoLogic,omitempty"`
	Instana             *InstanaMetric             `json:"instana,omitempty"`
	InfluxDB            *InfluxDBMetric            `json:"influxdb,omitempty"`
	GCM                 *GCMMetric                 `json:"gcm,omitempty"`
	AzureMonitor        *AzureMonitorMetric        `json:"azureMonitor,omitempty"`
	Generic             *GenericMetric             `json:"generic,omitempty"`
	Honeycomb           *HoneycombMetric           `json:"honeycomb,omitempty"`
}

MetricSpec defines single time series obtained from data source

func (*MetricSpec) DataSourceType

func (m *MetricSpec) DataSourceType() v1alpha.DataSourceType

DataSourceType returns a type of data source.

func (*MetricSpec) Query

func (m *MetricSpec) Query() interface{}

Query returns interface containing metric query for this MetricSpec.

type NewRelicMetric

type NewRelicMetric struct {
	NRQL *string `json:"nrql"`
}

NewRelicMetric represents metric from NewRelic

type Objective

type Objective struct {
	ObjectiveBase `json:",inline"`
	// <!-- Go struct field and type names renaming budgetTarget to target has been postponed after GA as requested
	// in PC-1240. -->
	BudgetTarget    *float64          `json:"target"`
	TimeSliceTarget *float64          `json:"timeSliceTarget,omitempty"`
	CountMetrics    *CountMetricsSpec `json:"countMetrics,omitempty"`
	RawMetric       *RawMetricSpec    `json:"rawMetric,omitempty"`
	Operator        *string           `json:"op,omitempty"`
}

Objective represents single objective for SLO, for internal usage

func (Objective) GetBudgetTarget

func (o Objective) GetBudgetTarget() float64

func (*Objective) HasCountMetrics

func (o *Objective) HasCountMetrics() bool

HasCountMetrics returns true if Objective has count metrics.

func (*Objective) HasRawMetricQuery

func (o *Objective) HasRawMetricQuery() bool

HasRawMetricQuery returns true if Objective has raw metric with query set.

type ObjectiveBase

type ObjectiveBase struct {
	DisplayName string   `json:"displayName"`
	Value       *float64 `json:"value"`
	Name        string   `json:"name"`
	NameChanged bool     `json:"-"`
}

ObjectiveBase base structure representing an objective.

func (ObjectiveBase) GetValue

func (o ObjectiveBase) GetValue() float64

type OpenTSDBMetric

type OpenTSDBMetric struct {
	Query *string `json:"query"`
}

OpenTSDBMetric represents metric from OpenTSDB.

type Period

type Period struct {
	Begin string `json:"begin"`
	End   string `json:"end"`
}

Period represents period of time

type PingdomMetric

type PingdomMetric struct {
	CheckID   *string `json:"checkId"`
	CheckType *string `json:"checkType"`
	Status    *string `json:"status,omitempty"`
}

PingdomMetric represents metric from Pingdom.

type PrometheusMetric

type PrometheusMetric struct {
	PromQL *string `json:"promql"`
}

PrometheusMetric represents metric from Prometheus

type RawMetricSpec

type RawMetricSpec struct {
	MetricQuery *MetricSpec `json:"query"`
}

RawMetricSpec represents integration with a metric source for a particular objective.

type RedshiftMetric

type RedshiftMetric struct {
	Region       *string `json:"region"`
	ClusterID    *string `json:"clusterId"`
	DatabaseName *string `json:"databaseName"`
	Query        *string `json:"query"`
}

RedshiftMetric represents metric from Redshift.

type ReplayStatus

type ReplayStatus struct {
	Status    string `json:"status"`
	Unit      string `json:"unit"`
	Value     int    `json:"value"`
	StartTime string `json:"startTime,omitempty"`
}

type SLO

type SLO struct {
	APIVersion string        `json:"apiVersion"`
	Kind       manifest.Kind `json:"kind"`
	Metadata   Metadata      `json:"metadata"`
	Spec       Spec          `json:"spec"`
	Status     *Status       `json:"status,omitempty"`

	Organization   string `json:"organization,omitempty"`
	ManifestSource string `json:"manifestSrc,omitempty"`
}

SLO struct which mapped one to one with kind: slo yaml definition, external usage

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/slo"
)

func main() {
	// Create the object:
	mySLO := slo.New(
		slo.Metadata{
			Name:        "my-slo",
			DisplayName: "My SLO",
			Project:     "default",
			Labels: v1alpha.Labels{
				"team":   []string{"green", "orange"},
				"region": []string{"eu-central-1"},
			},
		},
		slo.Spec{
			Description:   "Example slo",
			AlertPolicies: []string{"my-policy-name"},
			Attachments: []slo.Attachment{
				{
					DisplayName: ptr("Grafana Dashboard"),
					URL:         "https://loki.my-org.dev/grafana/d/dnd48",
				},
			},
			BudgetingMethod: slo.BudgetingMethodOccurrences.String(),
			Service:         "prometheus",
			Indicator: slo.Indicator{
				MetricSource: slo.MetricSourceSpec{
					Name:    "prometheus",
					Project: "default",
					Kind:    manifest.KindAgent,
				},
			},
			Objectives: []slo.Objective{
				{
					ObjectiveBase: slo.ObjectiveBase{
						DisplayName: "Good",
						Value:       ptr(0.),
						Name:        "good",
					},
					BudgetTarget: ptr(0.9),
					CountMetrics: &slo.CountMetricsSpec{
						Incremental: ptr(false),
						GoodMetric: &slo.MetricSpec{
							Prometheus: &slo.PrometheusMetric{
								PromQL: ptr(`sum(rate(prometheus_http_requests_total{code=~"^2.*"}[1h]))`),
							},
						},
						TotalMetric: &slo.MetricSpec{
							Prometheus: &slo.PrometheusMetric{
								PromQL: ptr(`sum(rate(prometheus_http_requests_total[1h]))`),
							},
						},
					},
				},
			},
			TimeWindows: []slo.TimeWindow{
				{
					Unit:      "Day",
					Count:     1,
					IsRolling: true,
				},
			},
		},
	)
	// Verify the object:
	if err := mySLO.Validate(); err != nil {
		log.Fatal("slo validation failed, err: %w", err)
	}
	// Apply the object:
	client := examples.GetOfflineEchoClient()
	if err := client.ApplyObjects(context.Background(), []manifest.Object{mySLO}); err != nil {
		log.Fatal("failed to apply slo, err: %w", err)
	}
}

func ptr[T any](v T) *T { return &v }
Output:

apiVersion: n9/v1alpha
kind: SLO
metadata:
  name: my-slo
  displayName: My SLO
  project: default
  labels:
    region:
    - eu-central-1
    team:
    - green
    - orange
spec:
  description: Example slo
  indicator:
    metricSource:
      name: prometheus
      project: default
      kind: Agent
  budgetingMethod: Occurrences
  objectives:
  - displayName: Good
    value: 0.0
    name: good
    target: 0.9
    countMetrics:
      incremental: false
      good:
        prometheus:
          promql: sum(rate(prometheus_http_requests_total{code=~"^2.*"}[1h]))
      total:
        prometheus:
          promql: sum(rate(prometheus_http_requests_total[1h]))
  service: prometheus
  timeWindows:
  - unit: Day
    count: 1
    isRolling: true
  alertPolicies:
  - my-policy-name
  attachments:
  - url: https://loki.my-org.dev/grafana/d/dnd48
    displayName: Grafana Dashboard

func New

func New(metadata Metadata, spec Spec) SLO

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

func (SLO) GetKind

func (s SLO) GetKind() manifest.Kind

func (SLO) GetManifestSource

func (s SLO) GetManifestSource() string

func (SLO) GetName

func (s SLO) GetName() string

func (SLO) GetOrganization

func (s SLO) GetOrganization() string

func (SLO) GetProject

func (s SLO) GetProject() string

func (SLO) GetVersion

func (s SLO) GetVersion() string

func (SLO) SetManifestSource

func (s SLO) SetManifestSource(src string) manifest.Object

func (SLO) SetOrganization

func (s SLO) SetOrganization(org string) manifest.Object

func (SLO) SetProject

func (s SLO) SetProject(project string) manifest.Object

func (SLO) Validate

func (s SLO) Validate() error

type Spec

type Spec struct {
	Description     string         `json:"description"`
	Indicator       Indicator      `json:"indicator"`
	BudgetingMethod string         `json:"budgetingMethod"`
	Objectives      []Objective    `json:"objectives"`
	Service         string         `json:"service"`
	TimeWindows     []TimeWindow   `json:"timeWindows"`
	AlertPolicies   []string       `json:"alertPolicies"`
	Attachments     []Attachment   `json:"attachments,omitempty"`
	CreatedAt       string         `json:"createdAt,omitempty"`
	Composite       *Composite     `json:"composite,omitempty"`
	AnomalyConfig   *AnomalyConfig `json:"anomalyConfig,omitempty"`
}

Spec holds detailed information specific to SLO.

func (*Spec) AllMetricSpecs

func (s *Spec) AllMetricSpecs() []*MetricSpec

AllMetricSpecs returns slice of all metrics defined in SLO regardless of their type.

func (*Spec) CountMetricPairs

func (s *Spec) CountMetricPairs() []*CountMetricsSpec

CountMetricPairs returns a slice of all count metrics defined in this SLOSpec's objectives.

func (*Spec) CountMetrics

func (s *Spec) CountMetrics() []*MetricSpec

CountMetrics returns a flat slice of all count metrics defined in this SLOSpec's objectives.

func (*Spec) CountMetricsCount

func (s *Spec) CountMetricsCount() int

CountMetricsCount returns total number of all count metrics defined in this SLOSpec's objectives.

func (*Spec) GoodTotalCountMetrics

func (s *Spec) GoodTotalCountMetrics() (good, total []*MetricSpec)

func (*Spec) HasCountMetrics

func (s *Spec) HasCountMetrics() bool

HasCountMetrics returns true if SLOSpec has count metrics.

func (*Spec) HasRawMetric

func (s *Spec) HasRawMetric() bool

HasRawMetric returns true if SLOSpec has raw metric.

func (*Spec) IsComposite

func (s *Spec) IsComposite() bool

IsComposite returns true if SLOSpec contains composite type.

func (*Spec) ObjectivesRawMetricsCount

func (s *Spec) ObjectivesRawMetricsCount() int

ObjectivesRawMetricsCount returns total number of all raw metrics defined in this SLO Spec's objectives.

func (*Spec) RawMetrics

func (s *Spec) RawMetrics() []*MetricSpec

RawMetrics returns raw metric spec.

type SplunkMetric

type SplunkMetric struct {
	Query *string `json:"query"`
}

SplunkMetric represents metric from Splunk

type SplunkObservabilityMetric

type SplunkObservabilityMetric struct {
	Program *string `json:"program"`
}

SplunkObservabilityMetric represents metric from SplunkObservability

type Status

type Status struct {
	ReplayStatus *ReplayStatus `json:"timeTravel,omitempty"`
}

Status holds dynamic fields returned when the Service is fetched from Nobl9 platform. Status is not part of the static object definition.

type SumoLogicMetric

type SumoLogicMetric struct {
	Type         *string `json:"type"`
	Query        *string `json:"query"`
	Quantization *string `json:"quantization,omitempty"`
	Rollup       *string `json:"rollup,omitempty"`
}

SumoLogicMetric represents metric from Sumo Logic.

type ThousandEyesMetric

type ThousandEyesMetric struct {
	TestID   *int64  `json:"testID"`
	TestType *string `json:"testType"`
}

ThousandEyesMetric represents metric from ThousandEyes

type TimeWindow

type TimeWindow struct {
	Unit      string    `json:"unit"`
	Count     int       `json:"count"`
	IsRolling bool      `json:"isRolling"`
	Calendar  *Calendar `json:"calendar,omitempty"`

	// Period is only returned in `/get/slo` requests it is ignored for `/apply`
	Period *Period `json:"period,omitempty"`
}

TimeWindow represents content of time window

func (TimeWindow) GetType

func (tw TimeWindow) GetType() twindow.TimeWindowTypeEnum

GetType returns value of twindow.TimeWindowTypeEnum for given time window>

Jump to

Keyboard shortcuts

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