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 ¶
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 ¶
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 ¶
MuxWithRoutes returns a ServeMux that includes the PromSim handlers already registered
func NewTestServer ¶
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