promclient

package
v0.0.96 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: MIT Imports: 41 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnnotationsToAPIWarnings added in v0.0.94

func AnnotationsToAPIWarnings(anns annotations.Annotations) v1.Warnings

AnnotationsToAPIWarnings converts annotations.Annotations to v1.Warnings. TODO: move to a util package?

func CloneExpr added in v0.0.92

func CloneExpr(expr parser.Expr) (newExpr parser.Expr)

CloneExp returns a cloned copy of `expr`

func DowngradeErrSeriesSet added in v0.0.94

func DowngradeErrSeriesSet(ss storage.SeriesSet) storage.SeriesSet

DowngradeErrSeriesSet returns ss with any error demoted to a warning.

func ExprIsLiteral added in v0.0.92

func ExprIsLiteral(expr parser.Expr) bool

func FilterLabelMatchers added in v0.0.77

func FilterLabelMatchers(filter map[string]map[string]struct{}, matcher *labels.Matcher) bool

TODO: better name, this is to check if a matcher is in the filter

func FilterMatchers

func FilterMatchers(ls model.LabelSet, matchers []*labels.Matcher) ([]*labels.Matcher, bool)

FilterMatchers applies the matchers to the given labelset to determine if there is a match and to return all remaining matchers to be matched

func MapErrSeriesSet added in v0.0.94

func MapErrSeriesSet(ss storage.SeriesSet, fn func(error) error) storage.SeriesSet

MapErrSeriesSet returns ss with its error transformed by fn.

func MapLabelsSeriesSet added in v0.0.94

func MapLabelsSeriesSet(ss storage.SeriesSet, fn func(labels.Labels) labels.Labels) storage.SeriesSet

MapLabelsSeriesSet returns ss with each series' labels rewritten by fn.

func MergeAnnotations added in v0.0.94

func MergeAnnotations(a, b annotations.Annotations) annotations.Annotations

MergeAnnotations unions b into a (a may be nil).

func MergeLabelSets

func MergeLabelSets(a, b []model.LabelSet) []model.LabelSet

MergeLabelSets merges the labelset b into a

func MergeLabelValues

func MergeLabelValues(a, b []model.LabelValue) []model.LabelValue

MergeLabelValues merges the labels from b into a

func MergeSeriesSets added in v0.0.94

func MergeSeriesSets(antiAffinity model.Time, dynamic bool, preferMax bool, sets ...storage.SeriesSet) storage.SeriesSet

MergeSeriesSets merges HA-member SeriesSets with anti-affinity dedup, preserving promxy's existing merge semantics. When dynamic is true the anti-affinity buffer is inferred per series from inter-sample spacing (with antiAffinity as the fallback); see promhttputil.MergeSampleStream and #734.

func ModelValueToSeriesSet added in v0.0.94

func ModelValueToSeriesSet(v model.Value, warnings annotations.Annotations, err error) storage.SeriesSet

ModelValueToSeriesSet converts a model.Value (from the remote_read path or a client_golang fallback) into a storage.SeriesSet. It is the inverse of the streaming decode and exists only for the non-JSON paths that still produce model.Value.

func NormalizePromError

func NormalizePromError(err error) error

NormalizePromError converts the errors that the prometheus API client returns into errors that the prometheus API server actually handles and returns proper error codes for

func ParserValueToModelValue added in v0.0.83

func ParserValueToModelValue(value parser.Value) (model.Value, error)

ParserValueToModelValue can *parser.Value to model.Value

func PreserveLabel added in v0.0.92

func PreserveLabel(expr parser.Expr, srcLabel string, dstLabel string) (relabelExpress parser.Expr)

PreserveLabel wraps the input expression with a label replace in order to preserve the metadata through binary expressions

func RewriteLabels added in v0.0.76

func RewriteLabels(cfgs []*MetricRelabelConfig, labels []string) []string

RewriteLabels simply rewrites the label names passed in if the actions require it

func RewriteMatchers added in v0.0.76

func RewriteMatchers(cfgs []*MetricRelabelConfig, matchers []*labels.Matcher) ([]*labels.Matcher, bool)

RewriteMatchers go through each matcher and replace the label if matches

func SeriesSetToMatrix added in v0.0.94

func SeriesSetToMatrix(ss storage.SeriesSet) (model.Matrix, error)

SeriesSetToMatrix materializes a storage.SeriesSet into a model.Matrix, for the few call sites that still operate on model.Value.

func UnwrapExpr added in v0.0.92

func UnwrapExpr(expr parser.Expr) parser.Expr

func WithWarnings added in v0.0.94

WithWarnings returns ss reporting w as its warnings.

Types

type API

type API interface {
	// LabelNames returns all the unique label names present in the block in sorted order.
	LabelNames(ctx context.Context, matchers []string, startTime time.Time, endTime time.Time) ([]string, v1.Warnings, error)
	// LabelValues performs a query for the values of the given label.
	LabelValues(ctx context.Context, label string, matchers []string, startTime time.Time, endTime time.Time) (model.LabelValues, v1.Warnings, error)
	// Query performs a query for the given time.
	Query(ctx context.Context, query string, ts time.Time) storage.SeriesSet
	// QueryRange performs a query for the given range.
	QueryRange(ctx context.Context, query string, r v1.Range) storage.SeriesSet
	// Series finds series by label matchers.
	Series(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]model.LabelSet, v1.Warnings, error)
	// GetValue loads the raw data for a given set of matchers in the time range
	GetValue(ctx context.Context, start, end time.Time, matchers []*labels.Matcher) storage.SeriesSet
	// Metadata returns metadata about metrics currently scraped by the metric name.
	Metadata(ctx context.Context, metric, limit string) (map[string][]v1.Metadata, error)
	// QueryExemplars performs a query for exemplars by the given query and time range.
	QueryExemplars(ctx context.Context, query string, startTime, endTime time.Time) ([]v1.ExemplarQueryResult, error)
}

API Subset of the interface defined in the prometheus client

func CreateTestServer added in v0.0.76

func CreateTestServer(t *testing.T, path string) (API, func(), error)

