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 ¶
- func DecodeSeriesSet(body []byte) storage.SeriesSet
- func FloatSample(t int64, v float64) chunks.Sample
- func HistogramSample(t int64, fh *histogram.FloatHistogram) chunks.Sample
- func NewSeries(lbls labels.Labels, samples []chunks.Sample) storage.Series
- type Client
- func (c *Client) LabelNames(ctx context.Context, matchers []*labels.Matcher, start, end time.Time) ([]string, annotations.Annotations, error)
- func (c *Client) LabelValues(ctx context.Context, label string, matchers []*labels.Matcher, ...) ([]string, annotations.Annotations, error)
- func (c *Client) Metadata(ctx context.Context, metric, limit string) (map[string][]Metadata, error)
- func (c *Client) Query(ctx context.Context, query string, ts time.Time) storage.SeriesSet
- func (c *Client) QueryRange(ctx context.Context, query string, r Range) storage.SeriesSet
- func (c *Client) Select(ctx context.Context, start, end time.Time, matchers ...*labels.Matcher) storage.SeriesSet
- func (c *Client) Series(ctx context.Context, matchers []*labels.Matcher, start, end time.Time) ([]labels.Labels, annotations.Annotations, error)
- type Metadata
- type Range
- type ResponseError
- type SeriesSet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeSeriesSet ¶
DecodeSeriesSet streams an API response body into a storage.SeriesSet.
func FloatSample ¶
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 ¶
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 ¶
Metadata returns metric metadata, optionally limited to a metric and/or count.
func (*Client) QueryRange ¶
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).
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 ResponseError ¶
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) Warnings ¶
func (s *SeriesSet) Warnings() annotations.Annotations