Documentation
¶
Index ¶
- Variables
- func MustLabelValue(ctx context.Context) string
- func MustLabelValues(ctx context.Context) []string
- func NewRoutes(upstream *url.URL, label string, extractLabeler ExtractLabeler, opts ...Option) (*routes, error)
- func WithLabelValues(ctx context.Context, labels []string) context.Context
- type ExtractLabeler
- type HTTPFormEnforcer
- type HTTPHeaderEnforcer
- type Option
- type PromQLEnforcer
- type StaticLabelEnforcer
Constants ¶
This section is empty.
Variables ¶
var ( // ErrQueryParse is returned when the input query is invalid. ErrQueryParse = errors.New("failed to parse query string") // ErrIllegalLabelMatcher is returned when the input query contains a conflicting label matcher. ErrIllegalLabelMatcher = errors.New("conflicting label matcher") // ErrEnforceLabel is returned when the label matchers couldn't be enforced. ErrEnforceLabel = errors.New("failed to enforce label") )
Functions ¶
func MustLabelValue ¶ added in v0.6.0
MustLabelValue returns the first (alphabetical order) label value previously stored using WithLabelValue() from the given context. Similar to MustLabelValues, it will panic if no label is found or the value is empty.
func MustLabelValues ¶ added in v0.7.0
MustLabelValues returns labels (previously stored using WithLabelValue()) from the given context. It will panic if no label is found or the value is empty.
Types ¶
type ExtractLabeler ¶ added in v0.6.0
type ExtractLabeler interface {
ExtractLabel(next http.HandlerFunc) http.Handler
}
ExtractLabeler is an HTTP handler that extract the label value to be enforced from the HTTP request. If a valid label value is found, it should store it in the request's context. Otherwise it should return an error in the HTTP response (usually 400 or 500).
type HTTPFormEnforcer ¶ added in v0.6.0
type HTTPFormEnforcer struct {
ParameterName string
}
HTTPFormEnforcer enforces a label value extracted from the HTTP form and query parameters.
func (HTTPFormEnforcer) ExtractLabel ¶ added in v0.6.0
func (hff HTTPFormEnforcer) ExtractLabel(next http.HandlerFunc) http.Handler
ExtractLabel implements the ExtractLabeler interface.
type HTTPHeaderEnforcer ¶ added in v0.6.0
HTTPHeaderEnforcer enforces a label value extracted from the HTTP headers.
func (HTTPHeaderEnforcer) ExtractLabel ¶ added in v0.6.0
func (hhe HTTPHeaderEnforcer) ExtractLabel(next http.HandlerFunc) http.Handler
ExtractLabel implements the ExtractLabeler interface.
type Option ¶ added in v0.3.0
type Option interface {
// contains filtered or unexported methods
}
func WithActiveAlerts ¶ added in v0.11.0
func WithActiveAlerts() Option
WithActiveAlerts causes the proxy to return rules with active alerts.
func WithEnabledLabelsAPI ¶ added in v0.3.0
func WithEnabledLabelsAPI() Option
WithEnabledLabelsAPI enables proxying to labels API. If false, "501 Not implemented" will be return for those.
func WithErrorOnReplace ¶ added in v0.4.0
func WithErrorOnReplace() Option
WithErrorOnReplace causes the proxy to return 400 if a label matcher we want to inject is present in the query already and matches something different
func WithPassthroughPaths ¶ added in v0.3.0
WithPassthroughPaths configures routes to register given paths as passthrough handlers for all HTTP methods. that, if requested, will be forwarded without enforcing label. Use with care. NOTE: Passthrough "all" paths like "/" or "" and regex are not allowed.
func WithPrometheusRegistry ¶ added in v0.6.0
func WithPrometheusRegistry(reg prometheus.Registerer) Option
WithPrometheusRegistry configures the proxy to use the given registerer.
func WithRegexMatch ¶ added in v0.8.0
func WithRegexMatch() Option
WithRegexMatch causes the proxy to handle tenant name as regexp
type PromQLEnforcer ¶ added in v0.10.0
type PromQLEnforcer struct {
// contains filtered or unexported fields
}
PromQLEnforcer can enforce label matchers in PromQL expressions.
func NewPromQLEnforcer ¶ added in v0.10.0
func NewPromQLEnforcer(errorOnReplace bool, ms ...*labels.Matcher) *PromQLEnforcer
func (*PromQLEnforcer) Enforce ¶ added in v0.10.0
func (ms *PromQLEnforcer) Enforce(q string) (string, error)
Enforce the label matchers in a PromQL expression.
func (PromQLEnforcer) EnforceMatchers ¶ added in v0.10.0
EnforceMatchers appends the enforced label matcher(s) to the list of matchers if not already present.
If the label matcher that is to be injected is present (by labelname), the behavior depends on the errorOnReplace variable and the enforced matcher(s): * If errorOnReplace is false
- And the label matcher type is '=', the existing matcher is silently discarded whatever is the original value.
- Otherwise the existing matcher is preserved.
* if errorOnReplace is true
- And the label matcher and the enforced matcher are disjoint, the function returns an error.
- Otherwise the existing matcher is preserved.
func (PromQLEnforcer) EnforceNode ¶ added in v0.10.0
func (ms PromQLEnforcer) EnforceNode(node parser.Node) error
EnforceNode walks the given node recursively and enforces the given label enforcer on it.
Whenever a parser.MatrixSelector or parser.VectorSelector AST node is found, their label enforcer is being potentially modified. If a node's label matcher has the same name as a label matcher of the given enforcer, then it will be replaced.
type StaticLabelEnforcer ¶ added in v0.6.0
type StaticLabelEnforcer []string
StaticLabelEnforcer enforces a static label value.
func (StaticLabelEnforcer) ExtractLabel ¶ added in v0.6.0
func (sle StaticLabelEnforcer) ExtractLabel(next http.HandlerFunc) http.Handler
ExtractLabel implements the ExtractLabeler interface.