common

package
v1.13.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	DefaultRetryInterval = 100 * time.Millisecond
	DefaultTimeout       = 90 * time.Second
)

Variables

View Source
var (
	// Environment variables which carry information about the alloy container under test are prefixed with ALLOY_
	AlloyStartTimeEnv = "ALLOY_START_TIME_UNIX"

	// Environment variables which adjust the test behavior are prefixed with TEST_
	TestStatefulEnv = "TEST_STATEFUL"
	TestTimeout     = "TEST_TIMEOUT"
)
View Source
var OtelDefaultHistogramMetrics = []string{
	"example_exponential_histogram",
	"example_exponential_float_histogram",
}

Default histogram metrics list according to what the otel-gen app is generating.

View Source
var OtelDefaultMetrics = []string{
	"example_counter",
	"example_float_counter",
	"example_updowncounter",
	"example_float_updowncounter",
	"example_histogram_bucket",
	"example_float_histogram_bucket",
}

Default metrics list according to what the otel-gen app is generating.

View Source
var PromDefaultMetricMetadata = map[string]Metadata{
	"golang_counter":         {Type: "counter", Help: "The counter description string"},
	"golang_gauge":           {Type: "gauge", Help: "The gauge description string"},
	"golang_histogram":       {Type: "histogram", Help: "The histogram description string"},
	"golang_mixed_histogram": {Type: "histogram", Help: "The mixed_histogram description string"},
	"golang_summary":         {Type: "summary", Help: "The summary description string"},
}

Default metrics metadata that the prometheus.remote_write and otelcol.exporter.otlphttp components create in Mimir.

View Source
var PromDefaultMetrics = []string{
	"golang_counter",
	"golang_gauge",
	"golang_histogram_bucket",
	"golang_histogram_count",
	"golang_histogram_sum",
	"golang_mixed_histogram_bucket",
	"golang_mixed_histogram_count",
	"golang_mixed_histogram_sum",
	"golang_summary",
}

Default metrics list according to what the prom-gen app is generating.

View Source
var PromDefaultNativeHistogramMetadata = map[string]Metadata{
	"golang_native_histogram": {Type: "histogram", Help: "The native_histogram description string"},
	"golang_mixed_histogram":  {Type: "histogram", Help: "The mixed_histogram description string"},
}

Default native histogram metadata

View Source
var PromDefaultNativeHistogramMetrics = []string{
	"golang_native_histogram",
	"golang_mixed_histogram",
}

Default native histogram metrics list according to what the prom-gen app is generating.

View Source
var WriteQueueDefaultMetricMetadata = map[string]Metadata{
	"golang_counter":                {Type: "counter", Help: "The counter description string"},
	"golang_gauge":                  {Type: "gauge", Help: "The gauge description string"},
	"golang_histogram_bucket":       {Type: "histogram", Help: "The histogram description string"},
	"golang_histogram_count":        {Type: "histogram", Help: "The histogram description string"},
	"golang_histogram_sum":          {Type: "histogram", Help: "The histogram description string"},
	"golang_mixed_histogram_bucket": {Type: "histogram", Help: "The mixed_histogram description string"},
	"golang_mixed_histogram_count":  {Type: "histogram", Help: "The mixed_histogram description string"},
	"golang_mixed_histogram_sum":    {Type: "histogram", Help: "The mixed_histogram description string"},
	"golang_summary":                {Type: "summary", Help: "The summary description string"},
}

Default metrics metadata that the prometheus.write_queue component creates in Mimir. For some reason it causes _bucket, _count, and _sum metrics to be visible on Mimir's /metadata endpoint. This is not normal. When Prometheus or Alloy's prometheus.remote_write components send metrics to Mimir, only the metric family is visible on Mimir's /metadata endpoint. TODO: Look into why the write_queue components causes Mimir to behave this way.

Functions

func AlloyStartTimeUnix

func AlloyStartTimeUnix() int64

AlloyStartTimeUnix pulls the start time from env.

func AlloyStartTimeUnixNano

func AlloyStartTimeUnixNano() int64

func AssertHistogramData

func AssertHistogramData(t *testing.T, query string, expectedMetric string, testName string)

AssertHistogramData performs a Prometheus query and expect the result to eventually contain the expected histogram. The count and sum metrics should be greater than 10 before the timeout triggers.

func AssertLogsPresent

func AssertLogsPresent(t *testing.T, expected ...ExpectedLogResult)

AssertLogsPresent checks that logs are present in Loki and match expected labels

func AssertMetricData

func AssertMetricData(t *testing.T, query, expectedMetric string, testName string)

AssertMetricData performs a Prometheus query and expect the result to eventually contain the expected metric.

func AssertMetricsAvailable

func AssertMetricsAvailable(t *testing.T, metrics []string, histogramMetrics []string, testName string)

AssertMetricsAvailable performs a Prometheus query and expect the result to eventually contain the list of expected metrics.

func AssertStatefulTestEnv

func AssertStatefulTestEnv(t *testing.T)

AssertStatefulTestEnv verifies the environment is properly configured if the test is supposed to be stateful

func AssertTracesAvailable

func AssertTracesAvailable(t *testing.T, tags map[string]string)

AssertTracesAvailable performs a Tempo search query and expects to eventually find traces with the given tags

func FetchDataFromURL