CreateTestServer creates a test HTTP server backed by an in-memory promql engine and returns an API client, a close function, and any error encountered during setup.

type APILabels

type APILabels interface {
	API
	// Key returns a labelset used to determine other api clients that are the "same"
	Key() model.LabelSet
}

APILabels includes a Key() mechanism to differentiate which APIs are "the same"

type AbsoluteTimeFilter

type AbsoluteTimeFilter struct {
	API
	Start, End time.Time
	Truncate   bool
}

AbsoluteTimeFilter will filter queries out (return nil,nil) for all queries outside the given times

func (*AbsoluteTimeFilter) GetValue

func (tf *AbsoluteTimeFilter) GetValue(ctx context.Context, start, end time.Time, matchers []*labels.Matcher) storage.SeriesSet

GetValue loads the raw data for a given set of matchers in the time range

func (*AbsoluteTimeFilter) LabelNames added in v0.0.79

func (tf *AbsoluteTimeFilter) LabelNames(ctx context.Context, matchers []string, startTime time.Time, endTime time.Time) ([]string, v1.Warnings, error)

LabelNames returns all the unique label names present in the block in sorted order.

func (*AbsoluteTimeFilter) LabelValues added in v0.0.79

func (tf *AbsoluteTimeFilter) LabelValues(ctx context.Context, label string, matchers []string, startTime time.Time, endTime time.Time) (model.LabelValues, v1.Warnings, error)

LabelValues performs a query for the values of the given label.

func (*AbsoluteTimeFilter) Query

func (tf *AbsoluteTimeFilter) Query(ctx context.Context, query string, ts time.Time) storage.SeriesSet

Query performs a query for the given time.

func (*AbsoluteTimeFilter) QueryExemplars added in v0.0.94

func (tf *AbsoluteTimeFilter) QueryExemplars(ctx context.Context, query string, startTime, endTime time.Time) ([]v1.ExemplarQueryResult, error)

QueryExemplars performs a query for exemplars by the given query and time range.

func (*AbsoluteTimeFilter) QueryRange

func (tf *AbsoluteTimeFilter) QueryRange(ctx context.Context, query string, r v1.Range) storage.SeriesSet

QueryRange performs a query for the given range.

func (*AbsoluteTimeFilter) Series

func (tf *AbsoluteTimeFilter) Series(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]model.LabelSet, v1.Warnings, error)

Series finds series by label matchers.

type AddLabelClient

type AddLabelClient struct {
	API
	Labels model.LabelSet
}

AddLabelClient proxies a client and adds the given labels to all results

func (*AddLabelClient) GetValue

func (c *AddLabelClient) GetValue(ctx context.Context, start, end time.Time, matchers []*labels.Matcher) storage.SeriesSet

GetValue loads the raw data for a given set of matchers in the time range

func (*AddLabelClient) Key

func (c *AddLabelClient) Key() model.LabelSet

Key defines the labelset which identifies this client

func (*AddLabelClient) LabelNames added in v0.0.41

func (c *AddLabelClient) LabelNames(ctx context.Context, matchers []string, startTime time.Time, endTime time.Time) ([]string, v1.Warnings, error)

LabelNames returns all the unique label names present in the block in sorted order.

func (*AddLabelClient) LabelValues

func (c *AddLabelClient) LabelValues(ctx context.Context, label string, matchers []string, startTime time.Time, endTime time.Time) (model.LabelValues, v1.Warnings, error)

LabelValues performs a query for the values of the given label.

func (*AddLabelClient) Query

func (c *AddLabelClient) Query(ctx context.Context, query string, ts time.Time) storage.SeriesSet

Query performs a query for the given time.

func (*AddLabelClient) QueryExemplars added in v0.0.94

func (c *AddLabelClient) QueryExemplars(ctx context.Context, query string, startTime, endTime time.Time) ([]v1.ExemplarQueryResult, error)

QueryExemplars performs a query for exemplars by the given query and time range. Skips the downstream call when every selector in the query is incompatible with this server-group's labels (mirrors the GetValue / Series matcher filtering — without it we'd send a guaranteed-empty query for every `metric{az="other"}` lookup). Tags each surviving result's SeriesLabels with the server-group's labels so callers can attribute exemplars.

func (*AddLabelClient) QueryRange

func (c *AddLabelClient) QueryRange(ctx context.Context, query string, r v1.Range) storage.SeriesSet

QueryRange performs a query for the given range.

func (*AddLabelClient) Series

func (c *AddLabelClient) Series(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]model.LabelSet, v1.Warnings, error)

Series finds series by label matchers.

type BooleanFinder added in v0.0.92

type BooleanFinder struct {
	Func  func(parser.Node) bool
	Found int
}

BooleanFinder uses the given func to determine if something is in there or notret := &parser.VectorSelector{Offset: offset}

func (*BooleanFinder) Visit added in v0.0.92

func (f *BooleanFinder) Visit(node parser.Node, _ []parser.Node) (parser.Visitor, error)

Visit runs on each node in the tree

type ClientArgsWrap added in v0.0.49

type ClientArgsWrap struct {
	api.Client
	// contains filtered or unexported fields
}

ClientArgsWrap wraps the prom API client to add query params to any given urls

func NewClientArgsWrap added in v0.0.49

func NewClientArgsWrap(api api.Client, args map[string]string) *ClientArgsWrap

NewClientArgsWrap returns a client that will add the given args

func (*ClientArgsWrap) URL added in v0.0.49

func (c *ClientArgsWrap) URL(ep string, args map[string]string) *url.URL

URL returns a URL for the given endpoint + args

type DebugAPI

type DebugAPI struct {
	A             API
	PrefixMessage string
}

DebugAPI simply logs debug lines for the given API with the given prefix

func (*DebugAPI) GetValue

func (d *DebugAPI) GetValue(ctx context.Context, start, end time.Time, matchers []*labels.Matcher) storage.SeriesSet

GetValue loads the raw data for a given set of matchers in the time range

func (*DebugAPI) LabelNames added in v0.0.44

func (d *DebugAPI) LabelNames(ctx context.Context, matchers []string, startTime time.Time, endTime time.Time) ([]string, v1.Warnings, error)

