native

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2021 License: Apache-2.0 Imports: 36 Imported by: 4

Documentation

Overview

Package native handles the prometheus api endpoints using m3.

Index

Constants

View Source
const (
	// CompleteTagsURL is the url for searching tags.
	CompleteTagsURL = route.Prefix + "/search"

	// CompleteTagsHTTPMethod is the HTTP method used with this resource.
	CompleteTagsHTTPMethod = http.MethodGet
)
View Source
const (
	// PromParseURL is the url for native prom parse handler, this parses out the
	// query and returns a JSON representation of the execution DAG.
	PromParseURL = route.Prefix + "/parse"

	// PromParseHTTPMethod is the HTTP method used with this resource.
	PromParseHTTPMethod = http.MethodGet
)
View Source
const (
	// PromThresholdURL is the url for native prom threshold handler, this  parses
	// out the  query and returns a JSON representation of the execution DAG.
	PromThresholdURL = route.Prefix + "/threshold"

	// PromThresholdHTTPMethod is the HTTP method used with this resource.
	PromThresholdHTTPMethod = http.MethodGet
)
View Source
const (
	// PromReadURL is the URL for native prom read handler, this matches the
	// default URL for the query range endpoint found on a Prometheus server.
	PromReadURL = route.QueryRangeURL

	// PromReadInstantURL is the URL for native instantaneous prom read
	// handler, this matches the  default URL for the query endpoint
	// found on a Prometheus server.
	PromReadInstantURL = route.QueryURL

	// PrometheusReadURL is the URL for native prom read handler.
	PrometheusReadURL = "/prometheus" + PromReadURL

	// PrometheusReadInstantURL is the URL for native instantaneous prom read handler.
	PrometheusReadInstantURL = "/prometheus" + PromReadInstantURL

	// M3QueryReadURL is the URL for native m3 query read handler.
	M3QueryReadURL = "/m3query" + PromReadURL

	// M3QueryReadInstantURL is the URL for native instantaneous m3 query read handler.
	M3QueryReadInstantURL = "/m3query" + PromReadInstantURL
)
View Source
const (
	// ListTagsURL is the url for listing tags.
	ListTagsURL = route.LabelNamesURL
)
View Source
const (
	// QueryParam is the name of the query form/url parameter
	QueryParam = "query"
)

Variables

View Source
var (
	// PromReadHTTPMethods are the HTTP methods for the read handler.
	PromReadHTTPMethods = []string{
		http.MethodGet,
		http.MethodPost,
	}

	// PromReadInstantHTTPMethods are the HTTP methods for the instant handler.
	PromReadInstantHTTPMethods = []string{
		http.MethodGet,
		http.MethodPost,
	}
)
View Source
var ListTagsHTTPMethods = []string{http.MethodGet, http.MethodPost}

ListTagsHTTPMethods are the HTTP methods for this handler.

View Source
var WithInstantQueryParamsAndRangeRewriting middleware.OverrideOptions = func(
	opts middleware.Options,
) middleware.Options {
	opts = WithQueryParams(opts)
	opts.PrometheusRangeRewrite.Enabled = true
	opts.PrometheusRangeRewrite.Instant = true

	return opts
}

WithInstantQueryParamsAndRangeRewriting adds the instant query request parameters to the middleware options and enables range rewriting

View Source
var WithQueryParams middleware.OverrideOptions = func(opts middleware.Options) middleware.Options {
	opts.Logging.Fields = opts.Logging.Fields.Append(func(r *http.Request, start time.Time) []zap.Field {
		params, err := middlewareParseParams(r, start)
		if err != nil {
			opts.InstrumentOpts.Logger().Warn("failed to parse query params for response logging", zap.Error(err))
			return nil
		}
		return []zap.Field{
			zap.String("query", params.Query),
			zap.Time("start", params.Start),
			zap.Time("end", params.End),
			zap.Duration("queryRange", params.Range()),
		}
	})
	opts.Metrics.ParseQueryParams = middlewareParseParams
	return opts
}

WithQueryParams adds the query request parameters to the middleware options.

View Source
var WithRangeQueryParamsAndRangeRewriting middleware.OverrideOptions = func(
	opts middleware.Options,
) middleware.Options {
	opts = WithQueryParams(opts)
	opts.PrometheusRangeRewrite.Enabled = true

	return opts
}

WithRangeQueryParamsAndRangeRewriting adds the range query request parameters to the middleware options and enables range rewriting

Functions

func NewCompleteTagsHandler added in v0.5.0

func NewCompleteTagsHandler(opts options.HandlerOptions) http.Handler

NewCompleteTagsHandler returns a new instance of handler.

func NewListTagsHandler added in v0.9.0

func NewListTagsHandler(opts options.HandlerOptions) http.Handler

NewListTagsHandler returns a new instance of handler.

func NewPromParseHandler added in v0.14.1

func NewPromParseHandler(opts options.HandlerOptions) http.Handler

NewPromParseHandler returns a new instance of handler.

func NewPromReadHandler

func NewPromReadHandler(opts options.HandlerOptions) http.Handler

NewPromReadHandler returns a new prometheus-compatible read handler.

func NewPromReadInstantHandler added in v0.5.0

func NewPromReadInstantHandler(opts options.HandlerOptions) http.Handler

