slogo

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

README ΒΆ

SLOGo - Go for Service Level Objectives (SLOs)

Go CI Go Lint Go SAST Go Report Card Docs Visualization License

Go utilities for working with OpenSLO (Service Level Objectives) specifications.

Overview

slogo is a Go library that provides convenient utilities for reading, writing, and validating OpenSLO specification files. It builds on top of the OpenSLO Go SDK to provide a simpler interface for working with SLO definitions in JSON and YAML formats.

Features

  • πŸ“– Read OpenSLO objects from files or readers (auto-detects JSON/YAML format)
  • πŸ“ Write OpenSLO objects to files in JSON or YAML format
  • βœ… Validate SLO definitions against the OpenSLO specification
  • πŸ”’ Type-safe Go representations of SLO objects
  • 🏷️ Predefined severity and attribute constants
  • πŸ“Š Comprehensive SLO ontology for metric labeling and categorization
  • πŸš€ Production-ready examples for RED, USE, AI Agents, and SaaS metrics

Installation

go get github.com/grokify/slogo

Usage

Reading SLO Files
import "github.com/grokify/slogo"

// Read from file (auto-detects JSON or YAML)
objs, err := slogo.ReadFile("slo-definition.yaml")
if err != nil {
    log.Fatal(err)
}

// Read from io.Reader
objs, err := slogo.Read(reader)
if err != nil {
    log.Fatal(err)
}
Validating SLO Objects
// Validate all objects
if err := objs.Validate(); err != nil {
    log.Fatal(err)
}
Writing SLO Files
// Write as YAML
err := objs.WriteFileYAML("output.yaml")
if err != nil {
    log.Fatal(err)
}

// Write as JSON
err := objs.WriteFileJSON("output.json")
if err != nil {
    log.Fatal(err)
}
Using Predefined Constants
import "github.com/grokify/slogo"

// Severity levels
severity := slogo.SeverityCritical // "critical"
severity := slogo.SeverityHigh     // "high"
severity := slogo.SeverityMedium   // "medium"
severity := slogo.SeverityLow      // "low"
severity := slogo.SeverityInfo     // "info"

// Attributes
attr := slogo.AttrQuery // "query"
Using the Ontology System
import (
    v1 "github.com/OpenSLO/go-sdk/pkg/openslo/v1"
    "github.com/grokify/slogo/ontology"
)

// Create labeled SLO metadata
metadata := v1.Metadata{
    Name:        "api-error-rate",
    DisplayName: "API Error Rate",
    Labels: ontology.NewLabels(map[string]string{
        ontology.LabelFramework:  ontology.FrameworkRED,
        ontology.LabelLayer:      ontology.LayerService,
        ontology.LabelScope:      ontology.ScopeCustomerFacing,
        ontology.LabelAudience:   ontology.AudienceSRE,
        ontology.LabelCategory:   ontology.CategoryQuality,
        ontology.LabelSeverity:   ontology.SeverityCritical,
        ontology.LabelTier:       ontology.TierP0,
    }),
}

Ontology

The ontology package provides a comprehensive labeling system for organizing and categorizing SLOs across multiple dimensions:

  • πŸ”§ Frameworks: RED (Rate/Errors/Duration), USE (Utilization/Saturation/Errors), Custom
  • πŸ“¦ Layers: Service, Infrastructure, Business, Application
  • 🎯 Scopes: Customer-facing, Internal, Business-outcome
  • πŸ‘₯ Audiences: SRE, Engineering, Product, Executive, Customer-success
  • πŸ“Š Categories: Availability, Latency, Throughput, Quality, Resource, Engagement, Conversion, Cost
  • ⚠️ Severities: Critical, High, Medium, Low
  • πŸ“ˆ Metric Types: Rate, Errors, Duration, Utilization, Saturation, Satisfaction, Stickiness, Retention, etc.
  • 🏒 Domains: AI-ML, CRM, SaaS, E-commerce, Fintech
  • πŸ—ΊοΈ Journey Stages: Acquisition, Activation, Engagement, Retention, Revenue, Referral

