http

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package http is the HTTP backend of the Prometheus querier: instant queries reduced to one sample, and range queries reduced to one series, over a Prometheus server's HTTP query API. Both fail closed: a result that is not exactly one finite value (or one series of them) is an error, never a silent zero.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client queries the Prometheus server at its base URL.

func New

func New(baseURL string, doer HTTPDoer) *Client

New builds the client for the Prometheus server at baseURL (e.g. the in-cluster service address), sending requests through doer.

func (*Client) Query

func (c *Client) Query(ctx context.Context, promql string) (float64, error)

Query evaluates promql as an instant query and returns its single sample value. No sample, several series, or a NaN or infinite value is an error: a value that can't be measured is never reported as 0.

func (*Client) QueryRange

func (c *Client) QueryRange(
	ctx context.Context,
	promql string,
	start, end time.Time,
	step time.Duration,
) ([]Sample, error)

QueryRange evaluates promql over [start, end] at step and returns its single series. No series is an empty series (nothing was recorded in the window); several series or a NaN or infinite sample is an error.

type Config

type Config struct {
	// BaseURL is the Prometheus server root (e.g. its in-cluster service address);
	// required.
	BaseURL string `yaml:"base_url" mapstructure:"base_url"`

	// Timeout is the http.Client timeout: it bounds each HTTP attempt, response body
	// included, even with the client resilience disabled; zero means no transport
	// bound.
	Timeout time.Duration `yaml:"timeout" mapstructure:"timeout"`

	// MaxBodyBytes caps a response body the backend buffers; a larger one is
	// CodeInvalidInput. Zero or less means no cap.
	MaxBodyBytes int64 `yaml:"max_body_bytes" mapstructure:"max_body_bytes"`
}

Config configures the HTTP backend.

type HTTPDoer

type HTTPDoer interface {
	// Do sends req and returns its response (the caller closes its body).
	Do(req *nethttp.Request) (*nethttp.Response, error)
}

HTTPDoer is the HTTP boundary the client sends its requests through.

SDK seam — matches *nethttp.Client's Do, the stdlib HTTP transport boundary; it types the wire call, not a port, so it cannot compose with a core interface.

func DecorateDoer

func DecorateDoer(
	inner HTTPDoer,
	c client.Base,
	maxBodyBytes int64,
) HTTPDoer

DecorateDoer runs every request inner sends through the client tier (c), as the operation "prometheus.<last path segment>" (prometheus.query, prometheus.query_range).

Each attempt reads the whole response body before the tier's per-attempt timeout ends, so the returned body is buffered and the deadline cannot cut a read short. A body larger than maxBodyBytes is CodeInvalidInput (narrow the query); zero or less means no limit.

Query requests are GETs, so every attempt is retryable. A transport error keeps a code it already carries; otherwise the caller's deadline is CodeTimeout, its cancellation CodeCanceled, and any other failure CodeUnavailable. A throttling or unavailable status (429, 502, 503, 504) is a CodeUnavailable error, so the tier retries it and its breaker counts it. Any other status passes through for the client to code.

type Sample

type Sample = types.MetricSample

Sample is one point of a range-query series.

Jump to

Keyboard shortcuts

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