Documentation
¶
Overview ¶
Package prometheus is the client for a Prometheus server's HTTP query API: instant queries reduced to one sample, and range queries reduced to one series. Both fail closed: a result that is not exactly one finite value (or one series of them) is an error, never a silent zero. NewFromConfig picks the backend: the zero-infrastructure stub (the default) or the HTTP client, its transport wrapped in the client stack.
Index ¶
Constants ¶
const DefaultMaxBodyBytes int64 = 32 << 20
DefaultMaxBodyBytes is DefaultConfig's response-body cap (32 MiB).
Variables ¶
This section is empty.
Functions ¶
func NewFromConfig ¶
func NewFromConfig(cfg Config, deps clientdecorators.Deps) (interfaces.MetricsQuerier, error)
NewFromConfig builds the querier cfg selects, without I/O. The HTTP kind sends through an http.Client bounded by cfg.Timeout and wrapped (DecorateDoer) in the client stack built from cfg.Resilience and deps, capping bodies at cfg.MaxBodyBytes. An unknown kind, or KindHTTP without a BaseURL, is CodeInvalidInput.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client queries the Prometheus server at its base URL.
func New ¶
New builds the client for the Prometheus server at baseURL (e.g. the in-cluster service address), sending requests through doer.
func (*Client) Query ¶
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 for KindHTTP.
BaseURL string `yaml:"base_url" mapstructure:"base_url"`
// Resilience tunes the client stack around each HTTP request.
Resilience clientdecorators.Config `yaml:"resilience" mapstructure:"resilience"`
// Timeout is the http.Client timeout: it bounds each HTTP attempt, response body
// included, even with the client stack disabled; zero means no transport bound.
Timeout time.Duration `yaml:"timeout" mapstructure:"timeout"`
// MaxBodyBytes caps a response body the HTTP kind buffers; a larger one is
// CodeInvalidInput. Zero or less means no cap.
MaxBodyBytes int64 `yaml:"max_body_bytes" mapstructure:"max_body_bytes"`
// Kind selects the backend.
Kind Kind `yaml:"kind" mapstructure:"kind"`
}
Config selects and configures the metrics querier.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the stub kind, a 30-second request timeout, a 32 MiB body cap and the default client stack.
type HTTPDoer ¶
type HTTPDoer interface {
// Do sends req and returns its response (the caller closes its body).
Do(req *http.Request) (*http.Response, error)
}
HTTPDoer is the HTTP boundary the client sends its requests through.
SDK seam — matches *http.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, stack *clientdecorators.Stack, maxBodyBytes int64) HTTPDoer
DecorateDoer runs every request inner sends through the client stack, as the operation "prometheus.<last path segment>" (prometheus.query, prometheus.query_range).
Each attempt reads the whole response body before the stack'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 stack retries it and its breaker counts it. Any other status passes through for the client to code.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package stub is the zero-infrastructure metrics querier: every instant query is 0 and every range query an empty series, with no network I/O.
|
Package stub is the zero-infrastructure metrics querier: every instant query is 0 and every range query an empty series, with no network I/O. |