This multi-dimensional taxonomy enables effective filtering, querying, and organization of SLOs across different teams and use cases.

Examples

The examples directory contains production-ready SLO examples organized by monitoring framework and use case:

Infrastructure & Service Monitoring
RED Metrics (4 SLOs)

Request-driven service monitoring for APIs and microservices:

  • πŸ“ˆ Rate SLO - Track request throughput (requests per second)
  • ❌ Error Rate SLO - Monitor success/failure ratio with 99.9% reliability target
  • ⏱️ Duration SLOs - P95 and P99 latency monitoring for response times
USE Metrics (11 SLOs)

Infrastructure resource monitoring with Brendan Gregg's USE methodology:

  • πŸ“Š Utilization - CPU, Memory, Disk space usage
  • 🌊 Saturation - CPU load average, swap usage, disk I/O, network bandwidth
  • ⚠️ Errors - Disk I/O errors, network errors, memory ECC errors, CPU throttling
Business & Product Metrics
AI Agents (20 SLOs)

Comprehensive monitoring for AI agent platforms with both aggregated and per-user metrics:

  • 🟒 Availability - Service uptime and per-user consistency
  • ⭐ Quality - User satisfaction, accuracy, hallucination tracking
  • ⚑ Performance - Response time, first-token latency
  • βœ… Task Success - Completion rates, abandonment, multi-step tasks
  • πŸ‘₯ Engagement - DAU, retention, session duration, conversation depth
  • πŸ’° Cost Efficiency - Token usage, per-user costs, cache hit rates
SaaS CRM (25 SLOs)

End-to-end user journey metrics for CRM platforms (Salesforce, HubSpot):

  • πŸš€ Activation - User onboarding, time to first value, activation rates
  • πŸ’¬ Engagement - DAU, MAU, DAU/MAU ratio (stickiness), WAU, power users
  • πŸ”§ Feature Adoption - Contact management, deal pipeline, email integration, reporting, mobile app
  • πŸ“ˆ Business Outcomes - Deal creation, win rates, sales cycle length, contact growth
  • πŸ”„ Retention - Day 7/30 retention, churn rate, cohort analysis, user resurrection
Methodology Examples
Budgeting Methods

Compares different budgeting methods (Occurrences, Timeslices, and RatioTimeslices):

  • 🟒 Availability SLO - Internet provider SLA with 99% uptime
  • πŸ”’ Occurrences SLO - Search latency treating all searches equally
  • πŸ“Š Ratio Timeslices SLO - Main page availability based on response codes
Treat Low Traffic as Equally Important

Maintains high reliability regardless of traffic volume, ensuring low-usage services receive equal attention.

Example Features

Each example includes:

  • βœ… Complete, working Go code
  • πŸ“‹ Detailed descriptions of what is being measured
  • 🏷️ OpenSLO-compliant metadata with ontology labels
  • πŸ” Prometheus/BigQuery query examples
  • πŸ§ͺ Automated validation tests
  • πŸ“š README with methodology explanations and best practices

Project Structure

slogo/
β”œβ”€β”€ ontology/          # SLO labeling and categorization system
β”œβ”€β”€ examples/
β”‚   β”œβ”€β”€ red-metrics/       # Rate, Errors, Duration (service monitoring)
β”‚   β”œβ”€β”€ use-metrics/       # Utilization, Saturation, Errors (infrastructure)
β”‚   β”œβ”€β”€ ai-agents/         # AI agent platform business metrics
β”‚   β”œβ”€β”€ saas-crm/          # SaaS CRM user journey metrics
β”‚   β”œβ”€β”€ budgeting-method/  # Budgeting method comparisons
β”‚   └── treat-low-traffic-as-equally-important/
β”œβ”€β”€ datadog/          # Datadog integration utilities
└── cmd/parse/        # CLI tools for parsing SLO files

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Resources

OpenSLO
SRE & Monitoring Methodologies
Product & Business Metrics

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

View Source
const (
	AttrQuery = "query"
)

Variables ΒΆ

This section is empty.

Functions ΒΆ

func NewAlertCondition ΒΆ added in v0.3.0

