mockdatadog

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package mockdatadog provides an in-process Datadog API mock for testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClient

func NewClient(ts *httptest.Server) *datadog.Client

NewClient creates a datadog.Client that talks to the given TLS test server.

func Usage

func Usage(addr string) string

Usage prints instructions for using the mock server.

Types

type Dataset

type Dataset struct {
	Monitors      []datadog.Monitor
	MonitorEvents []MonitorEventRecord
	SLOs          []datadog.SLOData
	SLOHistory    map[string]SLOHistoryRecord // keyed by SLO ID
	SLOEvents     []SLOEventRecord
}

Dataset holds all mock Datadog data served by the Server.

func LoadFromSLOCSV

func LoadFromSLOCSV(path string) (*Dataset, error)

LoadFromSLOCSV loads SLO data from the --save-raw-data CSV format. CSV format: slo_id,app,name,type,target,current,budget,violated,event_count

func NewDataset

func NewDataset() *Dataset

NewDataset creates an empty Dataset.

func RealisticDataset

func RealisticDataset() *Dataset

RealisticDataset returns a richer dataset with ~10 monitors and ~20 SLOs anchored to the current time.

func SmallDataset

func SmallDataset() *Dataset

SmallDataset returns a small deterministic dataset with a handful of monitors and SLOs anchored to the current time so events fall within any recent default date range.

type MonitorBuilder

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

MonitorBuilder provides a fluent API for constructing test monitors.

func NewMonitor

func NewMonitor(id int64, name string) *MonitorBuilder

NewMonitor starts building a new monitor.

func (*MonitorBuilder) AsAlerted

func (b *MonitorBuilder) AsAlerted() *MonitorBuilder

func (*MonitorBuilder) Build

func (b *MonitorBuilder) Build() datadog.Monitor

Build returns the constructed datadog.Monitor.

func (*MonitorBuilder) WithState

func (b *MonitorBuilder) WithState(s string) *MonitorBuilder

func (*MonitorBuilder) WithTags

func (b *MonitorBuilder) WithTags(tags ...string) *MonitorBuilder

func (*MonitorBuilder) WithType

func (b *MonitorBuilder) WithType(t string) *MonitorBuilder

type MonitorEventRecord

type MonitorEventRecord struct {
	ID        string
	MonitorID int64
	Title     string
	Status    string
	Timestamp time.Time
	Tags      []string
}

MonitorEventRecord is the server-side representation of a monitor alert event.

type SLOBuilder

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

SLOBuilder provides a fluent API for constructing test SLOs.

func NewSLO

func NewSLO(id, app, name string) *SLOBuilder

NewSLO starts building a new SLO.

func (*SLOBuilder) AsViolated

func (b *SLOBuilder) AsViolated() *SLOBuilder

AsViolated marks the SLO as below its target.

func (*SLOBuilder) Build

Build returns the SLOData and SLOHistoryRecord for the Dataset.

func (*SLOBuilder) WithBudget

func (b *SLOBuilder) WithBudget(bud float64) *SLOBuilder

func (*SLOBuilder) WithCurrent

func (b *SLOBuilder) WithCurrent(c float64) *SLOBuilder

func (*SLOBuilder) WithTarget

func (b *SLOBuilder) WithTarget(t float64) *SLOBuilder

func (*SLOBuilder) WithType

func (b *SLOBuilder) WithType(t string) *SLOBuilder

type SLOEventRecord

type SLOEventRecord struct {
	ID        string
	SLOID     string
	Title     string
	Timestamp time.Time
	Tags      []string
}

SLOEventRecord is the server-side representation of an SLO violation event.

type SLOHistoryRecord

type SLOHistoryRecord struct {
	SLIValue float64
	Budget   float64
}

SLOHistoryRecord stores SLI/budget values for a single SLO.

type Server

type Server struct {
	Dataset *Dataset
	// contains filtered or unexported fields
}

Server is a mock Datadog API server backed by a Dataset.

func New

func New(ds *Dataset) *Server

New creates a new mock Datadog server with the given dataset.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(addr string) error

ListenAndServe starts the server on the given address (e.g., ":8083").

func (*Server) Start

func (s *Server) Start() *httptest.Server

Start returns an httptest.Server for use in Go tests.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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