v1alpha

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package v1alpha defines the OpenSLO specification version v1alpha definitions.

Index

Examples

Constants

View Source
const APIVersion = openslo.VersionV1alpha

Variables

This section is empty.

Functions

func GetSupportedKinds

func GetSupportedKinds() []openslo.Kind

Types

type Metadata

type Metadata struct {
	Name        string `json:"name"`
	DisplayName string `json:"displayName,omitempty"`
}

type Object added in v0.6.0

type Object interface {
	openslo.Object
	GetMetadata() Metadata
}

type Operator

type Operator string
const (
	OperatorGT  Operator = "gt"
	OperatorLT  Operator = "lt"
	OperatorGTE Operator = "gte"
	OperatorLTE Operator = "lte"
)

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 NewSLO

func NewSLO(metadata Metadata, spec SLOSpec) SLO

func (SLO) GetKind

func (s SLO) GetKind() openslo.Kind

func (SLO) GetMetadata added in v0.6.0

func (s SLO) GetMetadata() Metadata

func (SLO) GetName

func (s SLO) GetName() string

func (SLO) GetValidator added in v0.7.0

func (s SLO) GetValidator() govy.Validator[SLO]

func (SLO) GetVersion

func (s SLO) GetVersion() openslo.Version

func (SLO) String added in v0.4.0

func (s SLO) String() string

func (SLO) Validate

func (s SLO) Validate() error

type SLOBudgetingMethod

type SLOBudgetingMethod string
const (
	SLOBudgetingMethodOccurrences SLOBudgetingMethod = "Occurrences"
	SLOBudgetingMethodTimeslices  SLOBudgetingMethod = "Timeslices"
)

type SLOCalendar

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

type SLOIndicator

type SLOIndicator struct {
	ThresholdMetric SLOMetricSourceSpec `json:"thresholdMetric"`
}

type SLOMetricSourceSpec

type SLOMetricSourceSpec struct {
	Source    string `json:"source"`
	QueryType string `json:"queryType"`
	Query     string `json:"query"`
}

type SLOObjective

type SLOObjective struct {
	DisplayName     string           `json:"displayName"`
	Value           *float64         `json:"value"`
	RatioMetrics    *SLORatioMetrics `json:"ratioMetrics"`
	BudgetTarget    *float64         `json:"target"`
	TimeSliceTarget *float64         `json:"timeSliceTarget,omitempty"`
	Operator        Operator         `json:"op,omitempty"`
}

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) GetKind

func (s Service) GetKind() openslo.Kind

func (Service) GetMetadata added in v0.6.0

func (s Service) GetMetadata() Metadata

func (Service) GetName

func (s Service) GetName() string

func (Service) GetValidator added in v0.7.0

func (s Service) GetValidator() govy.Validator[Service]

func (Service) GetVersion

func (s Service) GetVersion() openslo.Version

func (Service) String added in v0.4.0

func (s Service) String() string

func (Service) Validate

func (s Service) Validate() error

type ServiceSpec

type ServiceSpec struct {
	Description string `json:"description,omitempty"`
}

Jump to

Keyboard shortcuts

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