func FetchDataFromURL(url string, target Unmarshaler) (string, error)

func IsStatefulTest

func IsStatefulTest() bool

func LogQuery

func LogQuery(testName string, limit int) string

LogQuery returns a formatted Loki query with the given test_name label

func MetadataQuery

func MetadataQuery() string

func MetricQuery

func MetricQuery(metricName string, testName string) string

MetricQuery returns a formatted Prometheus metric query with a given metricName and the given test_name label.

func MetricsQuery

func MetricsQuery(testName string) string

MetricsQuery returns the list of available metrics matching the given test_name label.

func MimirMetadataTest

func MimirMetadataTest(t *testing.T, expectedMetadata map[string]Metadata)

func MimirMetricsTest

func MimirMetricsTest(t *testing.T, metrics []string, histogramMetrics []string, testName string)

MimirMetricsTest checks that all given metrics are stored in Mimir.

func SanitizeTestName

func SanitizeTestName(t *testing.T) string

func TempoSearchQuery

func TempoSearchQuery(tags map[string]string) string

TempoSearchQuery builds a Tempo search query URL for traces with given tags

func TestTimeoutEnv

func TestTimeoutEnv(t *testing.T) time.Duration

func TracesTest

func TracesTest(t *testing.T, tags map[string]string, testName string)

TracesTest checks that traces with the given tags are stored in Tempo

func WaitForInitalLogs

func WaitForInitalLogs(testName string) error

WaitForInitalLogs will try to wait until any logs can be retrieved from loki for testName. It will return an error if no logs are found after test timeout.

Types

type Bucket

type Bucket struct {
	BoundaryRule  float64
	LeftBoundary  string
	RightBoundary string
	CountInBucket string
}

func (*Bucket) UnmarshalJSON

func (b *Bucket) UnmarshalJSON(data []byte) error

type ExpectedLogResult

type ExpectedLogResult struct {
	Labels     map[string]string
	EntryCount int
}

type HistogramData

type HistogramData struct {
	Count   string   `json:"count"`
	Sum     string   `json:"sum"`
	Buckets []Bucket `json:"buckets"`
}

type HistogramRawData

type HistogramRawData struct {
	Timestamp float64
	Data      HistogramData
}

func (*HistogramRawData) UnmarshalJSON

func (h *HistogramRawData) UnmarshalJSON(b []byte) error

type LogData

type LogData struct {
	Stream map[string]string `json:"stream"`
	Values [][2]string       `json:"values"`
}

type LogResponse

type LogResponse struct {
	Status string `json:"status"`
	Data   struct {
		ResultType string    `json:"resultType"`
		Result     []LogData `json:"result"`
	} `json:"data"`
}

Query response types

func (*LogResponse) Unmarshal

func (m *LogResponse) Unmarshal(data []byte) error

type Metadata

type Metadata struct {
	Type string `json:"type"`
	Help string `json:"help"`
	Unit string `json:"unit"`
}

type MetadataResponse

type MetadataResponse struct {
	Status string                `json:"status"`
	Data   map[string][]Metadata `json:"data"`
}

func GetMetadata

func GetMetadata() (MetadataResponse, error)

GetMetadata returns all available metric metadata

func (*MetadataResponse) Unmarshal

func (m *MetadataResponse) Unmarshal(bytes []byte) error

type Metric

type Metric struct {
	TestName string `json:"test_name"`
	Name     string `json:"__name__"`
}

type MetricData

type MetricData struct {
	ResultType string         `json:"resultType"`
	Result     []MetricResult `json:"result"`
}

type MetricResponse

type MetricResponse struct {
	Status string     `json:"status"`
	Data   MetricData `json:"data"`
}

func (*MetricResponse) Unmarshal

func (m *MetricResponse) Unmarshal(data []byte) error

type MetricResult

type MetricResult struct {
	Metric    Metric            `json:"metric"`
	Value     *Value            `json:"value,omitempty"`
	Histogram *HistogramRawData `json:"histogram,omitempty"`
}

type MetricsResponse

type MetricsResponse struct {
	Status string   `json:"status"`
	Data   []Metric `json:"data"`
}

func (*MetricsResponse) Unmarshal

func (m *MetricsResponse) Unmarshal(data []byte) error

type PushRequest

type PushRequest struct {
	Streams []LogData `json:"streams"`
}

Push request types

type TempoTraceSearchResponse

type TempoTraceSearchResponse struct {
	Traces []TraceInfo `json:"traces"`
}

TempoTraceSearchResponse represents the response from Tempo's trace search API

func (*TempoTraceSearchResponse) Unmarshal

func (t *TempoTraceSearchResponse) Unmarshal(data []byte) error

type TraceInfo

type TraceInfo struct {
	TraceID           string            `json:"traceID"`
	RootServiceName   string            `json:"rootServiceName"`
	RootTraceName     string            `json:"rootTraceName"`
	StartTimeUnixNano string            `json:"startTimeUnixNano"`
	DurationMs        float64           `json:"durationMs"`
	SpanSet           map[string]string `json:"spanSet,omitempty"`
}

TraceInfo represents basic trace information from Tempo search

type Unmarshaler

type Unmarshaler interface {
	Unmarshal([]byte) error
}

type Value

type Value struct {
	Timestamp int64
	Value     string
}

func (*Value) UnmarshalJSON

func (v *Value) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

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