sla

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Report

type Report struct {
	Timestamp   time.Time   `json:"timestamp"`
	WindowStart time.Time   `json:"window_start"`
	WindowEnd   time.Time   `json:"window_end"`
	SLOs        []SLOStatus `json:"slos"`
	Overall     bool        `json:"overall_compliant"`
}

Report represents a full SLA status report.

type SLAConfig

type SLAConfig struct {
	// SLOs is the list of SLOs to track.
	SLOs []SLO `json:"slos"`
	// WindowDuration is the rolling window over which SLIs are calculated.
	WindowDuration time.Duration `json:"window_duration"`
}

SLAConfig configures the SLA monitor.

func DefaultConfig

func DefaultConfig() SLAConfig

DefaultConfig returns a default SLA config with standard SLOs.

type SLAMonitor

type SLAMonitor struct {
	// contains filtered or unexported fields
}

SLAMonitor tracks SLIs and computes SLO compliance and error budgets.

func NewSLAMonitor

func NewSLAMonitor(cfg SLAConfig) *SLAMonitor

NewSLAMonitor creates a new SLAMonitor with the given config.

func (*SLAMonitor) Handler

func (m *SLAMonitor) Handler() http.HandlerFunc

Handler returns an HTTP handler that serves the SLA status as JSON at GET /api/sla/status.

func (*SLAMonitor) RecordLatency

func (m *SLAMonitor) RecordLatency(d time.Duration)

RecordLatency records a request latency.

func (*SLAMonitor) RecordRequest

func (m *SLAMonitor) RecordRequest(isError bool)

RecordRequest records a request outcome.

func (*SLAMonitor) RecordUptime

func (m *SLAMonitor) RecordUptime(success bool)

RecordUptime records an uptime check result.

func (*SLAMonitor) Reset

func (m *SLAMonitor) Reset()

Reset clears all SLI data and resets the window start time.

func (*SLAMonitor) Status

func (m *SLAMonitor) Status() Report

Status computes the current SLA status report.

type SLO

type SLO struct {
	// Name is a human-readable name for this SLO.
	Name string `json:"name"`
	// Type is "uptime", "latency", or "error_rate".
	Type string `json:"type"`
	// Target is the target value (e.g., 0.999 for 99.9% uptime, 500 for 500ms latency).
	Target float64 `json:"target"`
}

SLO defines a Service Level Objective.

type SLOStatus

type SLOStatus struct {
	Name            string  `json:"name"`
	Type            string  `json:"type"`
	Target          float64 `json:"target"`
	Current         float64 `json:"current"`
	Met             bool    `json:"met"`
	ErrorBudget     float64 `json:"error_budget"`
	ErrorBudgetUsed float64 `json:"error_budget_used"`
}

SLOStatus represents the status of a single SLO.

Jump to

Keyboard shortcuts

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