LabelNames returns all the unique label names present in the block in sorted order.

func (*DebugAPI) LabelValues

func (d *DebugAPI) LabelValues(ctx context.Context, label string, matchers []string, startTime time.Time, endTime time.Time) (model.LabelValues, v1.Warnings, error)

LabelValues performs a query for the values of the given label.

func (*DebugAPI) Metadata added in v0.0.76

func (d *DebugAPI) Metadata(ctx context.Context, metric, limit string) (map[string][]v1.Metadata, error)

Metadata returns metadata about metrics currently scraped by the metric name.

func (*DebugAPI) Query

func (d *DebugAPI) Query(ctx context.Context, query string, ts time.Time) storage.SeriesSet

Query performs a query for the given time.

func (*DebugAPI) QueryExemplars added in v0.0.94

func (d *DebugAPI) QueryExemplars(ctx context.Context, query string, startTime, endTime time.Time) ([]v1.ExemplarQueryResult, error)

QueryExemplars performs a query for exemplars by the given query and time range.

func (*DebugAPI) QueryRange

func (d *DebugAPI) QueryRange(ctx context.Context, query string, r v1.Range) storage.SeriesSet

QueryRange performs a query for the given range.

func (*DebugAPI) Series

func (d *DebugAPI) Series(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]model.LabelSet, v1.Warnings, error)

Series finds series by label matchers.

type DowngradeErrorAPI added in v0.0.86

type DowngradeErrorAPI struct {
	A API
}

DowngradeErrorAPI simply downgrades all errors into warnings from the given API.

func (*DowngradeErrorAPI) GetValue added in v0.0.86

func (n *DowngradeErrorAPI) GetValue(ctx context.Context, start, end time.Time, matchers []*labels.Matcher) storage.SeriesSet

GetValue loads the raw data for a given set of matchers in the time range

func (*DowngradeErrorAPI) Key added in v0.0.86

func (n *DowngradeErrorAPI) Key() model.LabelSet

Key returns a labelset used to determine other api clients that are the "same"

func (*DowngradeErrorAPI) LabelNames added in v0.0.86

func (n *DowngradeErrorAPI) LabelNames(ctx context.Context, matchers []string, startTime time.Time, endTime time.Time) ([]string, v1.Warnings, error)

LabelNames returns all the unique label names present in the block in sorted order.

func (*DowngradeErrorAPI) LabelValues added in v0.0.86

func (n *DowngradeErrorAPI) LabelValues(ctx context.Context, label string, matchers []string, startTime time.Time, endTime time.Time) (model.LabelValues, v1.Warnings, error)

LabelValues performs a query for the values of the given label.

func (*DowngradeErrorAPI) Metadata added in v0.0.86

func (n *DowngradeErrorAPI) Metadata(ctx context.Context, metric, limit string) (map[string][]v1.Metadata, error)

Metadata returns metadata about metrics currently scraped by the metric name.

func (*DowngradeErrorAPI) Query added in v0.0.86

func (n *DowngradeErrorAPI) Query(ctx context.Context, query string, ts time.Time) storage.SeriesSet

Query performs a query for the given time.

func (*DowngradeErrorAPI) QueryExemplars added in v0.0.94

func (n *DowngradeErrorAPI) QueryExemplars(ctx context.Context, query string, startTime, endTime time.Time) ([]v1.ExemplarQueryResult, error)

QueryExemplars performs a query for exemplars by the given query and time range.

func (*DowngradeErrorAPI) QueryRange added in v0.0.86

func (n *DowngradeErrorAPI) QueryRange(ctx context.Context, query string, r v1.Range) storage.SeriesSet

QueryRange performs a query for the given range.

func (*DowngradeErrorAPI) Series added in v0.0.86

func (n *DowngradeErrorAPI) Series(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]model.LabelSet, v1.Warnings, error)

Series finds series by label matchers.

type EngineAPI added in v0.0.83

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

EngineAPI implements the API interface using a Queryable and an engine

func NewEngineAPI added in v0.0.83

func NewEngineAPI(e *promql.Engine, q storage.Queryable) (*EngineAPI, error)

NewEngineAPI returns a new EngineAPI

func (*EngineAPI) GetValue added in v0.0.83

func (a *EngineAPI) GetValue(ctx context.Context, start, end time.Time, matchers []*labels.Matcher) storage.SeriesSet

GetValue loads the raw data for a given set of matchers in the time range

func (*EngineAPI) LabelNames added in v0.0.83

func (a *EngineAPI) LabelNames(ctx context.Context, matchers []string, startTime time.Time, endTime time.Time) ([]string, v1.Warnings, error)

LabelNames returns all the unique label names present in the block in sorted order.

func (*EngineAPI) LabelValues added in v0.0.83

func (a *EngineAPI) LabelValues(ctx context.Context, label string, matchers []string, startTime time.Time, endTime time.Time) (model.LabelValues, v1.Warnings, error)

LabelValues performs a query for the values of the given label.

func (*EngineAPI) Metadata added in v0.0.83

func (a *EngineAPI) Metadata(ctx context.Context, metric, limit string) (map[string][]v1.Metadata, error)

Metadata returns metadata about metrics currently scraped by the metric name.

func (*EngineAPI) Query added in v0.0.83

func (a *EngineAPI) Query(ctx context.Context, query string, ts time.Time) storage.SeriesSet

Query performs a query for the given time.

func (*EngineAPI) QueryExemplars added in v0.0.94

func (a *EngineAPI) QueryExemplars(ctx context.Context, query string, startTime, endTime time.Time) ([]v1.ExemplarQueryResult, error)

QueryExemplars performs a query for exemplars by the given query and time range.

func (*EngineAPI) QueryRange added in v0.0.83

func (a *EngineAPI) QueryRange(ctx context.Context, query string, r v1.Range) storage.SeriesSet

QueryRange performs a query for the given range.

func (*EngineAPI) Series added in v0.0.83

func (a *EngineAPI) Series(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]model.LabelSet, v1.Warnings, error)

Series finds series by label matchers.

type ErrorWrap added in v0.0.84

