Documentation
¶
Overview ¶
Package v1alpha defines the OpenSLO specification version v1alpha definitions.
Index ¶
- Constants
- func GetSupportedKinds() []openslo.Kind
- type Metadata
- type Object
- type Operator
- type SLO
- type SLOBudgetingMethod
- type SLOCalendar
- type SLOIndicator
- type SLOMetricSourceSpec
- type SLOObjective
- type SLORatioMetrics
- type SLOSpec
- type SLOTimeWindow
- type SLOTimeWindowUnit
- type Service
- type ServiceSpec
Examples ¶
Constants ¶
View Source
const APIVersion = openslo.VersionV1alpha
Variables ¶
This section is empty.
Functions ¶
func GetSupportedKinds ¶
Types ¶
type SLO ¶
type SLO struct {
APIVersion openslo.Version `json:"apiVersion"`
Kind openslo.Kind `json:"kind"`
Metadata Metadata `json:"metadata"`
Spec SLOSpec `json:"spec"`
}
Example ¶
package main
import (
"bytes"
"os"
"reflect"
"github.com/OpenSLO/go-sdk/pkg/openslo/v1alpha"
"github.com/OpenSLO/go-sdk/pkg/openslosdk"
)
func main() {
// Raw SLO object in YAML format.
const sloYAML = `
- apiVersion: openslo/v1alpha
kind: SLO
metadata:
name: web-availability
displayName: SLO for web availability
spec:
description: X% of search requests are successful
service: web
timeWindows:
- unit: Week
count: 1
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
value: 1
ratioMetrics:
incremental: true
good:
source: datadog
queryType: query
query: sum:requests{service:web,status:2xx}
total:
source: datadog
queryType: query
query: sum:requests{service:web}
`
// Define SLO programmatically.
slo := v1alpha.NewSLO(
v1alpha.Metadata{
Name: "web-availability",
DisplayName: "SLO for web availability",
},
v1alpha.SLOSpec{
Description: "X% of search requests are successful",
Service: "web",
TimeWindows: []v1alpha.SLOTimeWindow{
{
Unit: v1alpha.SLOTimeWindowUnitWeek,
Count: 1,
IsRolling: false,
Calendar: &v1alpha.SLOCalendar{
StartTime: "2022-01-01 12:00:00",
TimeZone: "America/New_York",
},
},
},
BudgetingMethod: v1alpha.SLOBudgetingMethodTimeslices,
Objectives: []v1alpha.SLOObjective{
{
DisplayName: "Good",
BudgetTarget: ptr(0.995),
TimeSliceTarget: ptr(0.95),
Value: ptr(1.0),
RatioMetrics: &v1alpha.SLORatioMetrics{
Incremental: true,
Good: v1alpha.SLOMetricSourceSpec{
Source: "datadog",
QueryType: "query",
Query: "sum:requests{service:web,status:2xx}",
},
Total: v1alpha.SLOMetricSourceSpec{
Source: "datadog",
QueryType: "query",
Query: "sum:requests{service:web}",
},
},
},
},
},
)
// 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)
}
}
func ptr[T any](v T) *T { return &v }
Output: - apiVersion: openslo/v1alpha kind: SLO metadata: displayName: SLO for web availability name: web-availability spec: budgetingMethod: Timeslices description: X% of search requests are successful indicator: null objectives: - displayName: Good ratioMetrics: good: query: sum:requests{service:web,status:2xx} queryType: query source: datadog incremental: true total: query: sum:requests{service:web} queryType: query source: datadog target: 0.995 timeSliceTarget: 0.95 value: 1 service: web timeWindows: - calendar: startTime: "2022-01-01 12:00:00" timeZone: America/New_York count: 1 isRolling: false unit: Week
func (SLO) GetMetadata ¶ added in v0.6.0
func (SLO) GetVersion ¶
type SLOBudgetingMethod ¶
type SLOBudgetingMethod string
const ( SLOBudgetingMethodOccurrences SLOBudgetingMethod = "Occurrences" SLOBudgetingMethodTimeslices SLOBudgetingMethod = "Timeslices" )
type SLOCalendar ¶
type SLOIndicator ¶
type SLOIndicator struct {
ThresholdMetric SLOMetricSourceSpec `json:"thresholdMetric"`
}
type SLOMetricSourceSpec ¶
type SLOObjective ¶
type SLORatioMetrics ¶
type SLORatioMetrics struct {
Good SLOMetricSourceSpec `json:"good"`
Total SLOMetricSourceSpec `json:"total"`
Incremental bool `json:"incremental"`
}
type SLOSpec ¶
type SLOSpec struct {
TimeWindows []SLOTimeWindow `json:"timeWindows"`
BudgetingMethod SLOBudgetingMethod `json:"budgetingMethod"`
Description string `json:"description,omitempty"`
Indicator *SLOIndicator `json:"indicator"`
Service string `json:"service"`
Objectives []SLOObjective `json:"objectives"`
}
type SLOTimeWindow ¶
type SLOTimeWindow struct {
Unit SLOTimeWindowUnit `json:"unit"`
Count int `json:"count"`
IsRolling bool `json:"isRolling"`
Calendar *SLOCalendar `json:"calendar,omitempty"`
}
type SLOTimeWindowUnit ¶
type SLOTimeWindowUnit string
const ( SLOTimeWindowUnitSecond SLOTimeWindowUnit = "Second" SLOTimeWindowUnitDay SLOTimeWindowUnit = "Day" SLOTimeWindowUnitWeek SLOTimeWindowUnit = "Week" SLOTimeWindowUnitMonth SLOTimeWindowUnit = "Month" SLOTimeWindowUnitQuarter SLOTimeWindowUnit = "Quarter" )
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"
"github.com/OpenSLO/go-sdk/pkg/openslo/v1alpha"
"github.com/OpenSLO/go-sdk/pkg/openslosdk"
)
func main() {
// Raw Service object in YAML format.
const serviceYAML = `
- apiVersion: openslo/v1alpha
kind: Service
metadata:
displayName: Example Service
name: example-service
spec:
description: Example service description
`
// Define Service programmatically.
service := v1alpha.NewService(
v1alpha.Metadata{
Name: "example-service",
DisplayName: "Example Service",
},
v1alpha.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/v1alpha kind: Service metadata: displayName: Example Service 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"`
}
Click to show internal directories.
Click to hide internal directories.