Documentation
¶
Index ¶
- type BackendResponse
- type BackendRole
- type DataObjConfig
- type FanOutHandler
- type FanOutHandlerConfig
- type HandlerFactory
- type HandlerFactoryConfig
- type InstrumentationServer
- type LimitsConfig
- type LokiLimits
- type NonDecodableResponse
- func (e *NonDecodableResponse) GetHeaders() []*queryrangebase.PrometheusResponseHeader
- func (e *NonDecodableResponse) ProtoMessage()
- func (e *NonDecodableResponse) Reset()
- func (e *NonDecodableResponse) SetHeader(_, _ string)
- func (e *NonDecodableResponse) String() string
- func (e *NonDecodableResponse) WithHeaders(_ []queryrangebase.PrometheusResponseHeader) queryrangebase.Response
- type PrimaryBackendConfig
- type Proxy
- type ProxyBackend
- type ProxyBackends
- type ProxyConfig
- type ProxyEndpoint
- type ProxyMetrics
- type QueryHandler
- type Route
- type SecondaryBackendConfig
- type Selection
- type SelectionStrategy
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BackendResponse ¶
type BackendResponse struct {
// contains filtered or unexported fields
}
type BackendRole ¶
type BackendRole int
BackendRole tells how the proxy uses a backend.
const ( // RoleOther is a backend that is neither the primary nor the secondary. It receives every // request on a registered route. The proxy never returns its response and never compares it. RoleOther BackendRole = iota // RolePrimary is the backend whose response the proxy returns to the client, even when the // response is an error. The proxy does not fall back to another backend. RolePrimary // RoleSecondary is the backend whose responses the proxy compares with the primary's. It // receives every write on a registered route. It receives a read only when the selection // strategy picks it. The proxy never returns its response. When -proxy.compare-responses is // set, the proxy compares its response with the primary's on routes that have a comparator. RoleSecondary )
func (BackendRole) String ¶
func (r BackendRole) String() string
String returns the name of the role. It is the value of the backend_alias metric label.
type DataObjConfig ¶
DataObjConfig holds the data object settings of the secondary backend's Loki cluster. The flags have the names, defaults and descriptions of the Loki flags. querytee does not read these settings from the Loki config file.
func (*DataObjConfig) RegisterFlags ¶
func (cfg *DataObjConfig) RegisterFlags(f *flag.FlagSet)
RegisterFlags registers the flags of the data object config.
type FanOutHandler ¶
type FanOutHandler struct {
// contains filtered or unexported fields
}
FanOutHandler implements queryrangebase.Handler and fans out requests to multiple backends. It sends each request to every backend, except that the secondary backend strategy decides whether the secondary backend gets it. It returns the primary backend's response as soon as it is ready. When it has a comparator, it compares the secondary backend's response with the primary's in the background. It never returns the secondary backend's response.
func NewFanOutHandler ¶
func NewFanOutHandler(cfg FanOutHandlerConfig) *FanOutHandler
NewFanOutHandler creates a new FanOutHandler.
func (*FanOutHandler) Do ¶
func (h *FanOutHandler) Do(ctx context.Context, req queryrangebase.Request) (queryrangebase.Response, error)
Do implements queryrangebase.Handler. It sends the request to every backend, except that the secondary backend strategy decides whether the secondary backend gets it. It returns the primary backend's response. In the background, when it has a comparator, it compares the secondary backend's response with the primary's.
func (*FanOutHandler) WithComparator ¶
func (h *FanOutHandler) WithComparator(comparator comparator.ResponsesComparator) *FanOutHandler
WithComparator sets the response comparator.
type FanOutHandlerConfig ¶
type FanOutHandlerConfig struct {
Backends []*ProxyBackend
Codec queryrangebase.Codec
Logger log.Logger
Metrics *ProxyMetrics
RouteName string
Comparator comparator.ResponsesComparator
ReportMissingSeries bool
// SecondaryBackendStrategy picks the requests that the secondary backend receives. Without a
// strategy, the secondary backend receives every request.
SecondaryBackendStrategy SelectionStrategy
}
FanOutHandlerConfig holds configuration for creating a FanOutHandler.
type HandlerFactory ¶
type HandlerFactory struct {
// contains filtered or unexported fields
}
HandlerFactory creates the query handler of a route.
func NewHandlerFactory ¶
func NewHandlerFactory(cfg HandlerFactoryConfig) *HandlerFactory
NewHandlerFactory creates a new HandlerFactory.
func (*HandlerFactory) CreateHandler ¶
func (f *HandlerFactory) CreateHandler(routeName string, comp comparator.ResponsesComparator) http.Handler
CreateHandler returns the query handler of a route. It sends each request to every backend, except that the strategy decides whether the secondary backend receives it. Without a secondary backend or a strategy, it sends every request to every backend.
type HandlerFactoryConfig ¶
type HandlerFactoryConfig struct {
Backends []*ProxyBackend
Codec queryrangebase.Codec
ReportMissingSeries bool
Logger log.Logger
Metrics *ProxyMetrics
// SecondaryBackendStrategy picks the requests that the secondary backend receives. Without a
// strategy, the secondary backend receives every request.
SecondaryBackendStrategy SelectionStrategy
}
HandlerFactoryConfig holds configuration for creating a HandlerFactory.
type InstrumentationServer ¶
type InstrumentationServer struct {
// contains filtered or unexported fields
}
func NewInstrumentationServer ¶
func NewInstrumentationServer(port int, registry *prometheus.Registry, logger log.Logger) *InstrumentationServer
NewInstrumentationServer returns a server exposing Prometheus metrics.
func (*InstrumentationServer) Start ¶
func (s *InstrumentationServer) Start() error
Start the instrumentation server.
func (*InstrumentationServer) Stop ¶
func (s *InstrumentationServer) Stop()
Stop closes the instrumentation server.
type LimitsConfig ¶
type LimitsConfig struct {
ConfigFile string
ExpandEnv bool
RuntimeConfig runtimeconfig.Config
}
LimitsConfig configures how querytee loads the limits of a Loki cluster. The flag names match the ones in Loki. The config file is read for the limits_config block only. The runtime config is read for the overrides only. When neither file is set, querytee loads no limits.
func (*LimitsConfig) RegisterFlags ¶
func (cfg *LimitsConfig) RegisterFlags(f *flag.FlagSet)
RegisterFlags registers the flags of the limits config.
type LokiLimits ¶
type LokiLimits struct {
// Overrides resolves the limits of a tenant: the per-tenant overrides of the runtime config on
// top of the defaults of limits_config.
Overrides *validation.Overrides
// contains filtered or unexported fields
}
LokiLimits holds the limits that querytee loaded from the config files of a Loki cluster.
The runtime config reloads while querytee runs, so Overrides sees changed per-tenant limits. The limits_config defaults stay as loaded at start-up.
func LoadLokiLimits ¶
func LoadLokiLimits(ctx context.Context, cfg LimitsConfig, logger log.Logger, registerer prometheus.Registerer) (*LokiLimits, error)
LoadLokiLimits loads the limits from the Loki config and runtime config files that the config names. It waits for the first load of the runtime config. It returns nil when the config names no file.
type NonDecodableResponse ¶
NonDecodableResponse is a minimal response type used when returning errors. It satisfies the queryrangebase.Response interface, and allows the querytee to capture responses that would otherwise be lost.
func (*NonDecodableResponse) GetHeaders ¶
func (e *NonDecodableResponse) GetHeaders() []*queryrangebase.PrometheusResponseHeader
GetHeaders implements queryrangebase.Response
func (*NonDecodableResponse) ProtoMessage ¶
func (e *NonDecodableResponse) ProtoMessage()
ProtoMessage implements proto.Message
func (*NonDecodableResponse) Reset ¶
func (e *NonDecodableResponse) Reset()
Reset implements proto.Message
func (*NonDecodableResponse) SetHeader ¶
func (e *NonDecodableResponse) SetHeader(_, _ string)
SetHeader implements queryrangebase.Response
func (*NonDecodableResponse) String ¶
func (e *NonDecodableResponse) String() string
String implements proto.Message
func (*NonDecodableResponse) WithHeaders ¶
func (e *NonDecodableResponse) WithHeaders(_ []queryrangebase.PrometheusResponseHeader) queryrangebase.Response
WithHeaders implements queryrangebase.Response
type PrimaryBackendConfig ¶
type PrimaryBackendConfig struct {
Hostname string
}
PrimaryBackendConfig configures the backend whose response the proxy returns to the client.
func (*PrimaryBackendConfig) RegisterFlags ¶
func (cfg *PrimaryBackendConfig) RegisterFlags(f *flag.FlagSet)
RegisterFlags registers the flags of the primary backend.
type Proxy ¶
type Proxy struct {
// contains filtered or unexported fields
}
func NewProxy ¶
func NewProxy( cfg ProxyConfig, logger log.Logger, readRoutes, writeRoutes []Route, registerer prometheus.Registerer, lokiLimits *LokiLimits, ) (*Proxy, error)
NewProxy returns a Proxy for the backends in cfg.BackendEndpoints.
Exactly one backend must match the primary hostname. When the secondary hostname is set, exactly one other backend must match it. A backend that matches neither is an "other" backend. The proxy sends it every request and never compares its responses.
type ProxyBackend ¶
type ProxyBackend struct {
// contains filtered or unexported fields
}
ProxyBackend holds the information of a single backend.
func NewProxyBackend ¶
func NewProxyBackend(name string, endpoint *url.URL, timeout time.Duration, role BackendRole) (*ProxyBackend, error)
NewProxyBackend makes a new ProxyBackend.
func (*ProxyBackend) Alias ¶
func (b *ProxyBackend) Alias() string
Alias returns the backend alias label value for metrics. It is "primary", "secondary" or "other".
func (*ProxyBackend) ForwardRequest ¶
func (b *ProxyBackend) ForwardRequest(orig *http.Request, body io.ReadCloser) *BackendResponse
type ProxyBackends ¶
type ProxyBackends []*ProxyBackend
ProxyBackends is a list of backends.
func (ProxyBackends) CountFunc ¶
func (bs ProxyBackends) CountFunc(match func(*ProxyBackend) bool) int
CountFunc returns the number of backends for which match returns true.
type ProxyConfig ¶
type ProxyConfig struct {
ServerServicePort int
BackendEndpoints string
BackendReadTimeout time.Duration
CompareResponses bool
ValueComparisonTolerance float64
UseRelativeError bool
PassThroughNonRegisteredRoutes bool
SkipRecentSamples time.Duration
SkipSamplesBefore flagext.Time
ReportMissingSeries bool
PrimaryBackend PrimaryBackendConfig
SecondaryBackend SecondaryBackendConfig
DataObj DataObjConfig
}
func (*ProxyConfig) RegisterFlags ¶
func (cfg *ProxyConfig) RegisterFlags(f *flag.FlagSet)
type ProxyEndpoint ¶
type ProxyEndpoint struct {
// contains filtered or unexported fields
}
func NewProxyEndpoint ¶
func NewProxyEndpoint( backends []*ProxyBackend, routeName string, metrics *ProxyMetrics, logger log.Logger, ) *ProxyEndpoint
func (*ProxyEndpoint) ServeHTTP ¶
func (p *ProxyEndpoint) ServeHTTP(w http.ResponseWriter, r *http.Request)
func (*ProxyEndpoint) WithQueryHandler ¶
func (p *ProxyEndpoint) WithQueryHandler(handler http.Handler) *ProxyEndpoint
WithQueryHandler sets the middleware-based query handlers (logs and metrics) for the endpoint. When set, ServeHTTP uses this handler instead of the legacy executeBackendRequests.
type ProxyMetrics ¶
type ProxyMetrics struct {
// contains filtered or unexported fields
}
func NewProxyMetrics ¶
func NewProxyMetrics(registerer prometheus.Registerer) *ProxyMetrics
type QueryHandler ¶
type QueryHandler struct {
// contains filtered or unexported fields
}
QueryHandler decodes a query request, sends it to the downstream handler and writes the response.
func NewQueryHandler ¶
func NewQueryHandler(codec queryrangebase.Codec, fanOutHandler queryrangebase.Handler, logger log.Logger) *QueryHandler
NewQueryHandler returns a handler that serves query requests with the given handler. It requires the org ID of the tenant on every request.
func (*QueryHandler) ServeHTTP ¶
func (h *QueryHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler. It answers with its own error when it cannot read the tenant or decode the request.
type Route ¶
type Route struct {
Path string
RouteName string
Methods []string
ResponseComparator comparator.ResponsesComparator
}
type SecondaryBackendConfig ¶
SecondaryBackendConfig configures the backend whose responses the proxy compares with the primary backend's responses when -proxy.compare-responses is set. The proxy never returns its responses to the client.
func (*SecondaryBackendConfig) RegisterFlags ¶
func (cfg *SecondaryBackendConfig) RegisterFlags(f *flag.FlagSet)
RegisterFlags registers the flags of the secondary backend.
func (*SecondaryBackendConfig) Validate ¶
func (cfg *SecondaryBackendConfig) Validate() error
Validate checks that the selection strategy is a known one, and that a strategy other than the default has a secondary backend.
type Selection ¶
type Selection struct {
Selected bool
// Reason is a value of the decision label. It comes from a small fixed set per strategy. A
// strategy sets it only when Selected is false. The router counts a selected request as "sent".
Reason string
}
Selection is the answer of a SelectionStrategy for one request.
type SelectionStrategy ¶
type SelectionStrategy interface {
// Select reports whether the secondary backend gets a copy of the request. The decision covers
// the whole request. The proxy does not split its time range. The request can be of any type
// that the codec decodes, not only a range or instant query.
Select(tenants []string, req queryrangebase.Request) Selection
}
SelectionStrategy decides which requests the secondary backend receives. The proxy calls it from many request goroutines, before it calls the primary backend. An implementation must be safe for concurrent use, cheap, and free of I/O.