type ErrorWrap struct {
	A   API
	Msg string
}

func (*ErrorWrap) GetValue added in v0.0.84

func (e *ErrorWrap) GetValue(ctx context.Context, start, end time.Time, matchers []*labels.Matcher) storage.SeriesSet

GetValue loads the raw data for a given set of matchers in the time range

func (*ErrorWrap) LabelNames added in v0.0.84

func (e *ErrorWrap) LabelNames(ctx context.Context, matchers []string, startTime time.Time, endTime time.Time) (v []string, w v1.Warnings, err error)

func (*ErrorWrap) LabelValues added in v0.0.84

func (e *ErrorWrap) LabelValues(ctx context.Context, label string, matchers []string, startTime time.Time, endTime time.Time) (v model.LabelValues, w v1.Warnings, err error)

LabelValues performs a query for the values of the given label.

func (*ErrorWrap) Metadata added in v0.0.84

func (e *ErrorWrap) Metadata(ctx context.Context, metric, limit string) (v map[string][]v1.Metadata, err error)

Metadata returns metadata about metrics currently scraped by the metric name.

func (*ErrorWrap) Query added in v0.0.84

func (e *ErrorWrap) Query(ctx context.Context, query string, ts time.Time) storage.SeriesSet

Query performs a query for the given time.

func (*ErrorWrap) QueryExemplars added in v0.0.94

func (e *ErrorWrap) QueryExemplars(ctx context.Context, query string, startTime, endTime time.Time) (v []v1.ExemplarQueryResult, err error)

QueryExemplars performs a query for exemplars by the given query and time range.

func (*ErrorWrap) QueryRange added in v0.0.84

func (e *ErrorWrap) QueryRange(ctx context.Context, query string, r v1.Range) storage.SeriesSet

QueryRange performs a query for the given range.

func (*ErrorWrap) Series added in v0.0.84

func (e *ErrorWrap) Series(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) (v []model.LabelSet, w v1.Warnings, err error)

Series finds series by label matchers.

type FilterLabelVisitor added in v0.0.77

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

FilterLabel implements the parser.Visitor interface to filter selectors based on a labelstet

func NewFilterLabelVisitor added in v0.0.77

func NewFilterLabelVisitor(filter map[string]map[string]struct{}) *FilterLabelVisitor

func (*FilterLabelVisitor) Visit added in v0.0.77

func (l *FilterLabelVisitor) Visit(node parser.Node, path []parser.Node) (w parser.Visitor, err error)

Visit checks if the given node matches the labels in the filter

type FilterMatcherVisitor added in v0.0.77

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

FilterMatcherVisitor implements the parser.Visitor interface to filter matchers based on a labelstet

func NewFilterMatcherVisitor added in v0.0.77

func NewFilterMatcherVisitor(ls model.LabelSet) *FilterMatcherVisitor

func (*FilterMatcherVisitor) Visit added in v0.0.77

func (l *FilterMatcherVisitor) Visit(node parser.Node, path []parser.Node) (w parser.Visitor, err error)

Visit checks if the given node matches the labels in the filter

type IgnoreErrorAPI

type IgnoreErrorAPI struct {
	A API
}

IgnoreErrorAPI simply swallows all errors from the given API. This allows the API to be used with all the regular error merging logic and effectively have its errors not considered

func (*IgnoreErrorAPI) GetValue

func (n *IgnoreErrorAPI) GetValue(ctx context.Context, start, end time.Time, matchers []*labels.Matcher) storage.SeriesSet

GetValue loads the raw data for a given set of matchers in the time range

func (*IgnoreErrorAPI) Key

func (n *IgnoreErrorAPI) Key() model.LabelSet

Key returns a labelset used to determine other api clients that are the "same"

func (*IgnoreErrorAPI) LabelNames added in v0.0.71

func (n *IgnoreErrorAPI) LabelNames(ctx context.Context, matchers []string, startTime time.Time, endTime time.Time) ([]string, v1.Warnings, error)

LabelNames returns all the unique label names present in the block in sorted order.

func (*IgnoreErrorAPI) LabelValues

func (n *IgnoreErrorAPI) LabelValues(ctx context.Context, label string, matchers []string, startTime time.Time, endTime time.Time) (model.LabelValues, v1.Warnings, error)

LabelValues performs a query for the values of the given label.

func (*IgnoreErrorAPI) Metadata added in v0.0.76

func (n *IgnoreErrorAPI) Metadata(ctx context.Context, metric, limit string) (map[string][]v1.Metadata, error)

Metadata returns metadata about metrics currently scraped by the metric name.

func (*IgnoreErrorAPI) Query

func (n *IgnoreErrorAPI) Query(ctx context.Context, query string, ts time.Time) storage.SeriesSet

Query performs a query for the given time.

func (*IgnoreErrorAPI) QueryExemplars added in v0.0.94

func (n *IgnoreErrorAPI) QueryExemplars(ctx context.Context, query string, startTime, endTime time.Time) ([]v1.ExemplarQueryResult, error)

QueryExemplars performs a query for exemplars by the given query and time range.

func (*IgnoreErrorAPI) QueryRange

func (n *IgnoreErrorAPI) QueryRange(ctx context.Context, query string, r v1.Range) storage.SeriesSet

QueryRange performs a query for the given range.

func (*IgnoreErrorAPI) Series

func (n *IgnoreErrorAPI) Series(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]model.LabelSet, v1.Warnings, error)

Series finds series by label matchers.

type InjectMatchersClient added in v0.0.94

type InjectMatchersClient struct {
	API
	// contains filtered or unexported fields
}

InjectMatchersClient wraps an API and injects a static set of label matchers into every selector of every request sent downstream. This effectively scopes the downstream to the subset of data matching those matchers -- even for queries that never reference the labels being injected (e.g. `count(up)` becomes `count(up{cluster="A"})`).

This differs from the other label mechanisms in promxy:

  • `labels` only *adds* labels to the responses coming back from the downstream
  • `label_filter` only *drops* queries whose matchers can't match the downstream
  • `inject_matchers` always *adds* the configured matchers to the queries themselves

