prometheus

package
v1.1.36-test Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package prometheus builds authenticated clients for the Prometheus HTTP API (Mimir, metrics-query, ...) and normalizes the values they answer with.

Index

Constants

View Source
const TenantHeader = "X-Scope-OrgID"

TenantHeader is the header Mimir reads the tenant from.

Variables

This section is empty.

Functions

func InstantVector

func InstantVector(value promModel.Value, at promModel.Time) (promModel.Vector, error)

InstantVector reduces whatever an instant query answered with to the vector the caller asked for. The prometheus API contract says an instant query returns a vector, but the query path in front of it does not always agree: a matrix comes back for the same query often enough that treating it as unusable meters those orgs at zero, silently, for the hour.

A matrix is the same answer with its history attached, so the sample to take is each series' last one at or before the instant — exactly what the vector would have held.

func NewApi

func NewApi(endpoint, bearerToken string) (v1.API, error)

NewApi returns a Prometheus v1 API client for endpoint that authenticates with bearerToken.

func NewApiWithHeaders

func NewApiWithHeaders(endpoint string, headers map[string]string) (v1.API, error)

NewApiWithHeaders returns a Prometheus v1 API client for endpoint that sends headers on every request.

func NewTenantApi

func NewTenantApi(endpoint, tenant string) (v1.API, error)

NewTenantApi returns a client for a Mimir endpoint that reads from one tenant. It is meant for in-cluster endpoints that do not require authentication (the query-frontend's direct port); a public front door such as metrics-query derives the tenant from the query instead.

Types

type BearerTransport

type BearerTransport struct {
	Token string
	Next  http.RoundTripper
}

BearerTransport adds a bearer token to every request it forwards. An empty token sends the request through untouched.

func (*BearerTransport) RoundTrip

func (t *BearerTransport) RoundTrip(req *http.Request) (*http.Response, error)

type HeaderTransport

type HeaderTransport struct {
	Headers map[string]string
	Next    http.RoundTripper
}

HeaderTransport sets fixed headers on every request it forwards.

func (*HeaderTransport) RoundTrip

func (t *HeaderTransport) RoundTrip(req *http.Request) (*http.Response, error)

Jump to

Keyboard shortcuts

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