func NewAlertCondition(name string, severity AlertSeverity, threshold float64, lookbackWindow, alertAfter string) v1.AlertCondition

NewAlertCondition creates a new AlertCondition with burn rate configuration. lookbackWindow and alertAfter are duration strings like "1h", "5m", "1d".

func NewAlertNotificationTarget ΒΆ added in v0.3.0

func NewAlertNotificationTarget(name, target, description string) v1.AlertNotificationTarget

NewAlertNotificationTarget creates a new AlertNotificationTarget.

func ReadJSONFile ΒΆ added in v0.3.0

func ReadJSONFile(filename string) ([]openslo.Object, error)

ReadJSONFile reads multiple OpenSLO objects from a JSON file. The JSON file should contain an array of objects.

func ReadYAMLFile ΒΆ added in v0.3.0

func ReadYAMLFile(filename string) ([]openslo.Object, error)

ReadYAMLFile reads multiple OpenSLO objects from a YAML file. The YAML file can contain multiple objects separated by '---'.

func StandardBurnRateAlerts ΒΆ added in v0.3.0

func StandardBurnRateAlerts() []v1.AlertCondition

StandardBurnRateAlerts returns standard multi-window burn rate alert conditions. This implements the Google SRE recommended approach with fast and slow burn rates.

Fast burn (14x): 1h lookback, alerts quickly for severe issues Slow burn (1x): 6h lookback, catches gradual degradation

func WriteJSONFile ΒΆ added in v0.3.0

func WriteJSONFile(filename string, objects ...openslo.Object) error

WriteJSONFile writes multiple OpenSLO objects to a JSON file. Objects will be written as a JSON array.

func WriteYAMLFile ΒΆ added in v0.3.0

func WriteYAMLFile(filename string, objects ...openslo.Object) error

WriteYAMLFile writes multiple OpenSLO objects to a YAML file. Objects will be separated by '---' in the output file.

Types ΒΆ

type AlertPolicyBuilder ΒΆ added in v0.3.0

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

AlertPolicyBuilder provides a fluent interface for building AlertPolicy objects.

func NewAlertPolicyBuilder ΒΆ added in v0.3.0

func NewAlertPolicyBuilder(name string) *AlertPolicyBuilder

NewAlertPolicyBuilder creates a new AlertPolicyBuilder.

func (*AlertPolicyBuilder) AddConditionInline ΒΆ added in v0.3.0

func (b *AlertPolicyBuilder) AddConditionInline(name string, severity AlertSeverity, threshold float64, lookbackWindow string) *AlertPolicyBuilder

AddConditionInline adds an inline AlertCondition. lookbackWindow is a duration string like "1h", "5m", "1d".

func (*AlertPolicyBuilder) AddConditionRef ΒΆ added in v0.3.0

func (b *AlertPolicyBuilder) AddConditionRef(ref string) *AlertPolicyBuilder

AddConditionRef adds a reference to an external AlertCondition.

func (*AlertPolicyBuilder) AddNotificationTargetInline ΒΆ added in v0.3.0

func (b *AlertPolicyBuilder) AddNotificationTargetInline(name, target, description string) *AlertPolicyBuilder

AddNotificationTargetInline adds an inline AlertNotificationTarget.

func (*AlertPolicyBuilder) AddNotificationTargetRef ΒΆ added in v0.3.0

func (b *AlertPolicyBuilder) AddNotificationTargetRef(ref string) *AlertPolicyBuilder

AddNotificationTargetRef adds a reference to an external AlertNotificationTarget.

func (*AlertPolicyBuilder) AlertWhenBreaching ΒΆ added in v0.3.0

func (b *AlertPolicyBuilder) AlertWhenBreaching(v bool) *AlertPolicyBuilder

AlertWhenBreaching configures alerting when SLO is breaching.

func (*AlertPolicyBuilder) AlertWhenNoData ΒΆ added in v0.3.0

func (b *AlertPolicyBuilder) AlertWhenNoData(v bool) *AlertPolicyBuilder

AlertWhenNoData configures alerting when no data is available.

func (*AlertPolicyBuilder) AlertWhenResolved ΒΆ added in v0.3.0