NOTE: this is not a "secure" mechanism. It only mutates the matchers in the request and does not (and cannot) prevent a downstream from returning data outside of the injected scope if the downstream ignores the matchers. As with `label_filter`, a way to use this more securely is to pair it with a trusted label proxy.

func NewInjectMatchersClient added in v0.0.94

func NewInjectMatchersClient(a API, matchers []*labels.Matcher) (*InjectMatchersClient, error)

NewInjectMatchersClient returns an InjectMatchersClient that injects the given matchers into all requests sent to the downstream API.

func (*InjectMatchersClient) GetValue added in v0.0.94

func (c *InjectMatchersClient) GetValue(ctx context.Context, start, end time.Time, matchers []*labels.Matcher) storage.SeriesSet

GetValue loads the raw data for a given set of matchers in the time range

func (*InjectMatchersClient) LabelNames added in v0.0.94

func (c *InjectMatchersClient) LabelNames(ctx context.Context, matchers []string, startTime time.Time, endTime time.Time) ([]string, v1.Warnings, error)

LabelNames returns all the unique label names present in the block in sorted order.

func (*InjectMatchersClient) LabelValues added in v0.0.94

func (c *InjectMatchersClient) LabelValues(ctx context.Context, label string, matchers []string, startTime time.Time, endTime time.Time) (model.LabelValues, v1.Warnings, error)

LabelValues performs a query for the values of the given label.

func (*InjectMatchersClient) Query added in v0.0.94

Query performs a query for the given time.

func (*InjectMatchersClient) QueryRange added in v0.0.94

func (c *InjectMatchersClient) QueryRange(ctx context.Context, query string, r v1.Range) storage.SeriesSet

QueryRange performs a query for the given range.

func (*InjectMatchersClient) Series added in v0.0.94

func (c *InjectMatchersClient) Series(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]model.LabelSet, v1.Warnings, error)

Series finds series by label matchers.

type LabelFilterClient added in v0.0.77

type LabelFilterClient struct {
	API
	// contains filtered or unexported fields
}

LabelFilterClient filters out calls to the downstream based on a label filter which is pulled and maintained from the downstream API.

func NewLabelFilterClient added in v0.0.77

func NewLabelFilterClient(ctx context.Context, a API, cfg *LabelFilterConfig) (*LabelFilterClient, error)

NewLabelFilterClient returns a LabelFilterClient which will filter the queries sent downstream based on a filter of labels maintained in memory from the downstream API.

func (*LabelFilterClient) GetValue added in v0.0.77

func (c *LabelFilterClient) GetValue(ctx context.Context, start, end time.Time, matchers []*labels.Matcher) storage.SeriesSet

GetValue loads the raw data for a given set of matchers in the time range

func (*LabelFilterClient) LabelFilter added in v0.0.77

func (c *LabelFilterClient) LabelFilter() map[string]map[string]struct{}

State returns the current ServerGroupState

func (*LabelFilterClient) Metadata added in v0.0.77

func (c *LabelFilterClient) Metadata(ctx context.Context, metric, limit string) (map[string][]v1.Metadata, error)

Metadata returns metadata about metrics currently scraped by the metric name.

func (*LabelFilterClient) Query added in v0.0.77

func (c *LabelFilterClient) Query(ctx context.Context, query string, ts time.Time) storage.SeriesSet

Query performs a query for the given time.

func (*LabelFilterClient) QueryExemplars added in v0.0.94

func (c *LabelFilterClient) QueryExemplars(ctx context.Context, query string, startTime, endTime time.Time) ([]v1.ExemplarQueryResult, error)

QueryExemplars performs a query for exemplars by the given query and time range. Mirrors the matcher-filter logic used by Series / GetValue: parse the query, extract every vector selector, and skip the downstream call when every selector references labels this server-group can't satisfy. A query that mixes a satisfiable selector with a non-satisfiable one is still forwarded (we can't easily rewrite a PromQL string) — the non-satisfiable side just returns no exemplars.

func (*LabelFilterClient) QueryRange added in v0.0.77

func (c *LabelFilterClient) QueryRange(ctx context.Context, query string, r v1.Range) storage.SeriesSet

QueryRange performs a query for the given range.

func (*LabelFilterClient) Series added in v0.0.77

func (c *LabelFilterClient) Series(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]model.LabelSet, v1.Warnings, error)

Series finds series by label matchers.

func (*LabelFilterClient) Sync added in v0.0.77

func (c *LabelFilterClient) Sync(ctx context.Context) error

type LabelFilterConfig added in v0.0.77

type LabelFilterConfig struct {
	// DynamicLabels is a list of labels to dynamically maintain a filter from the downstream from
	DynamicLabels []string `yaml:"dynamic_labels"`
	// SyncInterval defines how frequenlty to update the dynamic label filter
	SyncInterval time.Duration `yaml:"sync_interval"`
	// StaticLabelsInclude is a set of labels to always add to the downstream filter
	// this allows you to define some metrics to be included statically if you want to
	// avoid polling the downstream.
	// NOTE: this is not a "secure" measure as this entire label_filter is based on matchers
	// and as such doesn't restrict which metrics they touch (e.g. if you restrict by `__name__`
	// the could just query by another label).
	StaticLabelsInclude map[string][]string `yaml:"static_labels_include"`
	// StaticLabelsExclude is a set of labels to always exclude from the filter. This is done last
	// so it will apply after the dynamic and static lists are added to the filter.
	StaticLabelsExclude map[string][]string `yaml:"static_labels_exclude"`
	// OnSyncError controls behavior while the filter has never successfully synced
	// from the downstream (e.g. the target is unreachable at startup). This is
	// distinct from the servergroup's `ignore_error`, which governs the query path.
	//   abort  - fail the sync; this blocks servergroup startup until a sync
	//            succeeds (default; preserves historical behavior)
	//   open   - proceed without filtering; all queries are sent downstream until
	//            the first successful sync
	//   closed - proceed but filter out everything (skip this target) until the
	//            first successful sync
	OnSyncError LabelFilterOnSyncError `yaml:"on_sync_error"`
}

LabelFilterConfig is the configuration for the LabelFilterClient