NewPromReadInstantHandler returns a new pro instance of handler.

func NewPromThresholdHandler added in v0.14.1

func NewPromThresholdHandler(opts options.HandlerOptions) http.Handler

NewPromThresholdHandler returns a new instance of handler.

func ParseQuery added in v1.2.0

func ParseQuery(r *http.Request) (string, error)

ParseQuery parses a query out of an HTTP request.

Types

type CompleteTagsHandler added in v0.5.0

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

CompleteTagsHandler represents a handler for search tags endpoint.

func (*CompleteTagsHandler) ServeHTTP added in v0.5.0

func (h *CompleteTagsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type FunctionNode added in v0.14.1

type FunctionNode struct {
	// Name is the name of the function node.
	Name string `json:"name,omitempty"`
	// Children are any children this function node has.
	Children []FunctionNode `json:"children,omitempty"`
	// contains filtered or unexported fields
}

FunctionNode is a JSON representation of a function.

func (FunctionNode) QueryRepresentation added in v0.14.1

func (n FunctionNode) QueryRepresentation() (QueryRepresentation, error)

QueryRepresentation gives the query representation of the function node.

func (FunctionNode) String added in v0.14.1

func (n FunctionNode) String() string

String prints the string representation of a function node.

type ListTagsHandler added in v0.9.0

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

ListTagsHandler represents a handler for list tags endpoint.

func (*ListTagsHandler) ServeHTTP added in v0.9.0

func (h *ListTagsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ParsedOptions added in v0.15.0

type ParsedOptions struct {
	QueryOpts *executor.QueryOptions
	FetchOpts *storage.FetchOptions
	Params    models.RequestParams
}

ParsedOptions are parsed options for the query.

func ParseRequest added in v0.15.0

func ParseRequest(
	ctx context.Context,
	r *http.Request,
	instantaneous bool,
	opts options.HandlerOptions,
) (context.Context, ParsedOptions, error)

ParseRequest parses the given request.

type PromReadReturnedDataMetrics added in v1.2.0

type PromReadReturnedDataMetrics struct {
	FetchSeries     tally.Histogram
	FetchDatapoints tally.Histogram
}

PromReadReturnedDataMetrics are metrics on the data returned from prom reads.

func NewPromReadReturnedDataMetrics added in v1.2.0

func NewPromReadReturnedDataMetrics(scope tally.Scope) PromReadReturnedDataMetrics

NewPromReadReturnedDataMetrics returns metrics for returned data.

type QueryRepresentation added in v0.14.1

type QueryRepresentation struct {
	// Query is the non-threshold part of a query.
	Query FunctionNode `json:"query,omitempty"`
	// Threshold is any detected threshold (top level comparison functions).
	// NB: this is a pointer so it does not have to be present in output if unset.
	Thresold *Threshold `json:"threshold,omitempty"`
}

QueryRepresentation is a JSON representation of a query after attempting to extract any threshold-specific parameters.

NB: this is always presented with the threshold value (if present) as appearing on the right of the query. e.g. `1 > up` will instead be inverted to `up < 1`

type ReadResponse

type ReadResponse struct {
	Results []ts.Series `json:"results,omitempty"`
}

ReadResponse is the response that gets returned to the user

type ReadResult added in v0.15.0

type ReadResult struct {
	Series    []*ts.Series
	Meta      block.ResultMetadata
	BlockType block.BlockType
}

ReadResult is a result from a remote read.

type RenderResultsOptions added in v0.15.0

type RenderResultsOptions struct {
	KeepNaNs                bool
	Start                   xtime.UnixNano
	End                     xtime.UnixNano
	ReturnedSeriesLimit     int
	ReturnedDatapointsLimit int
}

RenderResultsOptions is a set of options for rendering the result.

type RenderResultsResult added in v1.2.0

type RenderResultsResult struct {
	// Datapoints is the count of datapoints rendered.
	Datapoints int
	// Series is the count of series rendered.
	Series int
	// TotalSeries is the count of series in total.
	TotalSeries int
	// LimitedMaxReturnedData indicates if the results rendering
	// was truncated by a limit on returned series or datapoints.
	LimitedMaxReturnedData bool
}

RenderResultsResult is the result from rendering results.

func RenderResultsJSON added in v0.15.0

func RenderResultsJSON(
	jw json.Writer,
	result ReadResult,
	opts RenderResultsOptions,
) RenderResultsResult

RenderResultsJSON renders results in JSON for range queries.

type ReturnedDataLimited added in v1.2.0

type ReturnedDataLimited struct {
	Series     int
	Datapoints int

	// Total series is the total number of series which maybe be >= Series.
	// Truncation happens at the series-level to avoid presenting partial series
	// and so this value is useful for indicating how many series would have
	// been rendered without limiting either series or datapoints.
	TotalSeries int

	// Limited signals that the results returned were
	// limited by either series or datapoint limits.
	Limited bool
}

ReturnedDataLimited are parsed options for the query.

type Threshold added in v0.14.1

type Threshold struct {
	// Comparator is the threshold comparator.
	Comparator string `json:"comparator"`
	// Value is the threshold value.
	Value float64 `json:"value"`
}

Threshold is a JSON representation of a threshold, represented by a top level comparison function.

Jump to

Keyboard shortcuts

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