promsim

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package promsim is a rudimentary Prometheus HTTP APIv1 output simulator, intended for use with unit testing that would normally require a running Prometheus server. PromSim outputs repeatable, Prometheus-formatted data, synthetically generated from query and timestamp. It does not validate queries and does not produce output that accurately depicts data shapes expected of the query. They will probably look really ugly on an actual graph PromSim currently only supports matrix responses to a query_range request

Index

Constants

This section is empty.

Variables

View Source
var UnitMap = map[string]int64{
	"ns": int64(time.Nanosecond),
	"us": int64(time.Microsecond),
	"µs": int64(time.Microsecond),
	"μs": int64(time.Microsecond),
	"ms": int64(time.Millisecond),
	"s":  int64(time.Second),
	"m":  int64(time.Minute),
	"h":  int64(time.Hour),
	"d":  int64(24 * time.Hour),
	"w":  int64(24 * 7 * time.Hour),
	"y":  int64(24 * 365 * time.Hour),
}

UnitMap provides a map of common time unit indicators to nanoseconds of duration per unit

Functions

func GetInstantData

func GetInstantData(query string, t time.Time) (string, int, error)

GetInstantData returns a simulated Vector Envelope with repeatable results

func GetTimeSeriesData

func GetTimeSeriesData(query string, start time.Time, end time.Time, step time.Duration) (string, int, error)

GetTimeSeriesData returns a simulated Matrix Envelope with repeatable results

func MuxWithRoutes

func MuxWithRoutes() *http.ServeMux

MuxWithRoutes returns a ServeMux that includes the PromSim handlers already registered

func NewTestServer

func NewTestServer() *httptest.Server

NewTestServer launches a Test Prometheus Server (for unit testing)

Types

type Modifiers

type Modifiers struct {
	// SeriesCount defines how many series to return
	SeriesCount int
	// Latency introduces a static delay in responding to each request
	Latency time.Duration
	// RangeLatency introduces an additional delay as a multiple of the number of timestamps in the series
	RangeLatency time.Duration
	// MaxValue limits the maximum value of any data in the query result
	MaxValue int
	// MinValue limits the minimum value of any data in the query result
	MinValue int
	// StatusCode indicates the desired return status code, to simulate errors
	StatusCode int
	// InvalidResponseBody when > 0 causes the server to respond with a payload that cannot be unmarshaled
	// useful for causing and testing unmarshling failure cases
	InvalidResponseBody int
	// LinePattern indicates the pattern/shape of the resulting timeseries
	LinePattern string
	// contains filtered or unexported fields
}

Modifiers represents a collection of modifiers for the simulator's behavior provided by the user

type Result

type Result struct {
	Metric string
	Values string
}

Result is a simplified version of a Prometheus timeseries response

Jump to

Keyboard shortcuts

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