func (*LabelFilterConfig) UnmarshalYAML added in v0.0.77

func (c *LabelFilterConfig) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

func (*LabelFilterConfig) Validate added in v0.0.77

func (c *LabelFilterConfig) Validate() error

type LabelFilterOnSyncError added in v0.0.96

type LabelFilterOnSyncError string

LabelFilterOnSyncError defines what a LabelFilterClient does while it has never successfully synced its filter from the downstream (e.g. the target is unreachable when promxy starts up).

const (
	// LabelFilterOnSyncErrorAbort fails the initial sync, which propagates up to
	// the servergroup and blocks startup until a sync succeeds. This preserves
	// the historical behavior and is the default.
	LabelFilterOnSyncErrorAbort LabelFilterOnSyncError = "abort"
	// LabelFilterOnSyncErrorOpen lets startup proceed and sends all queries
	// downstream (i.e. no filtering) until the first successful sync.
	LabelFilterOnSyncErrorOpen LabelFilterOnSyncError = "open"
	// LabelFilterOnSyncErrorClosed lets startup proceed but filters out every
	// query (i.e. the target is skipped) until the first successful sync.
	LabelFilterOnSyncErrorClosed LabelFilterOnSyncError = "closed"
)

type MetricRelabelConfig added in v0.0.76

type MetricRelabelConfig struct {
	SourceLabel model.LabelName `yaml:"source_label,flow,omitempty"`
	TargetLabel string          `yaml:"target_label,omitempty"`
	// Actions must either (a) not modify the LabelName or (b) be reversible as we need
	// to modify query/matchers appropriately
	// As such we only support:
	// - replace
	// - labeldrop
	// - lowercase
	// - uppercase
	Action relabel.Action `yaml:"action,omitempty"`
}

MetricRelabelConfig defines relabeling to be done *in-client*. This is a significantly constrained version of relabeling (as compared to prometheus ingestion) as these all need to be reversible -- as we need to adjust queries on-the-fly

func (*MetricRelabelConfig) ToRelabelConfig added in v0.0.76

func (c *MetricRelabelConfig) ToRelabelConfig() (*relabel.Config, error)

ToRelabelConfig simply converts our simplified relabel configuration into the equivalent prometheus relabel config. This is a good method to see exactly how these are mapped over.

func (*MetricRelabelConfig) UnmarshalYAML added in v0.0.76

func (c *MetricRelabelConfig) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

func (*MetricRelabelConfig) Validate added in v0.0.76

func (c *MetricRelabelConfig) Validate() error

type MetricsRelabelClient added in v0.0.76

type MetricsRelabelClient struct {
	API
	MetricsRelabelConfigs []*MetricRelabelConfig
	RelabelConfigs        []*relabel.Config
}

MetricsRelabelClient

func NewMetricsRelabelClient added in v0.0.76

func NewMetricsRelabelClient(a API, cfgs []*MetricRelabelConfig) (*MetricsRelabelClient, error)

NewMetricsRelabelClient returns a new MetricsRelabelClient which will intercept and rewrite queries

func (*MetricsRelabelClient) GetValue added in v0.0.76

func (c *MetricsRelabelClient) GetValue(ctx context.Context, start, end time.Time, matchers []*labels.Matcher) storage.SeriesSet

GetValue loads the raw data for a given set of matchers in the time range

func (*MetricsRelabelClient) LabelNames added in v0.0.76

func (c *MetricsRelabelClient) LabelNames(ctx context.Context, matchers []string, startTime time.Time, endTime time.Time) ([]string, v1.Warnings, error)

LabelNames returns all the unique label names present in the block in sorted order.

func (*MetricsRelabelClient) Query added in v0.0.76

Query performs a query for the given time.

func (*MetricsRelabelClient) QueryExemplars added in v0.0.94

func (c *MetricsRelabelClient) QueryExemplars(ctx context.Context, query string, startTime, endTime time.Time) ([]v1.ExemplarQueryResult, error)

QueryExemplars performs a query for exemplars by the given query and time range. We pass the query through unmodified — rewriting selectors inside an arbitrary PromQL expression is non-trivial — and apply the configured relabel rules to each result's SeriesLabels so caller-side labels match the rewritten metric names.

func (*MetricsRelabelClient) QueryRange added in v0.0.76

func (c *MetricsRelabelClient) QueryRange(ctx context.Context, query string, r v1.Range) storage.SeriesSet

QueryRange performs a query for the given range.

func (*MetricsRelabelClient) Series added in v0.0.76

func (c *MetricsRelabelClient) Series(ctx context.Context, matchers []string, startTime time.Time, endTime time.Time) ([]model.LabelSet, v1.Warnings, error)

Series finds series by label matchers.

type MetricsRelabelVisitor added in v0.0.76

type MetricsRelabelVisitor struct {
	MetricsRelabelConfigs []*MetricRelabelConfig
	RelabelConfigs        []*relabel.Config
	// contains filtered or unexported fields
}

MetricsRelabelVisitor implements the parser.Visitor interface to replace the labels

func NewMetricsRelabelVisitor added in v0.0.76

func NewMetricsRelabelVisitor(m []*MetricRelabelConfig, r []*relabel.Config) *MetricsRelabelVisitor

func (*MetricsRelabelVisitor) Visit added in v0.0.76

func (v *MetricsRelabelVisitor) Visit(node parser.Node, path []parser.Node) (w parser.Visitor, err error)

type MultiAPI

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

MultiAPI implements the API interface while merging the results from the apis it wraps

func NewMultiAPI

func NewMultiAPI(apis []API, antiAffinity model.Time, antiAffinityDynamic bool, metricFunc MultiAPIMetricFunc, requiredCount int, preferMax bool) (*MultiAPI, error)

NewMultiAPI returns a MultiAPI. When antiAffinityDynamic is true, MergeSampleStream infers the per-series anti-affinity from the inter- sample spacing of the data, using antiAffinity only as a fallback when too few samples are present to estimate. This lets a single server- group host series with mixed scrape intervals without forcing one global buffer that's wrong for half the metrics. See #734.

