promclient

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package promclient is a small read-only client for a Prometheus-compatible query API.

It exists so the hub's notification queries and the worker's sandbox-metrics endpoint share one implementation. Two copies of "parse a Prometheus result vector" would drift, and the second copy is where the subtle bugs live — a value arriving as a string rather than a number, a partial response, an empty vector that means "no data" rather than "zero".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrNotConfigured

func ErrNotConfigured() error

ErrNotConfigured reports that no endpoint has been set.

Types

type Client

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

Client queries a Prometheus-compatible API.

The configuration is swappable at runtime because it arrives on the cluster-config stream: the endpoint and its credential are pushed from the hub rather than baked into a flag, so a rotation reaches every worker without a restart.

func New

func New(cfg Config) *Client

New returns a Client. An empty BaseURL leaves it unconfigured, which callers must check with Ready before querying.

func (*Client) Query

func (c *Client) Query(ctx context.Context, promql string, at time.Time) ([]Series, error)

Query runs an instant query and returns every series in the result vector.

func (*Client) QueryRange

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

QueryRange runs a range query over [start, end] at the given step.

func (*Client) Ready

func (c *Client) Ready() bool

Ready reports whether an endpoint has been configured.

func (*Client) SetConfig

func (c *Client) SetConfig(cfg Config)

SetConfig replaces the endpoint and credentials. Safe to call concurrently with queries.

type Config

type Config struct {
	// BaseURL is the query root, e.g. https://obs.example.com/api/query/metrics
	// (the /api/v1/... paths are appended to it).
	BaseURL string
	// Headers are sent with every request; this is where an Authorization
	// bearer belongs.
	Headers map[string]string
	// Timeout bounds a single query. Zero uses a sane default.
	Timeout time.Duration
}

Config addresses a Prometheus-compatible query API.

type Sample

type Sample struct {
	At    time.Time
	Value float64
}

Sample is one point of a result series.

type Series

type Series struct {
	Labels  map[string]string
	Samples []Sample
}

Series is one labelled result series.

Jump to

Keyboard shortcuts

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