classes

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package classes provides types for class-based SLO management.

Class-based SLOs allow scaling observability by grouping endpoints into criticality tiers (critical, normal, best-effort) and mapping each class to SLO templates with threshold overrides.

This approach is used by large services to avoid per-endpoint SLO configuration while maintaining meaningful SLOs aligned with business impact.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Class

type Class struct {
	// Name is the class identifier (critical, normal, best_effort).
	Name ClassLevel `json:"name"`

	// Description explains the class purpose.
	Description string `json:"description,omitempty"`

	// SLOTemplate references an SLO template to use.
	SLOTemplate string `json:"slo_template"`

	// Endpoints are the endpoint patterns for this class.
	// Supports wildcards: /profile/* matches /profile/settings
	Endpoints []string `json:"endpoints"`

	// ThresholdOverrides customizes the SLO template for this class.
	ThresholdOverrides ThresholdOverrides `json:"threshold_overrides,omitempty"`
}

Class defines an endpoint class with SLO configuration.

func NewBestEffortClass

func NewBestEffortClass(endpoints ...string) Class

NewBestEffortClass creates a best-effort class with relaxed defaults.

func NewCriticalClass

func NewCriticalClass(endpoints ...string) Class

NewCriticalClass creates a critical class with common defaults.

func NewNormalClass

func NewNormalClass(endpoints ...string) Class

NewNormalClass creates a normal class with common defaults.

type ClassLevel

type ClassLevel string

ClassLevel represents endpoint criticality tier.

const (
	// ClassCritical is for high-impact endpoints (login, checkout, payments).
	ClassCritical ClassLevel = "critical"

	// ClassNormal is for standard endpoints (profile, search).
	ClassNormal ClassLevel = "normal"

	// ClassBestEffort is for low-priority endpoints (recommendations, analytics).
	ClassBestEffort ClassLevel = "best_effort"
)

type SLOTemplate

type SLOTemplate struct {
	// Name is the template identifier.
	Name string `json:"name"`

	// Description explains the template.
	Description string `json:"description,omitempty"`

	// IndicatorType is "availability", "latency", or "custom".
	IndicatorType string `json:"indicator_type"`

	// Defaults are the default threshold values.
	Defaults ThresholdOverrides `json:"defaults"`
}

SLOTemplate defines a reusable SLO configuration.

func StandardTemplates

func StandardTemplates() []SLOTemplate

StandardTemplates returns commonly used SLO templates.

type ServiceSpec

type ServiceSpec struct {
	// Service is the service name.
	Service string `json:"service"`

	// Owner is the team or person responsible for the service.
	Owner string `json:"owner,omitempty"`

	// MetricsModel specifies which metrics frameworks to use (RED, USE).
	MetricsModel []string `json:"metrics_model,omitempty"`

	// Classes defines endpoint classification and SLO mapping.
	Classes []Class `json:"classes"`

	// DefaultClass is the fallback class for unmatched endpoints.
	DefaultClass ClassLevel `json:"default_class,omitempty"`
}

ServiceSpec defines observability configuration for a service.

func NewServiceSpec

func NewServiceSpec(service, owner string) *ServiceSpec

NewServiceSpec creates a new service spec.

func (*ServiceSpec) AddClass

func (s *ServiceSpec) AddClass(c Class) *ServiceSpec

AddClass adds a class definition.

func (*ServiceSpec) ClassifyEndpoint

func (s *ServiceSpec) ClassifyEndpoint(endpoint string) *Class

ClassifyEndpoint returns the class for an endpoint path.

func (*ServiceSpec) GenerateSLOs

func (s *ServiceSpec) GenerateSLOs() []v1.SLO

GenerateSLOs generates OpenSLO objects for all endpoints in the service.

func (*ServiceSpec) WithDefaultClass

func (s *ServiceSpec) WithDefaultClass(level ClassLevel) *ServiceSpec

WithDefaultClass sets the fallback class for unmatched endpoints.

func (*ServiceSpec) WithMetricsModel

func (s *ServiceSpec) WithMetricsModel(models ...string) *ServiceSpec

WithMetricsModel sets the metrics frameworks.

type ThresholdOverrides

type ThresholdOverrides struct {
	// Latency is the maximum acceptable latency (e.g., "200ms").
	Latency string `json:"latency,omitempty"`

	// Availability is the target availability percentage (e.g., 99.9).
	Availability float64 `json:"availability,omitempty"`

	// ErrorRate is the maximum acceptable error rate percentage.
	ErrorRate float64 `json:"error_rate,omitempty"`

	// TimeWindow is the SLO time window (e.g., "30d").
	TimeWindow string `json:"time_window,omitempty"`
}

ThresholdOverrides allows per-class customization of SLO targets.

Jump to

Keyboard shortcuts

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