func NewMustMultiAPI added in v0.0.76

func NewMustMultiAPI(apis []API, antiAffinity model.Time, antiAffinityDynamic bool, metricFunc MultiAPIMetricFunc, requiredCount int, preferMax bool) *MultiAPI

NewMustMultiAPI returns a MultiAPI

func (*MultiAPI) GetValue

func (m *MultiAPI) GetValue(ctx context.Context, start, end time.Time, matchers []*labels.Matcher) storage.SeriesSet

GetValue fetches the raw collected data, merged across HA members.

func (*MultiAPI) LabelNames

func (m *MultiAPI) LabelNames(ctx context.Context, matchers []string, startTime time.Time, endTime time.Time) ([]string, v1.Warnings, error)

LabelNames returns all the unique label names present in the block in sorted order.

func (*MultiAPI) LabelValues

func (m *MultiAPI) LabelValues(ctx context.Context, label string, matchers []string, startTime time.Time, endTime time.Time) (model.LabelValues, v1.Warnings, error)

LabelValues performs a query for the values of the given label.

func (*MultiAPI) Metadata added in v0.0.76

func (m *MultiAPI) Metadata(ctx context.Context, metric, limit string) (map[string][]v1.Metadata, error)

Metadata returns metadata about metrics currently scraped by the metric name.

func (*MultiAPI) Query

func (m *MultiAPI) Query(ctx context.Context, query string, ts time.Time) storage.SeriesSet

func (*MultiAPI) QueryExemplars added in v0.0.94

func (m *MultiAPI) QueryExemplars(ctx context.Context, query string, startTime, endTime time.Time) ([]v1.ExemplarQueryResult, error)

QueryExemplars performs a query for exemplars by the given query and time range. We fan the query out to every server-group and concatenate the per-series exemplar lists, deduplicating by series labels (sum-style merge — the union of exemplars from all server-groups for the same series).

func (*MultiAPI) QueryRange

func (m *MultiAPI) QueryRange(ctx context.Context, query string, r v1.Range) storage.SeriesSet

QueryRange performs a query for the given range.

func (*MultiAPI) Series

func (m *MultiAPI) Series(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]model.LabelSet, v1.Warnings, error)

Series finds series by label matchers.

type MultiAPIMetricFunc

type MultiAPIMetricFunc func(i int, api, status string, took float64)

MultiAPIMetricFunc defines a method where a client can record metrics about the specific API calls made through this multi client

type MultiVisitor added in v0.0.92

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

MultiVisitor runs a set of visitors on the same pass over the node tree

func NewMultiVisitor added in v0.0.92

func NewMultiVisitor(visitors []parser.Visitor) *MultiVisitor

NewMultiVisitor takes a set of visitors and returns a MultiVisitor

func (*MultiVisitor) Visit added in v0.0.92

func (v *MultiVisitor) Visit(node parser.Node, path []parser.Node) (parser.Visitor, error)

Visit runs on each node in the tree

type OffsetFinder added in v0.0.92

type OffsetFinder struct {
	Found  bool
	Offset time.Duration
	Error  error
	// contains filtered or unexported fields
}

OffsetFinder finds the offset (if any) within the tree

func (*OffsetFinder) Visit added in v0.0.92

func (o *OffsetFinder) Visit(node parser.Node, path []parser.Node) (parser.Visitor, error)

Visit runs on each node in the tree

type OffsetRemover added in v0.0.92

type OffsetRemover struct{}

OffsetRemover removes any offset found in the node tree This is required when we send the queries below as we want to actually *remove* the offset.

func (*OffsetRemover) Visit added in v0.0.92

func (o *OffsetRemover) Visit(node parser.Node, _ []parser.Node) (parser.Visitor, error)

Visit runs on each node in the tree

type PromAPIRemoteRead

type PromAPIRemoteRead struct {
	API
	remote.ReadClient
}

PromAPIRemoteRead implements our internal API interface using a combination of the v1 HTTP API and the "experimental" remote_read API

func (*PromAPIRemoteRead) GetValue

func (p *PromAPIRemoteRead) GetValue(ctx context.Context, start, end time.Time, matchers []*labels.Matcher) storage.SeriesSet

GetValue loads the raw data for a given set of matchers in the time range

type PromAPIV1

type PromAPIV1 struct {
	v1.API
	Client api.Client
}

PromAPIV1 implements our internal API interface using *only* the v1 HTTP API Simply wraps the prom API to fullfil our internal API interface.

Client is the underlying api.Client used for Query / QueryRange. It is set when a PromAPIV1 is constructed against a real downstream so that we can parse the `infos` field of the JSON response (which client_golang's v1 package drops). Query / QueryRange fall back to the embedded v1.API if Client is nil — that path is used by tests that supply a stub v1.API directly.

func (*PromAPIV1) GetValue

func (p *PromAPIV1) GetValue(ctx context.Context, start, end time.Time, matchers []*labels.Matcher) storage.SeriesSet

GetValue loads the raw data for a given set of matchers in the time range

func (*PromAPIV1) LabelNames added in v0.0.63

func (p *PromAPIV1) LabelNames(ctx context.Context, matchers []string, startTime time.Time, endTime time.Time) ([]string, v1.Warnings, error)

LabelNames returns all the unique label names present in the block in sorted order.

func (*PromAPIV1) LabelValues added in v0.0.63

func (p *PromAPIV1) LabelValues(ctx context.Context, label string, matchers []string, startTime time.Time, endTime time.Time) (model.LabelValues, v1.Warnings, error)

LabelValues performs a query for the values of the given label.

func (*PromAPIV1) Query added in v0.0.78

func (p *PromAPIV1) Query(ctx context.Context, query string, ts time.Time) storage.SeriesSet

Query performs a query for the given time.

func (*PromAPIV1) QueryExemplars added in v0.0.94

func (p *PromAPIV1) QueryExemplars(ctx context.Context, query string, startTime, endTime time.Time) ([]v1.ExemplarQueryResult, error)

QueryExemplars performs a query for exemplars by the given query and time range.

func (*PromAPIV1) QueryRange added in v0.0.78

func (p *PromAPIV1) QueryRange(ctx context.Context, query string, r v1.Range) storage.SeriesSet

QueryRange performs a query for the given range.

func (*PromAPIV1) Series added in v0.0.78

func (p *PromAPIV1) Series(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]model.LabelSet, v1.Warnings, error)

