backends

package
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package backends the interface and generic functionality for Backend providers

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsVirtual

func IsVirtual(provider string) bool

IsVirtual returns true if the backend is a virtual type (e.g., ones that do not make an outbound http request, but instead front to other backends)

func UsesCache

func UsesCache(provider string) bool

UsesCache returns true if the backend uses a cache (anything except Virtuals and ReverseProxy)

Types

type Backend

type Backend interface {
	// RegisterHandlers registers the provided Handlers into the Router
	RegisterHandlers(handlers.Lookup)
	// Handlers returns a map of the HTTP Handlers the Backend has registered
	Handlers() handlers.Lookup
	// DefaultPathConfigs returns the default PathConfigs for the given Provider
	DefaultPathConfigs(*bo.Options) po.List
	// Configuration returns the configuration for the Backend
	Configuration() *bo.Options
	// Name returns the name of the Backend
	Name() string
	// HTTPClient will return the HTTP Client for this Backend
	HTTPClient() *http.Client
	// SetCache sets the Cache object the Backend will use when caching origin content
	SetCache(cache.Cache)
	// Router returns a Router that handles HTTP Requests for this Backend
	Router() http.Handler
	// Cache returns a handle to the Cache instance used by the Backend
	Cache() cache.Cache
	// BaseUpstreamURL returns the base URL for upstream requests
	BaseUpstreamURL() *url.URL
	// SetHealthCheckProbe sets the Health Check Status Prober for the Client
	SetHealthCheckProbe(healthcheck.DemandProbe)
	// HealthHandler executes a Health Check Probe when called
	HealthHandler(http.ResponseWriter, *http.Request)
	// DefaultHealthCheckConfig returns the default Health Check Config for the given Provider
	DefaultHealthCheckConfig() *ho.Options
	// HealthCheckHTTPClient returns the HTTP Client used for Health Checking
	HealthCheckHTTPClient() *http.Client
}

Backend is the primary interface for interoperating with backends

func New

func New(name string, o *bo.Options, registrar Registrar,
	router http.Handler, cache cache.Cache,
) (Backend, error)

New returns a new Backend

type Backends

type Backends map[string]Backend

Backends represents a map of Backends keyed by Name

func (Backends) CloseIdleConnections added in v2.0.2

func (b Backends) CloseIdleConnections()

CloseIdleConnections closes idle keep-alive conns on each backend's web and health-check transports. Reload replaces the backend map without closing the old map's transports, leaking persistConn readLoop/writeLoop goroutines until the per-transport IdleConnTimeout (default 2m) elapses.

func (Backends) Get

func (b Backends) Get(backendName string) Backend

Get returns the named origin

func (Backends) GetConfig

func (b Backends) GetConfig(backendName string) *bo.Options

GetConfig returns the named Backend's Configuration Options

func (Backends) GetRouter

func (b Backends) GetRouter(backendName string) http.Handler

GetRouter returns the named Backend's Request Router

func (Backends) StartHealthChecks

func (b Backends) StartHealthChecks(knownStatuses healthcheck.StatusLookup) (healthcheck.HealthChecker, error)

StartHealthChecks iterates the backends to fully configure health checkers and start up any intervaled health checks. knownStatuses is optional and sets the initial status of the provided targets (e.g., after a config reload)

type MergeableTimeseriesBackend

type MergeableTimeseriesBackend interface {
	// MergePaths should return a slice of HTTP Paths that are safe to merge with
	// other requests of the same path (e.g.,   /api/v1/query_range in prometheus)
	MergeablePaths() []string
}

MergeableTimeseriesBackend defines the interface for mergeable time series

type Registrar

type Registrar func(handlers.Lookup)

Registrar defines a function that registers http.Handlers with a router

type TSMMergeProvider added in v2.0.2

type TSMMergeProvider interface {
	// ClassifyMerge inspects the query string and returns:
	//   - strategy: the merge strategy to use for fanout accumulation, as the
	//     underlying int value of dataset.MergeStrategy (avoids importing the
	//     dataset package here and breaking the shallow backends import graph).
	//   - needsDualQuery: true when a weighted arithmetic mean is required
	//     (i.e. the outer aggregator is "avg"). TSM will fire two sub-queries —
	//     a "sum" variant and a "count" variant — and divide after gathering.
	//   - warning: non-empty when the aggregator cannot be correctly merged
	//     across fanout shards (e.g. stddev, quantile). TSM will fall back to
	//     deduplication and surface this warning in the response.
	ClassifyMerge(query string) (strategy int, needsDualQuery bool, warning string)

	// RewriteForWeightedAvg returns two modified copies of r — one with the
	// outer aggregator replaced by its "sum" equivalent and one by its "count"
	// equivalent. Both copies have the replacement injected in whatever way the
	// provider's wire protocol requires (URL query parameter, POST body, header,
	// etc.). The returned requests must be safe for concurrent use; they should
	// not share any mutable state with each other or with r.
	RewriteForWeightedAvg(r *http.Request, query string) (sumReq, countReq *http.Request)
}

