promapi

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: 21 Imported by: 0

Documentation

Overview

Package promapi is a small, standalone Prometheus HTTP API query client that decodes responses straight into storage.SeriesSet (via DecodeSeriesSet), avoiding client_golang's model.Value intermediate. It depends only on prometheus's storage/labels/model packages, so it is reusable on its own and composes with the prometheus storage ecosystem.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeSeriesSet

func DecodeSeriesSet(body []byte) storage.SeriesSet

DecodeSeriesSet streams an API response body into a storage.SeriesSet.

func FloatSample

func FloatSample(t int64, v float64) chunks.Sample

FloatSample and HistogramSample expose the package's chunks.Sample implementations so other packages (e.g. promxy's HA merge) can build storage.Series without re-deriving sample types.

func HistogramSample

func HistogramSample(t int64, fh *histogram.FloatHistogram) chunks.Sample

func NewSeries

func NewSeries(lbls labels.Labels, samples []chunks.Sample) storage.Series

NewSeries builds a storage.Series whose float-histogram reads are defensively copied (via storage.NewListSeriesIteratorWithCopy). The plain storage.NewListSeries hands back the stored *FloatHistogram pointer, so a caller (e.g. the PromQL engine) that reuses a hint across samples can observe aliased histograms when the same histogram repeats; copy-on-read prevents that while leaving float reads zero-copy.

Types

type Client

type Client struct {
	// URL is the base URL of the server (e.g. https://prom:9090).
	URL *url.URL
	// HTTPClient is the transport; nil uses http.DefaultClient.
	HTTPClient *http.Client
}

Client queries a single Prometheus-compatible HTTP API. The transport (TLS, auth, timeouts, ...) is supplied via HTTPClient, so callers control exactly how requests are made.

func (*Client) LabelNames

func (c *Client) LabelNames(ctx context.Context, matchers []*labels.Matcher, start, end time.Time) ([]string, annotations.Annotations, error)

LabelNames returns label names matching the matchers over [start, end].

func (*Client) LabelValues

func (c *Client) LabelValues(ctx context.Context, label string, matchers []*labels.Matcher, start, end time.Time) ([]string, annotations.Annotations, error)

LabelValues returns the values of label matching the matchers over [start, end].

func (*Client) Metadata

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

Metadata returns metric metadata, optionally limited to a metric and/or count.

func (*Client) Query

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

Query runs an instant query at ts (zero ts means "now", server-evaluated).

func (*Client) QueryRange

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

QueryRange runs a range query.

func (*Client) Select

func (c *Client) Select(ctx context.Context, start, end time.Time, matchers ...*labels.Matcher) storage.SeriesSet

Select fetches the raw series matching the matchers over [start, end]. It is implemented as an instant query over a range selector, returning every stored sample in the window (the shape promxy's storage layer needs).

func (*Client) Series

func (c *Client) Series(ctx context.Context, matchers []*labels.Matcher, start, end time.Time) ([]labels.Labels, annotations.Annotations, error)

Series returns the label sets of series matching the matchers over [start, end].

type Metadata

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

Metadata is a single metric metadata entry.

type Range

type Range struct {
	Start time.Time
	End   time.Time
	Step  time.Duration
}

Range is the [start, end] window with a resolution step for QueryRange.

type ResponseError

type ResponseError struct {
	Type string
	Msg  string
}

ResponseError is a downstream API error (a status:"error" body or a malformed response). It carries the API errorType and message but, unlike client_golang's v1.Error, adds no client_golang dependency -- keeping this decoder a standalone, reusable unit (and a step toward dropping client_golang entirely).

func (*ResponseError) Error

func (e *ResponseError) Error() string

type SeriesSet

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

SeriesSet is a minimal in-memory storage.SeriesSet carrying series, warnings and an error. It is the one reusable list-SeriesSet for promxy.

TODO(seriesset-refactor): pkg/proxyquerier has an identical type; once the query path returns this directly, delete proxyquerier's copy and use this.

func NewSeriesSet

func NewSeriesSet(series []storage.Series, warnings annotations.Annotations, err error) *SeriesSet

NewSeriesSet returns a storage.SeriesSet over the given series.

func (*SeriesSet) At

func (s *SeriesSet) At() storage.Series

func (*SeriesSet) Err

func (s *SeriesSet) Err() error

func (*SeriesSet) Next

func (s *SeriesSet) Next() bool

func (*SeriesSet) Warnings

func (s *SeriesSet) Warnings() annotations.Annotations

Jump to

Keyboard shortcuts

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