Series finds series by label matchers.

type RelativeTimeFilter

type RelativeTimeFilter struct {
	API
	Start, End *time.Duration
	Truncate   bool
}

RelativeTimeFilter will filter queries out (return nil,nil) for all queries outside the given durations relative to time.Now()

func (*RelativeTimeFilter) GetValue

func (tf *RelativeTimeFilter) GetValue(ctx context.Context, start, end time.Time, matchers []*labels.Matcher) storage.SeriesSet

GetValue loads the raw data for a given set of matchers in the time range

func (*RelativeTimeFilter) LabelNames added in v0.0.79

func (tf *RelativeTimeFilter) LabelNames(ctx context.Context, matchers []string, startTime time.Time, endTime time.Time) ([]string, v1.Warnings, error)

LabelNames returns all the unique label names present in the block in sorted order.

func (*RelativeTimeFilter) LabelValues added in v0.0.79

func (tf *RelativeTimeFilter) LabelValues(ctx context.Context, label string, matchers []string, startTime time.Time, endTime time.Time) (model.LabelValues, v1.Warnings, error)

LabelValues performs a query for the values of the given label.

func (*RelativeTimeFilter) Query

func (tf *RelativeTimeFilter) Query(ctx context.Context, query string, ts time.Time) storage.SeriesSet

Query performs a query for the given time.

func (*RelativeTimeFilter) QueryExemplars added in v0.0.94

func (tf *RelativeTimeFilter) QueryExemplars(ctx context.Context, query string, startTime, endTime time.Time) ([]v1.ExemplarQueryResult, error)

QueryExemplars performs a query for exemplars by the given query and time range.

func (*RelativeTimeFilter) QueryRange

func (tf *RelativeTimeFilter) QueryRange(ctx context.Context, query string, r v1.Range) storage.SeriesSet

QueryRange performs a query for the given range.

func (*RelativeTimeFilter) Series

func (tf *RelativeTimeFilter) Series(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]model.LabelSet, v1.Warnings, error)

Series finds series by label matchers.

type StepAlignClient added in v0.0.95

type StepAlignClient struct {
	API
}

StepAlignClient re-stamps QueryRange sample timestamps from the epoch step grid (k*step, as returned by step-aligning backends such as Mimir/Cortex) onto the grid implied by the request start (start + j*step). It is meant to be enabled per-server-group, only for backends that actually snap query_range results to the epoch grid.

The shift is purely additive: r = start mod step, applied forward (+r), so a sample the backend computed at k*step is reported at the next requested grid point k*step + r. Forward-only (never backward) keeps it causal -- we never surface a value as of a time later than the timestamp it is reported at.

Why this is the right reference frame: promxy pushes each leaf selector down as a QueryRange with Start = evalStart - offset, then the local engine looks the returned samples back up at (evalGrid - offset) == this request's Start grid. So aligning the output to r.Start's phase is exactly what the engine expects, regardless of any query offset.

func (*StepAlignClient) QueryRange added in v0.0.95

func (c *StepAlignClient) QueryRange(ctx context.Context, query string, r v1.Range) storage.SeriesSet

QueryRange performs a query for the given range, re-stamping the returned samples onto the request's start+step grid. It is a no-op when the request is already on the grid (start % step == 0) or the step is non-positive.

type TimeTruncate added in v0.0.49

type TimeTruncate struct {
	API
}

TimeTruncate is a workaround to https://github.com/jacksontj/promxy/issues/212 context: https://github.com/prometheus/prometheus/issues/5972 For now we need to truncate the time so that prometheus doesn't round up and return no data <= the timestamp we requested

func NewTimeTruncate added in v0.0.49

func NewTimeTruncate(a API) *TimeTruncate

NewTimeTruncate returns a new TimeTruncate client -- which will truncate the time to the millisecond.

func (*TimeTruncate) GetValue added in v0.0.49

func (t *TimeTruncate) GetValue(ctx context.Context, start, end time.Time, matchers []*labels.Matcher) storage.SeriesSet

GetValue loads the raw data for a given set of matchers in the time range

func (*TimeTruncate) Query added in v0.0.49

func (t *TimeTruncate) Query(ctx context.Context, query string, ts time.Time) storage.SeriesSet

Query performs a query for the given time.

func (*TimeTruncate) QueryExemplars added in v0.0.94

func (t *TimeTruncate) QueryExemplars(ctx context.Context, query string, startTime, endTime time.Time) ([]v1.ExemplarQueryResult, error)

QueryExemplars performs a query for exemplars by the given query and time range.

func (*TimeTruncate) QueryRange added in v0.0.49

func (t *TimeTruncate) QueryRange(ctx context.Context, query string, r v1.Range) storage.SeriesSet

QueryRange performs a query for the given range.

func (*TimeTruncate) Series added in v0.0.49

func (t *TimeTruncate) Series(ctx context.Context, matches []string, startTime time.Time, endTime time.Time) ([]model.LabelSet, v1.Warnings, error)

Series finds series by label matchers.

type TimestampFinder added in v0.0.94

type TimestampFinder struct {
	Found     bool
	Timestamp int64
	// contains filtered or unexported fields
}

TimestampFinder records the first @-modifier timestamp it encounters on a VectorSelector / MatrixSelector / SubqueryExpr in the subtree. Found is set once a timestamp is captured; subsequent matches are ignored. Used by the NodeReplacer when subtreeHasAt is true: knowing one safe pinning timestamp lets us issue an instant query rather than a range query whose start may land on a pre-epoch sub-second time and trip the upstream prometheus/common Time.UnmarshalJSON bug.

func (*TimestampFinder) Visit added in v0.0.94

func (f *TimestampFinder) Visit(node parser.Node, _ []parser.Node) (parser.Visitor, error)

Visit runs on each node in the tree.

Jump to

Keyboard shortcuts

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