Documentation
¶
Overview ¶
Package v1 contains the OpenSLO specification version v1alpha definitions.
Index ¶
- Constants
- func GetSupportedKinds() []openslo.Kind
- type AlertCondition
- func (a AlertCondition) GetKind() openslo.Kind
- func (a AlertCondition) GetMetadata() Metadata
- func (a AlertCondition) GetName() string
- func (a AlertCondition) GetValidator() govy.Validator[AlertCondition]
- func (a AlertCondition) GetVersion() openslo.Version
- func (a AlertCondition) String() string
- func (a AlertCondition) Validate() error
- type AlertConditionKind
- type AlertConditionSpec
- type AlertConditionType
- type AlertNotificationTarget
- func (a AlertNotificationTarget) GetKind() openslo.Kind
- func (a AlertNotificationTarget) GetMetadata() Metadata
- func (a AlertNotificationTarget) GetName() string
- func (a AlertNotificationTarget) GetValidator() govy.Validator[AlertNotificationTarget]
- func (a AlertNotificationTarget) GetVersion() openslo.Version
- func (a AlertNotificationTarget) String() string
- func (a AlertNotificationTarget) Validate() error
- type AlertNotificationTargetSpec
- type AlertPolicy
- func (a AlertPolicy) GetKind() openslo.Kind
- func (a AlertPolicy) GetMetadata() Metadata
- func (a AlertPolicy) GetName() string
- func (a AlertPolicy) GetValidator() govy.Validator[AlertPolicy]
- func (a AlertPolicy) GetVersion() openslo.Version
- func (a AlertPolicy) String() string
- func (a AlertPolicy) Validate() error
- type AlertPolicyCondition
- type AlertPolicyConditionInline
- type AlertPolicyConditionRef
- type AlertPolicyNotificationTarget
- type AlertPolicyNotificationTargetInline
- type AlertPolicyNotificationTargetRef
- type AlertPolicySpec
- type Annotations
- type DataSource
- func (d DataSource) GetKind() openslo.Kind
- func (d DataSource) GetMetadata() Metadata
- func (d DataSource) GetName() string
- func (d DataSource) GetValidator() govy.Validator[DataSource]
- func (d DataSource) GetVersion() openslo.Version
- func (d DataSource) String() string
- func (d DataSource) Validate() error
- type DataSourceSpec
- type DurationShorthand
- func (d DurationShorthand) Duration() time.Duration
- func (d *DurationShorthand) GetUnit() DurationShorthandUnit
- func (d *DurationShorthand) GetValue() int
- func (d DurationShorthand) MarshalText() ([]byte, error)
- func (d DurationShorthand) String() string
- func (d *DurationShorthand) UnmarshalText(text []byte) error
- func (d DurationShorthand) Validate() error
- type DurationShorthandUnit
- type Label
- type Labels
- type Metadata
- type Object
- type Operator
- type SLI
- type SLIMetricSource
- type SLIMetricSpec
- type SLIRatioMetric
- type SLIRawMetricType
- type SLISpec
- type SLO
- type SLOAlertPolicy
- type SLOAlertPolicyInline
- type SLOAlertPolicyRef
- type SLOBudgetingMethod
- type SLOCalendar
- type SLOIndicatorInline
- type SLOObjective
- type SLOSpec
- type SLOTimeWindow
- type Service
- type ServiceSpec
Examples ¶
Constants ¶
const APIVersion = openslo.VersionV1
Variables ¶
This section is empty.
Functions ¶
func GetSupportedKinds ¶
Types ¶
type AlertCondition ¶
type AlertCondition struct {
APIVersion openslo.Version `json:"apiVersion"`
Kind openslo.Kind `json:"kind"`
Metadata Metadata `json:"metadata"`
Spec AlertConditionSpec `json:"spec"`
}
Example ¶
package main
import (
"bytes"
"os"
"reflect"
v1 "github.com/OpenSLO/go-sdk/pkg/openslo/v1"
"github.com/OpenSLO/go-sdk/pkg/openslosdk"
)
func main() {
// Raw AlertCondition object in YAML format.
const alertConditionYAML = `
- apiVersion: openslo/v1
kind: AlertCondition
metadata:
name: cpu-usage-breach
displayName: CPU usage breach
labels:
env:
- prod
team:
- team-a
- team-b
spec:
description: If the CPU usage is too high for given period then it should alert
severity: page
condition:
kind: burnrate
op: lte
threshold: 2
lookbackWindow: 1h
alertAfter: 5m
`
// Define AlertCondition programmatically.
condition := v1.NewAlertCondition(
v1.Metadata{
Name: "cpu-usage-breach",
DisplayName: "CPU usage breach",
Labels: v1.Labels{
"team": {"team-a", "team-b"},
"env": {"prod"},
},
},
v1.AlertConditionSpec{
Severity: "page",
Condition: v1.AlertConditionType{
Kind: v1.AlertConditionKindBurnRate,
Operator: v1.OperatorLTE,
Threshold: ptr(2.0),
LookbackWindow: v1.NewDurationShorthand(1, v1.DurationShorthandUnitHour),
AlertAfter: ptr(v1.NewDurationShorthand(5, v1.DurationShorthandUnitMinute)),
},
Description: "If the CPU usage is too high for given period then it should alert",
},
)
// Read the raw AlertCondition object.
objects, err := openslosdk.Decode(bytes.NewBufferString(alertConditionYAML), openslosdk.FormatYAML)
if err != nil {
panic(err)
}
// Compare the raw AlertCondition object with the programmatically defined AlertCondition object.
if !reflect.DeepEqual(objects[0], condition) {
panic("AlertCondition objects are not equal!")
}
// Validate the AlertCondition object.
if err = condition.Validate(); err != nil {
panic(err)
}
// Encode the AlertCondition object to YAML and write it to stdout.
if err = openslosdk.Encode(os.Stdout, openslosdk.FormatYAML, condition); err != nil {
panic(err)
}
}
func ptr[T any](v T) *T { return &v }
Output: - apiVersion: openslo/v1 kind: AlertCondition metadata: displayName: CPU usage breach labels: env: - prod team: - team-a - team-b name: cpu-usage-breach spec: condition: alertAfter: 5m kind: burnrate lookbackWindow: 1h op: lte threshold: 2 description: If the CPU usage is too high for given period then it should alert severity: page
func NewAlertCondition ¶
func NewAlertCondition(metadata Metadata, spec AlertConditionSpec) AlertCondition
func (AlertCondition) GetKind ¶
func (a AlertCondition) GetKind() openslo.Kind
func (AlertCondition) GetMetadata ¶ added in v0.6.0
func (a AlertCondition) GetMetadata() Metadata
func (AlertCondition) GetName ¶
func (a AlertCondition) GetName() string
func (AlertCondition) GetValidator ¶ added in v0.7.0
func (a AlertCondition) GetValidator() govy.Validator[AlertCondition]
func (AlertCondition) GetVersion ¶
func (a AlertCondition) GetVersion() openslo.Version
func (AlertCondition) String ¶ added in v0.4.0
func (a AlertCondition) String() string
func (AlertCondition) Validate ¶
func (a AlertCondition) Validate() error
type AlertConditionKind ¶
type AlertConditionKind string
const (
AlertConditionKindBurnRate AlertConditionKind = "burnrate"
)
type AlertConditionSpec ¶
type AlertConditionSpec struct {
Severity string `json:"severity"`
Condition AlertConditionType `json:"condition"`
Description string `json:"description,omitempty"`
}
type AlertConditionType ¶
type AlertConditionType struct {
Kind AlertConditionKind `json:"kind"`
Operator Operator `json:"op"`
Threshold *float64 `json:"threshold"`
LookbackWindow DurationShorthand `json:"lookbackWindow"`
AlertAfter *DurationShorthand `json:"alertAfter,omitempty"`
}
type AlertNotificationTarget ¶
type AlertNotificationTarget struct {
APIVersion openslo.Version `json:"apiVersion"`
Kind openslo.Kind `json:"kind"`
Metadata Metadata `json:"metadata"`
Spec AlertNotificationTargetSpec `json:"spec"`
}
Example ¶
package main
import (
"bytes"
"os"
"reflect"
v1 "github.com/OpenSLO/go-sdk/pkg/openslo/v1"
"github.com/OpenSLO/go-sdk/pkg/openslosdk"
)
func main() {
// Raw AlertNotificationTarget object in YAML format.
const targetYAML = `
- apiVersion: openslo/v1
kind: AlertNotificationTarget
metadata:
labels:
env:
- prod
team:
- on-call
name: pd-on-call-notification
spec:
description: Sends PagerDuty alert to the current on-call
target: pagerduty
`
// Define AlertNotificationTarget programmatically.
target := v1.NewAlertNotificationTarget(
v1.Metadata{
Name: "pd-on-call-notification",
Labels: v1.Labels{
"team": {"on-call"},
"env": {"prod"},
},
},
v1.AlertNotificationTargetSpec{
Description: "Sends PagerDuty alert to the current on-call",
Target: "pagerduty",
},
)
// Read the raw AlertNotificationTarget object.
objects, err := openslosdk.Decode(bytes.NewBufferString(targetYAML), openslosdk.FormatYAML)
if err != nil {
panic(err)
}
// Compare the raw AlertNotificationTarget object with the programmatically defined AlertNotificationTarget object.
if !reflect.DeepEqual(objects[0], target) {
panic("AlertNotificationTarget objects are not equal!")
}
// Validate the AlertNotificationTarget object.
if err = target.Validate(); err != nil {
panic(err)
}
// Encode the AlertNotificationTarget object to YAML and write it to stdout.
if err = openslosdk.Encode(os.Stdout, openslosdk.FormatYAML, target); err != nil {
panic(err)
}
}
Output: - apiVersion: openslo/v1 kind: AlertNotificationTarget metadata: labels: env: - prod team: - on-call name: pd-on-call-notification spec: description: Sends PagerDuty alert to the current on-call target: pagerduty
func NewAlertNotificationTarget ¶
func NewAlertNotificationTarget(metadata Metadata, spec AlertNotificationTargetSpec) AlertNotificationTarget
func (AlertNotificationTarget) GetKind ¶
func (a AlertNotificationTarget) GetKind() openslo.Kind
func (AlertNotificationTarget) GetMetadata ¶ added in v0.6.0
func (a AlertNotificationTarget) GetMetadata() Metadata
func (AlertNotificationTarget) GetName ¶
func (a AlertNotificationTarget) GetName() string
func (AlertNotificationTarget) GetValidator ¶ added in v0.7.0
func (a AlertNotificationTarget) GetValidator() govy.Validator[AlertNotificationTarget]
func (AlertNotificationTarget) GetVersion ¶
func (a AlertNotificationTarget) GetVersion() openslo.Version
func (AlertNotificationTarget) String ¶ added in v0.4.0
func (a AlertNotificationTarget) String() string
func (AlertNotificationTarget) Validate ¶
func (a AlertNotificationTarget) Validate() error
type AlertPolicy ¶
type AlertPolicy struct {
APIVersion openslo.Version `json:"apiVersion"`
Kind openslo.Kind `json:"kind"`
Metadata Metadata `json:"metadata"`
Spec AlertPolicySpec `json:"spec"`
}
Example ¶
package main
import (
"bytes"
"os"
"reflect"
v1 "github.com/OpenSLO/go-sdk/pkg/openslo/v1"
"github.com/OpenSLO/go-sdk/pkg/openslosdk"
)
func main() {
// Raw AlertPolicy object in YAML format.
const alertPolicyYAML = `
- apiVersion: openslo/v1
kind: AlertPolicy
metadata:
name: low-priority
displayName: Low Priority
labels:
env:
- prod
team:
- team-a
- team-b
spec:
description: Alert policy for low priority notifications which notifies on-call via email
alertWhenBreaching: true
conditions:
- conditionRef: cpu-usage-breach
notificationTargets:
- targetRef: on-call-mail-notification
`
// Define AlertPolicy programmatically.
policy := v1.NewAlertPolicy(
v1.Metadata{
Name: "low-priority",
DisplayName: "Low Priority",
Labels: v1.Labels{
"team": {"team-a", "team-b"},
"env": {"prod"},
},
},
v1.AlertPolicySpec{
Description: "Alert policy for low priority notifications which notifies on-call via email",
AlertWhenBreaching: true,
Conditions: []v1.AlertPolicyCondition{
{
AlertPolicyConditionRef: &v1.AlertPolicyConditionRef{
ConditionRef: "cpu-usage-breach",
},
},
},
NotificationTargets: []v1.AlertPolicyNotificationTarget{
{
AlertPolicyNotificationTargetRef: &v1.AlertPolicyNotificationTargetRef{
TargetRef: "on-call-mail-notification",
},
},
},
},
)
// Read the raw AlertPolicy object.
objects, err := openslosdk.Decode(bytes.NewBufferString(alertPolicyYAML), openslosdk.FormatYAML)
if err != nil {
panic(err)
}
// Compare the raw AlertPolicy object with the programmatically defined AlertPolicy object.
if !reflect.DeepEqual(objects[0], policy) {
panic("AlertPolicy objects are not equal!")
}
// Validate the AlertPolicy object.
if err := policy.Validate(); err != nil {
panic(err)
}
// Encode the AlertPolicy object to YAML and write it to stdout.
if err := openslosdk.Encode(os.Stdout, openslosdk.FormatYAML, policy); err != nil {
panic(err)
}
}
Output: - apiVersion: openslo/v1 kind: AlertPolicy metadata: displayName: Low Priority labels: env: - prod team: - team-a - team-b name: low-priority spec: alertWhenBreaching: true conditions: - conditionRef: cpu-usage-breach description: Alert policy for low priority notifications which notifies on-call via email notificationTargets: - targetRef: on-call-mail-notification
func NewAlertPolicy ¶
func NewAlertPolicy(metadata Metadata, spec AlertPolicySpec) AlertPolicy
func (AlertPolicy) GetKind ¶
func (a AlertPolicy) GetKind() openslo.Kind
func (AlertPolicy) GetMetadata ¶ added in v0.6.0
func (a AlertPolicy) GetMetadata() Metadata
func (AlertPolicy) GetName ¶
func (a AlertPolicy) GetName() string
func (AlertPolicy) GetValidator ¶ added in v0.7.0
func (a AlertPolicy) GetValidator() govy.Validator[AlertPolicy]
func (AlertPolicy) GetVersion ¶
func (a AlertPolicy) GetVersion() openslo.Version
func (AlertPolicy) String ¶ added in v0.4.0
func (a AlertPolicy) String() string
func (AlertPolicy) Validate ¶
func (a AlertPolicy) Validate() error
type AlertPolicyCondition ¶
type AlertPolicyCondition struct {
*AlertPolicyConditionRef
*AlertPolicyConditionInline
}
type AlertPolicyConditionInline ¶
type AlertPolicyConditionInline struct {
Kind openslo.Kind `json:"kind"`
Metadata Metadata `json:"metadata"`
Spec AlertConditionSpec `json:"spec"`
}
type AlertPolicyConditionRef ¶
type AlertPolicyConditionRef struct {
ConditionRef string `json:"conditionRef"`
}
type AlertPolicyNotificationTarget ¶
type AlertPolicyNotificationTarget struct {
*AlertPolicyNotificationTargetRef
*AlertPolicyNotificationTargetInline
}
type AlertPolicyNotificationTargetInline ¶
type AlertPolicyNotificationTargetInline struct {
Kind openslo.Kind `json:"kind"`
Metadata Metadata `json:"metadata"`
Spec AlertNotificationTargetSpec `json:"spec"`
}
type AlertPolicyNotificationTargetRef ¶
type AlertPolicyNotificationTargetRef struct {
TargetRef string `json:"targetRef"`
}
type AlertPolicySpec ¶
type AlertPolicySpec struct {
Description string `json:"description,omitempty"`
AlertWhenNoData bool `json:"alertWhenNoData,omitempty"`
AlertWhenBreaching bool `json:"alertWhenBreaching,omitempty"`
AlertWhenResolved bool `json:"alertWhenResolved,omitempty"`
Conditions []AlertPolicyCondition `json:"conditions,omitempty"`
NotificationTargets []AlertPolicyNotificationTarget `json:"notificationTargets,omitempty"`
}
type Annotations ¶
type DataSource ¶
type DataSource struct {
APIVersion openslo.Version `json:"apiVersion"`
Kind openslo.Kind `json:"kind"`
Metadata Metadata `json:"metadata"`
Spec DataSourceSpec `json:"spec"`
}
Example ¶
package main
import (
"bytes"
"os"
"reflect"
v1 "github.com/OpenSLO/go-sdk/pkg/openslo/v1"
"github.com/OpenSLO/go-sdk/pkg/openslosdk"
)
func main() {
// Raw DataSource object in YAML format.
const dataSourceYAML = `
- apiVersion: openslo/v1
kind: DataSource
metadata:
labels:
env:
- prod
team:
- team-a
- team-b
name: prometheus
spec:
description: Production Prometheus
connectionDetails:
- url: http://prometheus.example.com
type: Prometheus
`
// Define DataSource programmatically.
dataSource := v1.NewDataSource(
v1.Metadata{
Name: "prometheus",
Labels: v1.Labels{
"team": {"team-a", "team-b"},
"env": {"prod"},
},
},
v1.DataSourceSpec{
Description: "Production Prometheus",
Type: "Prometheus",
ConnectionDetails: []byte(`[{"url":"http://prometheus.example.com"}]`),
},
)
// Read the raw DataSource object.
objects, err := openslosdk.Decode(bytes.NewBufferString(dataSourceYAML), openslosdk.FormatYAML)
if err != nil {
panic(err)
}
// Compare the raw DataSource object with the programmatically defined DataSource object.
if !reflect.DeepEqual(objects[0], dataSource) {
panic("DataSource objects are not equal!")
}
// Validate the DataSource object.
if err = dataSource.Validate(); err != nil {
panic(err)
}
// Encode the DataSource object to YAML and write it to stdout.
if err = openslosdk.Encode(os.Stdout, openslosdk.FormatYAML, dataSource); err != nil {
panic(err)
}
}
Output: - apiVersion: openslo/v1 kind: DataSource metadata: labels: env: - prod team: - team-a - team-b name: prometheus spec: connectionDetails: - url: http://prometheus.example.com description: Production Prometheus type: Prometheus
func NewDataSource ¶
func NewDataSource(metadata Metadata, spec DataSourceSpec) DataSource
func (DataSource) GetKind ¶
func (d DataSource) GetKind() openslo.Kind
func (DataSource) GetMetadata ¶ added in v0.6.0
func (d DataSource) GetMetadata() Metadata
func (DataSource) GetName ¶
func (d DataSource) GetName() string
func (DataSource) GetValidator ¶ added in v0.7.0
func (d DataSource) GetValidator() govy.Validator[DataSource]
func (DataSource) GetVersion ¶
func (d DataSource) GetVersion() openslo.Version
func (DataSource) String ¶ added in v0.4.0
func (d DataSource) String() string
func (DataSource) Validate ¶
func (d DataSource) Validate() error
type DataSourceSpec ¶
type DataSourceSpec struct {
Description string `json:"description,omitempty"`
Type string `json:"type"`
ConnectionDetails json.RawMessage `json:"connectionDetails"`
}
type DurationShorthand ¶
type DurationShorthand struct {
// contains filtered or unexported fields
}
DurationShorthand is a shorthand representation of time duration. It consists of a value and unit, e.g. '1m' (1 minute), '10d' (10 days).
func NewDurationShorthand ¶
func NewDurationShorthand(value int, unit DurationShorthandUnit) DurationShorthand
NewDurationShorthand creates a new DurationShorthand instance.
func ParseDurationShorthand ¶
func ParseDurationShorthand(s string) (DurationShorthand, error)
ParseDurationShorthand parses a string representation of DurationShorthand.
func (DurationShorthand) Duration ¶
func (d DurationShorthand) Duration() time.Duration
Duration returns the time.Duration representation of DurationShorthand.
func (*DurationShorthand) GetUnit ¶ added in v0.2.0
func (d *DurationShorthand) GetUnit() DurationShorthandUnit
GetUnit returns the underlying DurationShorthandUnit. Example:
duration, _ := ParseDurationShorthand("1w")
duration.GetUnit() -> "w"
func (*DurationShorthand) GetValue ¶ added in v0.2.0
func (d *DurationShorthand) GetValue() int
GetValue returns the underlying duration value. Example:
duration, _ := ParseDurationShorthand("12w")
duration.GetValue() -> "12"
func (DurationShorthand) MarshalText ¶
func (d DurationShorthand) MarshalText() ([]byte, error)
MarshalText implements encoding.TextMarshaler.
func (DurationShorthand) String ¶
func (d DurationShorthand) String() string
String implements fmt.Stringer.
func (*DurationShorthand) UnmarshalText ¶
func (d *DurationShorthand) UnmarshalText(text []byte) error
UnmarshalText implements encoding.TextUnmarshaler.
func (DurationShorthand) Validate ¶
func (d DurationShorthand) Validate() error
Validate checks if DurationShorthand is correct.
type DurationShorthandUnit ¶
type DurationShorthandUnit string
DurationShorthandUnit is a unit of DurationShorthand.
const ( DurationShorthandUnitMinute DurationShorthandUnit = "m" DurationShorthandUnitHour DurationShorthandUnit = "h" DurationShorthandUnitDay DurationShorthandUnit = "d" DurationShorthandUnitWeek DurationShorthandUnit = "w" DurationShorthandUnitMonth DurationShorthandUnit = "M" DurationShorthandUnitQuarter DurationShorthandUnit = "Q" DurationShorthandUnitYear DurationShorthandUnit = "Y" )
type Metadata ¶
type Metadata struct {
Name string `json:"name"`
DisplayName string `json:"displayName,omitempty"`
Labels Labels `json:"labels,omitempty"`
Annotations Annotations `json:"annotations,omitempty"`
}
type SLI ¶
type SLI struct {
APIVersion openslo.Version `json:"apiVersion"`
Kind openslo.Kind `json:"kind"`
Metadata Metadata `json:"metadata"`
Spec SLISpec `json:"spec"`
}
Example ¶
package main
import (
"bytes"
"os"
"reflect"
v1 "github.com/OpenSLO/go-sdk/pkg/openslo/v1"
"github.com/OpenSLO/go-sdk/pkg/openslosdk"
)
func main() {
// Raw SLI object in YAML format.
const sliYAML = `
- apiVersion: openslo/v1
kind: SLI
metadata:
displayName: Searching availability
labels:
env:
- prod
team:
- team-a
- team-b
name: search-availability
spec:
description: X% of search requests are successful
ratioMetric:
counter: true
good:
metricSource:
metricSourceRef: my-datadog
spec:
query: sum:trace.http.request.hits.by_http_status{http.status_code:200}.as_count()
type: Datadog
total:
metricSource:
metricSourceRef: my-datadog
spec:
query: sum:trace.http.request.hits.by_http_status{*}.as_count()
type: Datadog
`
// Define SLI programmatically.
sli := v1.NewSLI(
v1.Metadata{
Name: "search-availability",
DisplayName: "Searching availability",
Labels: v1.Labels{
"team": {"team-a", "team-b"},
"env": {"prod"},
},
},
v1.SLISpec{
Description: "X% of search requests are successful",
RatioMetric: &v1.SLIRatioMetric{
Counter: true,
Good: &v1.SLIMetricSpec{
MetricSource: v1.SLIMetricSource{
MetricSourceRef: "my-datadog",
Type: "Datadog",
Spec: map[string]interface{}{
"query": "sum:trace.http.request.hits.by_http_status{http.status_code:200}.as_count()",
},
},
},
Total: &v1.SLIMetricSpec{
MetricSource: v1.SLIMetricSource{
MetricSourceRef: "my-datadog",
Type: "Datadog",
Spec: map[string]interface{}{
"query": "sum:trace.http.request.hits.by_http_status{*}.as_count()",
},
},
},
},
},
)
// Read the raw SLI object.
objects, err := openslosdk.Decode(bytes.NewBufferString(sliYAML), openslosdk.FormatYAML)
if err != nil {
panic(err)
}
// Compare the raw SLI object with the programmatically defined SLI object.
if !reflect.DeepEqual(objects[0], sli) {
panic("SLI objects are not equal!")
}
// Validate the SLI object.
if err = sli.Validate(); err != nil {
panic(err)
}
// Encode the SLI object to YAML and write it to stdout.
if err = openslosdk.Encode(os.Stdout, openslosdk.FormatYAML, sli); err != nil {
panic(err)
}
}
Output: - apiVersion: openslo/v1 kind: SLI metadata: displayName: Searching availability labels: env: - prod team: - team-a - team-b name: search-availability spec: description: X% of search requests are successful ratioMetric: counter: true good: metricSource: metricSourceRef: my-datadog spec: query: sum:trace.http.request.hits.by_http_status{http.status_code:200}.as_count() type: Datadog total: metricSource: metricSourceRef: my-datadog spec: query: sum:trace.http.request.hits.by_http_status{*}.as_count() type: Datadog
func (SLI) GetMetadata ¶ added in v0.6.0
func (SLI) GetVersion ¶
type SLIMetricSource ¶
type SLIMetricSpec ¶
type SLIMetricSpec struct {
MetricSource SLIMetricSource `json:"metricSource"`
}
type SLIRatioMetric ¶
type SLIRatioMetric struct {
Counter bool `json:"counter"`
Good *SLIMetricSpec `json:"good,omitempty"`
Bad *SLIMetricSpec `json:"bad,omitempty"`
Total *SLIMetricSpec `json:"total,omitempty"`
RawType SLIRawMetricType `json:"rawType,omitempty"`
Raw *SLIMetricSpec `json:"raw,omitempty"`
}
type SLIRawMetricType ¶
type SLIRawMetricType string
const ( SLIRawMetricTypeSuccess SLIRawMetricType = "success" SLIRawMetricTypeFailure SLIRawMetricType = "failure" )
type SLISpec ¶
type SLISpec struct {
Description string `json:"description,omitempty"`
ThresholdMetric *SLIMetricSpec `json:"thresholdMetric,omitempty"`
RatioMetric *SLIRatioMetric `json:"ratioMetric,omitempty"`
}
type SLO ¶
type SLO struct {
APIVersion openslo.Version `json:"apiVersion"`
Kind openslo.Kind `json:"kind"`
Metadata Metadata `json:"metadata"`
Spec SLOSpec `json:"spec"`
}
Example ¶
// Raw SLO object in YAML format.
const sloYAML = `
- apiVersion: openslo/v1
kind: SLO
metadata:
name: web-availability
displayName: SLO for web availability
labels:
env:
- prod
team:
- team-a
- team-b
spec:
description: X% of search requests are successful
service: web
indicator:
metadata:
name: web-successful-requests-ratio
spec:
ratioMetric:
counter: true
good:
metricSource:
type: Prometheus
spec:
query: sum(http_requests{k8s_cluster="prod",component="web",code=~"2xx|4xx"})
total:
metricSource:
type: Prometheus
spec:
query: sum(http_requests{k8s_cluster="prod",component="web"})
timeWindow:
- duration: 1w
isRolling: false
calendar:
startTime: 2022-01-01 12:00:00
timeZone: America/New_York
budgetingMethod: Timeslices
objectives:
- displayName: Good
target: 0.995
timeSliceTarget: 0.95
timeSliceWindow: 1m
`
// Define SLO programmatically.
slo := v1.NewSLO(
v1.Metadata{
Name: "web-availability",
DisplayName: "SLO for web availability",
Labels: v1.Labels{
"team": {"team-a", "team-b"},
"env": {"prod"},
},
},
v1.SLOSpec{
Description: "X% of search requests are successful",
Service: "web",
Indicator: &v1.SLOIndicatorInline{
Metadata: v1.Metadata{
Name: "web-successful-requests-ratio",
},
Spec: v1.SLISpec{
RatioMetric: &v1.SLIRatioMetric{
Counter: true,
Good: &v1.SLIMetricSpec{
MetricSource: v1.SLIMetricSource{
Type: "Prometheus",
Spec: map[string]any{
"query": `sum(http_requests{k8s_cluster="prod",component="web",code=~"2xx|4xx"})`,
},
},
},
Total: &v1.SLIMetricSpec{
MetricSource: v1.SLIMetricSource{
Type: "Prometheus",
Spec: map[string]any{
"query": `sum(http_requests{k8s_cluster="prod",component="web"})`,
},
},
},
},
},
},
TimeWindow: []v1.SLOTimeWindow{
{
Duration: v1.NewDurationShorthand(1, v1.DurationShorthandUnitWeek),
IsRolling: false,
Calendar: &v1.SLOCalendar{
StartTime: "2022-01-01 12:00:00",
TimeZone: "America/New_York",
},
},
},
BudgetingMethod: v1.SLOBudgetingMethodTimeslices,
Objectives: []v1.SLOObjective{
{
DisplayName: "Good",
Target: ptr(0.995),
TimeSliceTarget: ptr(0.95),
TimeSliceWindow: ptr(v1.NewDurationShorthand(1, v1.DurationShorthandUnitMinute)),
},
},
},
)
// Read the raw SLO object.
objects, err := openslosdk.Decode(bytes.NewBufferString(sloYAML), openslosdk.FormatYAML)
if err != nil {
panic(err)
}
// Compare the raw SLO object with the programmatically defined SLO object.
if !reflect.DeepEqual(objects[0], slo) {
panic("SLO objects are not equal!")
}
// Validate the SLO object.
if err = slo.Validate(); err != nil {
panic(err)
}
// Encode the SLO object to YAML and write it to stdout.
if err = openslosdk.Encode(os.Stdout, openslosdk.FormatYAML, slo); err != nil {
panic(err)
}
Output: - apiVersion: openslo/v1 kind: SLO metadata: displayName: SLO for web availability labels: env: - prod team: - team-a - team-b name: web-availability spec: budgetingMethod: Timeslices description: X% of search requests are successful indicator: metadata: name: web-successful-requests-ratio spec: ratioMetric: counter: true good: metricSource: spec: query: sum(http_requests{k8s_cluster="prod",component="web",code=~"2xx|4xx"}) type: Prometheus total: metricSource: spec: query: sum(http_requests{k8s_cluster="prod",component="web"}) type: Prometheus objectives: - displayName: Good target: 0.995 timeSliceTarget: 0.95 timeSliceWindow: 1m service: web timeWindow: - calendar: startTime: "2022-01-01 12:00:00" timeZone: America/New_York duration: 1w isRolling: false
func (SLO) GetMetadata ¶ added in v0.6.0
func (SLO) GetVersion ¶
func (SLO) IsComposite ¶
type SLOAlertPolicy ¶
type SLOAlertPolicy struct {
*SLOAlertPolicyInline
*SLOAlertPolicyRef
}
type SLOAlertPolicyInline ¶
type SLOAlertPolicyInline struct {
Kind openslo.Kind `json:"kind"`
Metadata Metadata `json:"metadata"`
Spec AlertPolicySpec `json:"spec"`
}
type SLOAlertPolicyRef ¶
type SLOAlertPolicyRef struct {
AlertPolicyRef string `json:"alertPolicyRef"`
}
type SLOBudgetingMethod ¶
type SLOBudgetingMethod string
const ( SLOBudgetingMethodOccurrences SLOBudgetingMethod = "Occurrences" SLOBudgetingMethodTimeslices SLOBudgetingMethod = "Timeslices" SLOBudgetingMethodRatioTimeslices SLOBudgetingMethod = "RatioTimeslices" )
type SLOCalendar ¶
type SLOIndicatorInline ¶
type SLOObjective ¶
type SLOObjective struct {
DisplayName string `json:"displayName,omitempty"`
Operator Operator `json:"op,omitempty"`
Value *float64 `json:"value,omitempty"`
Target *float64 `json:"target,omitempty"`
TargetPercent *float64 `json:"targetPercent,omitempty"`
TimeSliceTarget *float64 `json:"timeSliceTarget,omitempty"`
TimeSliceWindow *DurationShorthand `json:"timeSliceWindow,omitempty"`
Indicator *SLOIndicatorInline `json:"indicator,omitempty"`
IndicatorRef *string `json:"indicatorRef,omitempty"`
CompositeWeight *float64 `json:"compositeWeight,omitempty"`
}
type SLOSpec ¶
type SLOSpec struct {
Description string `json:"description,omitempty"`
Service string `json:"service"`
Indicator *SLOIndicatorInline `json:"indicator,omitempty"`
IndicatorRef *string `json:"indicatorRef,omitempty"`
BudgetingMethod SLOBudgetingMethod `json:"budgetingMethod"`
TimeWindow []SLOTimeWindow `json:"timeWindow,omitempty"`
Objectives []SLOObjective `json:"objectives"`
AlertPolicies []SLOAlertPolicy `json:"alertPolicies,omitempty"`
}
func (SLOSpec) HasCompositeObjectives ¶
type SLOTimeWindow ¶
type SLOTimeWindow struct {
Duration DurationShorthand `json:"duration"`
IsRolling bool `json:"isRolling"`
Calendar *SLOCalendar `json:"calendar,omitempty"`
}
type Service ¶
type Service struct {
APIVersion openslo.Version `json:"apiVersion"`
Kind openslo.Kind `json:"kind"`
Metadata Metadata `json:"metadata"`
Spec ServiceSpec `json:"spec"`
}
Example ¶
package main
import (
"bytes"
"os"
"reflect"
v1 "github.com/OpenSLO/go-sdk/pkg/openslo/v1"
"github.com/OpenSLO/go-sdk/pkg/openslosdk"
)
func main() {
// Raw Service object in YAML format.
const serviceYAML = `
- apiVersion: openslo/v1
kind: Service
metadata:
labels:
env:
- prod
team:
- team-a
- team-b
name: example-service
spec:
description: Example service description
`
// Define Service programmatically.
service := v1.NewService(
v1.Metadata{
Name: "example-service",
Labels: v1.Labels{
"team": {"team-a", "team-b"},
"env": {"prod"},
},
},
v1.ServiceSpec{
Description: "Example service description",
},
)
// Read the raw Service object.
objects, err := openslosdk.Decode(bytes.NewBufferString(serviceYAML), openslosdk.FormatYAML)
if err != nil {
panic(err)
}
// Compare the raw Service object with the programmatically defined Service object.
if !reflect.DeepEqual(objects[0], service) {
panic("Service objects are not equal!")
}
// Validate the Service object.
if err = service.Validate(); err != nil {
panic(err)
}
// Encode the Service object to YAML and write it to stdout.
if err = openslosdk.Encode(os.Stdout, openslosdk.FormatYAML, service); err != nil {
panic(err)
}
}
Output: - apiVersion: openslo/v1 kind: Service metadata: labels: env: - prod team: - team-a - team-b name: example-service spec: description: Example service description
func NewService ¶
func NewService(metadata Metadata, spec ServiceSpec) Service
func (Service) GetMetadata ¶ added in v0.6.0
func (Service) GetValidator ¶ added in v0.7.0
func (Service) GetVersion ¶
type ServiceSpec ¶
type ServiceSpec struct {
Description string `json:"description,omitempty"`
}