Documentation
¶
Overview ¶
Package v2alpha contains the OpenSLO specification version v2alpha definitions. It is a prototype of the next version of the OpenSLO specification. It is not stable and is subject to breaking changes.
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 Labels
- type Metadata
- type Object
- type Operator
- type SLI
- type SLIMetricSpec
- type SLIRatioMetric
- type SLIRawMetricType
- type SLISpec
- type SLO
- type SLOAlertPolicy
- type SLOAlertPolicyInline
- type SLOAlertPolicyRef
- type SLOBudgetingMethod
- type SLOCalendar
- type SLOObjective
- type SLOSLIInline
- type SLOSpec
- type SLOTimeWindow
- type Service
- type ServiceSpec
Examples ¶
Constants ¶
const APIVersion = openslo.VersionV2alpha
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"
"github.com/OpenSLO/go-sdk/pkg/openslo/v2alpha"
"github.com/OpenSLO/go-sdk/pkg/openslosdk"
)
func main() {
// Raw AlertCondition object in YAML format.
const alertConditionYAML = `
- apiVersion: openslo.com/v2alpha
kind: AlertCondition
metadata:
name: cpu-usage-breach
labels:
env: prod
team: team-a
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 := v2alpha.NewAlertCondition(
v2alpha.Metadata{
Name: "cpu-usage-breach",
Labels: v2alpha.Labels{
"team": "team-a",
"env": "prod",
},
},
v2alpha.AlertConditionSpec{
Severity: "page",
Condition: v2alpha.AlertConditionType{
Kind: v2alpha.AlertConditionKindBurnRate,
Operator: v2alpha.OperatorLTE,
Threshold: ptr(2.0),
LookbackWindow: v2alpha.NewDurationShorthand(1, v2alpha.DurationShorthandUnitHour),
AlertAfter: v2alpha.NewDurationShorthand(5, v2alpha.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.com/v2alpha kind: AlertCondition metadata: labels: env: prod team: team-a 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"`
}
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"
"github.com/OpenSLO/go-sdk/pkg/openslo/v2alpha"
"github.com/OpenSLO/go-sdk/pkg/openslosdk"
)
func main() {
// Raw AlertNotificationTarget object in YAML format.
const targetYAML = `
- apiVersion: openslo.com/v2alpha
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 := v2alpha.NewAlertNotificationTarget(
v2alpha.Metadata{
Name: "pd-on-call-notification",
Labels: v2alpha.Labels{
"team": "on-call",
"env": "prod",
},
},
v2alpha.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.com/v2alpha 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"
"github.com/OpenSLO/go-sdk/pkg/openslo/v2alpha"
"github.com/OpenSLO/go-sdk/pkg/openslosdk"
)
func main() {
// Raw AlertPolicy object in YAML format.
const alertPolicyYAML = `
- apiVersion: openslo.com/v2alpha
kind: AlertPolicy
metadata:
name: low-priority
labels:
env: prod
team: team-a
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 := v2alpha.NewAlertPolicy(
v2alpha.Metadata{
Name: "low-priority",
Labels: v2alpha.Labels{
"team": "team-a",
"env": "prod",
},
},
v2alpha.AlertPolicySpec{
Description: "Alert policy for low priority notifications which notifies on-call via email",
AlertWhenBreaching: true,
Conditions: []v2alpha.AlertPolicyCondition{
{
AlertPolicyConditionRef: &v2alpha.AlertPolicyConditionRef{
ConditionRef: "cpu-usage-breach",
},
},
},
NotificationTargets: []v2alpha.AlertPolicyNotificationTarget{
{
AlertPolicyNotificationTargetRef: &v2alpha.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.com/v2alpha kind: AlertPolicy metadata: labels: env: prod team: team-a 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"
"github.com/OpenSLO/go-sdk/pkg/openslo/v2alpha"
"github.com/OpenSLO/go-sdk/pkg/openslosdk"
)
func main() {
// Raw DataSource object in YAML format.
const dataSourceYAML = `
- apiVersion: openslo.com/v2alpha
kind: DataSource
metadata:
labels:
env: prod
team: team-a
name: prometheus
spec:
description: Production Prometheus
connectionDetails:
- url: http://prometheus.example.com
type: Prometheus
`
// Define DataSource programmatically.
dataSource := v2alpha.NewDataSource(
v2alpha.Metadata{
Name: "prometheus",
Labels: v2alpha.Labels{
"team": "team-a",
"env": "prod",
},
},
v2alpha.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.com/v2alpha kind: DataSource metadata: labels: env: prod team: team-a 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" )
type Metadata ¶
type Metadata struct {
Name string `json:"name"`
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"
"github.com/OpenSLO/go-sdk/pkg/openslo/v2alpha"
"github.com/OpenSLO/go-sdk/pkg/openslosdk"
)
func main() {
// Raw SLI object in YAML format.
const sliYAML = `
- apiVersion: openslo.com/v2alpha
kind: SLI
metadata:
labels:
env: prod
team: team-a
name: search-availability
spec:
description: X% of search requests are successful
ratioMetric:
counter: true
good:
dataSourceRef: my-datadog
spec:
query: sum:trace.http.request.hits.by_http_status{http.status_code:200}.as_count()
total:
dataSourceRef: my-datadog
spec:
query: sum:trace.http.request.hits.by_http_status{*}.as_count()
`
// Define SLI programmatically.
sli := v2alpha.NewSLI(
v2alpha.Metadata{
Name: "search-availability",
Labels: v2alpha.Labels{
"team": "team-a",
"env": "prod",
},
},
v2alpha.SLISpec{
Description: "X% of search requests are successful",
RatioMetric: &v2alpha.SLIRatioMetric{
Counter: true,
Good: &v2alpha.SLIMetricSpec{
DataSourceRef: "my-datadog",
Spec: map[string]interface{}{
"query": "sum:trace.http.request.hits.by_http_status{http.status_code:200}.as_count()",
},
},
Total: &v2alpha.SLIMetricSpec{
DataSourceRef: "my-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.com/v2alpha kind: SLI metadata: labels: env: prod team: team-a name: search-availability spec: description: X% of search requests are successful ratioMetric: counter: true good: dataSourceRef: my-datadog spec: query: sum:trace.http.request.hits.by_http_status{http.status_code:200}.as_count() total: dataSourceRef: my-datadog spec: query: sum:trace.http.request.hits.by_http_status{*}.as_count()
func (SLI) GetMetadata ¶ added in v0.6.0
func (SLI) GetVersion ¶
type SLIMetricSpec ¶
type SLIMetricSpec struct {
DataSourceRef string `json:"dataSourceRef,omitempty"`
DataSourceSpec *DataSourceSpec `json:"dataSourceSpec,omitempty"`
Spec map[string]any `json:"spec,omitempty"`
}
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.com/v2alpha
kind: SLO
metadata:
name: web-availability
labels:
env: prod
team: team-a
spec:
description: X% of search requests are successful
serviceRef: web
sli:
metadata:
name: web-successful-requests-ratio
spec:
ratioMetric:
counter: true
good:
dataSourceRef: my-prometheus
spec:
query: sum(http_requests{k8s_cluster="prod",component="web",code=~"2xx|4xx"})
total:
dataSourceRef: my-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 := v2alpha.NewSLO(
v2alpha.Metadata{
Name: "web-availability",
Labels: v2alpha.Labels{
"team": "team-a",
"env": "prod",
},
},
v2alpha.SLOSpec{
Description: "X% of search requests are successful",
ServiceRef: "web",
SLI: &v2alpha.SLOSLIInline{
Metadata: v2alpha.Metadata{
Name: "web-successful-requests-ratio",
},
Spec: v2alpha.SLISpec{
RatioMetric: &v2alpha.SLIRatioMetric{
Counter: true,
Good: &v2alpha.SLIMetricSpec{
DataSourceRef: "my-prometheus",
Spec: map[string]any{
"query": `sum(http_requests{k8s_cluster="prod",component="web",code=~"2xx|4xx"})`,
},
},
Total: &v2alpha.SLIMetricSpec{
DataSourceRef: "my-prometheus",
Spec: map[string]any{
"query": `sum(http_requests{k8s_cluster="prod",component="web"})`,
},
},
},
},
},
TimeWindow: []v2alpha.SLOTimeWindow{
{
Duration: v2alpha.NewDurationShorthand(1, v2alpha.DurationShorthandUnitWeek),
IsRolling: false,
Calendar: &v2alpha.SLOCalendar{
StartTime: "2022-01-01 12:00:00",
TimeZone: "America/New_York",
},
},
},
BudgetingMethod: v2alpha.SLOBudgetingMethodTimeslices,
Objectives: []v2alpha.SLOObjective{
{
DisplayName: "Good",
Target: ptr(0.995),
TimeSliceTarget: ptr(0.95),
TimeSliceWindow: ptr(v2alpha.NewDurationShorthand(1, v2alpha.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.com/v2alpha kind: SLO metadata: labels: env: prod team: team-a name: web-availability spec: budgetingMethod: Timeslices description: X% of search requests are successful objectives: - displayName: Good target: 0.995 timeSliceTarget: 0.95 timeSliceWindow: 1m serviceRef: web sli: metadata: name: web-successful-requests-ratio spec: ratioMetric: counter: true good: dataSourceRef: my-prometheus spec: query: sum(http_requests{k8s_cluster="prod",component="web",code=~"2xx|4xx"}) total: dataSourceRef: my-prometheus spec: query: sum(http_requests{k8s_cluster="prod",component="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 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"`
SLI *SLOSLIInline `json:"sli,omitempty"`
SLIRef *string `json:"sliRef,omitempty"`
CompositeWeight *float64 `json:"compositeWeight,omitempty"`
}
type SLOSLIInline ¶
type SLOSpec ¶
type SLOSpec struct {
Description string `json:"description,omitempty"`
ServiceRef string `json:"serviceRef"`
SLI *SLOSLIInline `json:"sli,omitempty"`
SLIRef *string `json:"sliRef,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"
v2alpha "github.com/OpenSLO/go-sdk/pkg/openslo/v2alpha"
"github.com/OpenSLO/go-sdk/pkg/openslosdk"
)
func main() {
// Raw Service object in YAML format.
const serviceYAML = `
- apiVersion: openslo.com/v2alpha
kind: Service
metadata:
labels:
env: prod
team: team-a
name: example-service
spec:
description: Example service description
`
// Define Service programmatically.
service := v2alpha.NewService(
v2alpha.Metadata{
Name: "example-service",
Labels: v2alpha.Labels{
"team": "team-a",
"env": "prod",
},
},
v2alpha.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.com/v2alpha kind: Service metadata: labels: env: prod team: team-a 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"`
}