TSMMergeProvider is an optional interface that a Backend may implement to participate in Time Series Merge (TSM) scatter/gather with query-aware merge strategies.

If a backend does not implement TSMMergeProvider, TSM falls back to deduplication for all queries.

type TimeseriesBackend

type TimeseriesBackend interface {
	// RegisterHandlers registers the provided Handlers into the Router
	RegisterHandlers(handlers.Lookup)
	// Handlers returns a map of the HTTP Handlers the Backend has registered
	Handlers() handlers.Lookup
	// DefaultPathConfigs returns the default PathConfigs for the given Provider
	DefaultPathConfigs(*bo.Options) po.List
	// ParseTimeRangeQuery returns a timeseries.TimeRangeQuery based on the provided HTTP Request
	ParseTimeRangeQuery(*http.Request) (*timeseries.TimeRangeQuery, *timeseries.RequestOptions, bool, error)
	// Configuration returns the configuration for the Backend
	Configuration() *bo.Options
	// Name returns the name of the Backend
	Name() string
	// FastForwardRequest returns an *http.Request crafted to collect Fast Forward data
	// from the Origin, based on the provided HTTP Request. If the inbound request is
	// POST/PUT/PATCH, a Content-Type header and non-nil body with the query parameters
	// must be set, in lieu of updated url query values, in the returned request
	FastForwardRequest(*http.Request) (*http.Request, error)
	// SetExtent will update an upstream request's timerange
	// parameters based on the provided timeseries.Extent
	SetExtent(*http.Request, *timeseries.TimeRangeQuery, *timeseries.Extent)
	// HTTPClient will return the HTTP Client for this Backend
	HTTPClient() *http.Client
	// SetCache sets the Cache object the Backend will use when caching origin content
	SetCache(cache.Cache)
	// Cache returns a handle to the Cache object used by the Backend
	Cache() cache.Cache
	// Router returns a Router that handles HTTP Requests for this Backend
	Router() http.Handler
	// BaseUpstreamURL returns the base URL for upstream requests
	BaseUpstreamURL() *url.URL
	// Modeler returns the Modeler for converting between DataSets and wire documents
	Modeler() *timeseries.Modeler
	// DefaultHealthCheckConfig returns the default HealthCHeck Config for the given Provider
	DefaultHealthCheckConfig() *ho.Options
	// SetHealthCheckProbe sets the Health Check Status Prober for the Client
	SetHealthCheckProbe(healthcheck.DemandProbe)
	// HealthHandler executes a Health Check Probe when called
	HealthHandler(http.ResponseWriter, *http.Request)
	// HealthCheckHTTPClient returns the HTTP Client used for Health Checking
	HealthCheckHTTPClient() *http.Client
	// ProcessTransformations executes any provider-specific transformations, like injecting
	// labels into the dataset
	ProcessTransformations(timeseries.Timeseries)
}

TimeseriesBackend is the primary interface for interoperating with Trickster and upstream TSDB's

func NewTimeseriesBackend

func NewTimeseriesBackend(name string, o *bo.Options, registrar Registrar, router http.Handler,
	cache cache.Cache, modeler *timeseries.Modeler,
) (TimeseriesBackend, error)

NewTimeseriesBackend returns a new BaseTimeseriesBackend Instance

Directories

Path Synopsis
alb
Package alb implements the Application Load Balancer Backend
Package alb implements the Application Load Balancer Backend
mech
Package mech provides the ALB Mechanisms functionality
Package mech provides the ALB Mechanisms functionality
mech/fanout
Package fanout is the shared primitive for ALB mechanisms that scatter a single inbound request to N pool members and gather their responses.
Package fanout is the shared primitive for ALB mechanisms that scatter a single inbound request to N pool members and gather their responses.
pool
Package pool provides an application load balancer pool
Package pool provides an application load balancer pool
Package clickhouse provides the ClickHouse backend provider
Package clickhouse provides the ClickHouse backend provider
authenticator
Package authenticator provides an Authenticator implementation for ClickHouse.
Package authenticator provides an Authenticator implementation for ClickHouse.
Package influxdb provides the InfluxDB Backend provider
Package influxdb provides the InfluxDB Backend provider
iofmt
package iofmt assists with managing supported input and output formats across the various versions of InfluxDB
package iofmt assists with managing supported input and output formats across the various versions of InfluxDB
Package prometheus provides the Prometheus Backend provider
Package prometheus provides the Prometheus Backend provider
promql
Package promql provides utilities for parsing and rewriting PromQL queries.
Package promql provides utilities for parsing and rewriting PromQL queries.
Package reverseproxy provides the HTTP Reverse Proxy (no caching) Backend provider
Package reverseproxy provides the HTTP Reverse Proxy (no caching) Backend provider
Package reverseproxycache provides the HTTP Reverse Proxy Cache Backend provider
Package reverseproxycache provides the HTTP Reverse Proxy Cache Backend provider
Package tree provides data structures that define the possible paths through chained Backends to assist with config Validation
Package tree provides data structures that define the possible paths through chained Backends to assist with config Validation

Jump to

Keyboard shortcuts

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