federate

package
v0.0.96 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package federate provides a fast /federate handler for promxy.

It is a drop-in replacement for the vendored Prometheus federation handler for the common case (text/plain exposition of float samples), avoiding the per-request dto.MetricFamily tree and the encode-time name re-validation that dominate federation CPU/allocations (issue #784). For any other negotiated format (protobuf, OpenMetrics) -- and thus for native histograms, which are only servable over those formats -- it transparently delegates to a fallback handler (the vendored one), so behavior is unchanged outside the fast path.

The query path (selectors, lookback window, merge, staleness handling, sort, external-label attachment) mirrors the vendored handler exactly, and the output is byte-for-byte identical (verified by tests against the vendored handler); only the encoding is replaced with pkg/expfmt.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

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

Handler serves /federate. Construct with New and keep external labels current via SetExternalLabels on each config reload.

func New

func New(queryable storage.Queryable, lookback time.Duration, fallback http.Handler) *Handler

New returns a federation handler that queries queryable over the given lookback window and delegates non-text formats to fallback.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*Handler) SetExternalLabels

func (h *Handler) SetExternalLabels(ext labels.Labels)

SetExternalLabels updates the external labels attached to federated series. It mirrors the vendored handler: the configured global external_labels plus an implicit empty "instance" label when not otherwise set. Safe for concurrent use with ServeHTTP.

Jump to

Keyboard shortcuts

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