func (b *AlertPolicyBuilder) AlertWhenResolved(v bool) *AlertPolicyBuilder

AlertWhenResolved configures alerting when SLO breach is resolved.

func (*AlertPolicyBuilder) Build ΒΆ added in v0.3.0

func (b *AlertPolicyBuilder) Build() v1.AlertPolicy

Build creates the AlertPolicy.

func (*AlertPolicyBuilder) WithDescription ΒΆ added in v0.3.0

func (b *AlertPolicyBuilder) WithDescription(desc string) *AlertPolicyBuilder

WithDescription sets the alert policy description.

func (*AlertPolicyBuilder) WithLabels ΒΆ added in v0.3.0

func (b *AlertPolicyBuilder) WithLabels(labels v1.Labels) *AlertPolicyBuilder

WithLabels sets the alert policy labels.

type AlertSeverity ΒΆ added in v0.3.0

type AlertSeverity string

AlertSeverity represents standard alert severity levels.

const (
	SeverityCritical AlertSeverity = "critical"
	SeverityHigh     AlertSeverity = "high"
	SeverityMedium   AlertSeverity = "medium"
	SeverityLow      AlertSeverity = "low"
	SeverityInfo     AlertSeverity = "info"
)

type Objects ΒΆ

type Objects []openslo.Object

func Read ΒΆ

func Read(r io.Reader) (Objects, error)

func ReadFile ΒΆ

func ReadFile(filename string) (Objects, error)

func (*Objects) AddAlertConditions ΒΆ added in v0.3.0

func (objs *Objects) AddAlertConditions(conditions ...v1.AlertCondition)

AddAlertConditions adds AlertCondition objects to the Objects slice.

func (*Objects) AddAlertNotificationTargets ΒΆ added in v0.3.0

func (objs *Objects) AddAlertNotificationTargets(targets ...v1.AlertNotificationTarget)

AddAlertNotificationTargets adds AlertNotificationTarget objects to the Objects slice.

func (*Objects) AddAlertPolicies ΒΆ added in v0.3.0

func (objs *Objects) AddAlertPolicies(policies ...v1.AlertPolicy)

AddAlertPolicies adds AlertPolicy objects to the Objects slice.

func (*Objects) AddSLOs ΒΆ added in v0.3.0

func (objs *Objects) AddSLOs(slos ...v1.SLO)

func (Objects) Validate ΒΆ

func (objs Objects) Validate() error

func (Objects) WriteFile ΒΆ

func (objs Objects) WriteFile(filename string, format openslosdk.ObjectFormat) error

func (Objects) WriteFileJSON ΒΆ

func (objs Objects) WriteFileJSON(filename string) error

func (Objects) WriteFileYAML ΒΆ

func (objs Objects) WriteFileYAML(filename string) error

Directories ΒΆ

Path Synopsis
cmd
gen-metrics-doc command
label-stats command
ontologies
domains/business
Package business provides business-specific ontology labels and values for SLOs.
Package business provides business-specific ontology labels and values for SLOs.
domains/compliance
Package compliance provides compliance-specific ontology labels and values for SLOs.
Package compliance provides compliance-specific ontology labels and values for SLOs.
domains/iam
Package iam provides IAM/IGA-specific ontology labels and values for SLOs.
Package iam provides IAM/IGA-specific ontology labels and values for SLOs.
domains/operations
Package operations provides operations-specific ontology labels and values for SLOs.
Package operations provides operations-specific ontology labels and values for SLOs.
domains/product
Package product provides product/growth-specific ontology labels and values for SLOs.
Package product provides product/growth-specific ontology labels and values for SLOs.
domains/saas
Package saas provides SaaS-specific ontology labels and values for SLOs.
Package saas provides SaaS-specific ontology labels and values for SLOs.
domains/security
Package security provides security-specific ontology labels and values for SLOs.
Package security provides security-specific ontology labels and values for SLOs.
Package ontology provides a generic labeling taxonomy for SLOs.
Package ontology provides a generic labeling taxonomy for SLOs.

Jump to

Keyboard shortcuts

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