queryrangebase

package
v3.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: AGPL-3.0 Imports: 51 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ResultsCacheGenNumberHeaderName holds name of the header we want to set in http response
	ResultsCacheGenNumberHeaderName = "Results-Cache-Gen-Number"
)
View Source
const StatusSuccess = "success"

StatusSuccess Prometheus success result.

Variables

View Source
var (

	// PrometheusCodecForRangeQueries is a codec to encode and decode Loki range metric query requests and responses.
	PrometheusCodecForRangeQueries = &prometheusCodec{
		resultType: model.ValMatrix,
	}

	// PrometheusCodecForInstantQueries is a codec to encode and decode Loki range metric query requests and responses.
	PrometheusCodecForInstantQueries = &prometheusCodec{
		resultType: model.ValVector,
	}
)
View Source
var (
	ErrInvalidLengthQueryrange = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowQueryrange   = fmt.Errorf("proto: integer overflow")
)
View Source
var PassthroughMiddleware = MiddlewareFunc(func(next Handler) Handler {
	return next
})

PassthroughMiddleware is a noop middleware

View Source
var StepAlignMiddleware = MiddlewareFunc(func(next Handler) Handler {
	return stepAlign{
		next: next,
	}
})

StepAlignMiddleware aligns the start and end of request to the step to improved the cacheability of the query results.

Functions

func CacheGenNumberHeaderSetterMiddleware

func CacheGenNumberHeaderSetterMiddleware(cacheGenNumbersLoader resultscache.CacheGenNumberLoader) middleware.Interface

func FromQueryResponseMergerToCacheResponseMerger

func FromQueryResponseMergerToCacheResponseMerger(m Merger) resultscache.ResponseMerger

func NewSeriesSet

func NewSeriesSet(results []SampleStream) storage.SeriesSet

NewSeriesSet returns an in memory storage.SeriesSet from a []SampleStream As NewSeriesSet uses NewConcreteSeriesSet to implement SeriesSet, result will be sorted by label names.

Types

type Buffer

type Buffer interface {
	Bytes() []byte
}

Buffer can be used to read a response body. This allows to avoid reading the body multiple times from the `http.Response.Body`.

type CacheGenNumberLoader

type CacheGenNumberLoader = resultscache.CacheGenNumberLoader

type CachingOptions

type CachingOptions = definitions.CachingOptions

type Codec

type Codec = definitions.Codec

type Config

type Config struct {
	AlignQueriesWithStep bool                   `yaml:"align_queries_with_step"`
	ResultsCacheConfig   ResultsCacheConfig     `yaml:"results_cache"`
	CacheResults         bool                   `yaml:"cache_results"`
	MaxRetries           int                    `yaml:"max_retries"`
	ShardedQueries       bool                   `yaml:"parallelise_shardable_queries"`
	ShardAggregations    flagext.StringSliceCSV `yaml:"shard_aggregations"`
}

Config for query_range middleware chain.

func (*Config) RegisterFlags

func (cfg *Config) RegisterFlags(f *flag.FlagSet)

RegisterFlags adds the flags required to config this to the given FlagSet.

func (*Config) Validate

func (cfg *Config) Validate() error

Validate validates the config.

type Extent

type Extent = resultscache.Extent

type Extractor

type Extractor interface {
	resultscache.Extractor
	ResponseWithoutHeaders(resp Response) Response
}

Extractor is used by the cache to extract a subset of a response from a cache entry.

type Handler

type Handler interface {
	Do(context.Context, Request) (Response, error)
}

Handler is like http.Handle, but specifically for Prometheus query_range calls.

type HandlerFunc

type HandlerFunc func(context.Context, Request) (Response, error)

HandlerFunc is like http.HandlerFunc, but for Handler.

func (HandlerFunc) Do

func (q HandlerFunc) Do(ctx context.Context, req Request) (Response, error)

Do implements Handler.

type InstrumentMiddlewareMetrics

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

InstrumentMiddlewareMetrics holds the metrics tracked by InstrumentMiddleware.

func NewInstrumentMiddlewareMetrics

func NewInstrumentMiddlewareMetrics(registerer prometheus.Registerer, metricsNamespace string) *InstrumentMiddlewareMetrics

NewInstrumentMiddlewareMetrics makes a new InstrumentMiddlewareMetrics.

type Limits

type Limits interface {
	// MaxQueryLookback returns the max lookback period of queries.
	MaxQueryLookback(context.Context, string) time.Duration

	// MaxQueryLength returns the limit of the length (in time) of a query.
	MaxQueryLength(context.Context, string) time.Duration

	// MaxQueryParallelism returns the limit to the number of split queries the
	// frontend will process in parallel.
	MaxQueryParallelism(context.Context, string) int

	// MaxCacheFreshness returns the period after which results are cacheable,
	// to prevent caching of very recent results.
	MaxCacheFreshness(context.Context, string) time.Duration
}

Limits allows us to specify per-tenant runtime limits on the behavior of the query handling code.

type Merger

type Merger = definitions.Merger

type Middleware

type Middleware interface {
	Wrap(Handler) Handler
}

Middleware is a higher order Handler.

func CacheGenNumberContextSetterMiddleware

func CacheGenNumberContextSetterMiddleware(cacheGenNumbersLoader resultscache.CacheGenNumberLoader) Middleware

func InstrumentMiddleware

func InstrumentMiddleware(name string, metrics *InstrumentMiddlewareMetrics) Middleware

InstrumentMiddleware can be inserted into the middleware chain to expose timing information.

func MergeMiddlewares

func MergeMiddlewares(middleware ...Middleware) Middleware

MergeMiddlewares produces a middleware that applies multiple middleware in turn; ie Merge(f,g,h).Wrap(handler) == f.Wrap(g.Wrap(h.Wrap(handler)))

func NewResultsCacheMiddleware

func NewResultsCacheMiddleware(
	logger log.Logger,
	c cache.Cache,
	keygen resultscache.KeyGenerator,
	limits Limits,
	merger Merger,
	extractor Extractor,
	cacheGenNumberLoader resultscache.CacheGenNumberLoader,
	shouldCache ShouldCacheFn,
	parallelismForReq ParallelismForReqFn,
	retentionEnabled bool,
	onlyUseEntireExtent bool,
	metrics *ResultsCacheMetrics,
) (Middleware, error)

NewResultsCacheMiddleware creates results cache middleware from config. The middleware cache result using a unique cache key for a given request (step,query,user) and interval. The cache assumes that each request length (end-start) is below or equal the interval. Each request starting from within the same interval will hit the same cache entry. If the cache doesn't have the entire duration of the request cached, it will query the uncached parts and append them to the cache entries. see `generateKey`.

func NewRetryMiddleware

func NewRetryMiddleware(log log.Logger, maxRetries int, metrics *RetryMiddlewareMetrics, metricsNamespace string) Middleware

NewRetryMiddleware returns a middleware that retries requests if they fail with 500 or a non-HTTP error.

type MiddlewareFunc

type MiddlewareFunc func(Handler) Handler

MiddlewareFunc is like http.HandlerFunc, but for Middleware.

func (MiddlewareFunc) Wrap

func (q MiddlewareFunc) Wrap(h Handler) Handler

Wrap implements Middleware.

type MockShardedQueryable

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

MockShardedQueryable is exported to be reused in the querysharding benchmarking

func NewMockShardedQueryable

func NewMockShardedQueryable(
	nSamples int,
	labelSet []string,
	labelBuckets int,
	delayPerSeries time.Duration,
) *MockShardedQueryable

NewMockShardedQueryable creates a shard-aware in memory queryable.

func (*MockShardedQueryable) Close

func (q *MockShardedQueryable) Close() error

Close releases the resources of the Querier.

func (*MockShardedQueryable) LabelNames

LabelNames returns all the unique label names present in the block in sorted order.

func (*MockShardedQueryable) LabelValues

LabelValues impls storage.Querier

func (*MockShardedQueryable) Querier

Querier impls storage.Queryable

func (*MockShardedQueryable) Select

Select implements storage.Querier interface. The bool passed is ignored because the series is always sorted.

type NoopCollector

type NoopCollector struct{}

NoopCollector is a noop collector that can be used as placeholder when no metric should tracked by the instrumentation.

func (*NoopCollector) After

func (c *NoopCollector) After(_ context.Context, _, _ string, _ time.Time)

After implements instrument.Collector.

func (*NoopCollector) Before

func (c *NoopCollector) Before(_ context.Context, _ string, _ time.Time)

Before implements instrument.Collector.

func (*NoopCollector) Register

func (c *NoopCollector) Register()

Register implements instrument.Collector.

type ParallelismForReqFn

type ParallelismForReqFn func(ctx context.Context, tenantIDs []string, r Request) int

ParallelismForReqFn returns the parallelism for a given request.

type PrometheusData

type PrometheusData struct {
	ResultType string         `protobuf:"bytes,1,opt,name=ResultType,proto3" json:"resultType"`
	Result     []SampleStream `protobuf:"bytes,2,rep,name=Result,proto3" json:"result"`
}

func (*PrometheusData) Descriptor

func (*PrometheusData) Descriptor() ([]byte, []int)

func (*PrometheusData) Equal

func (this *PrometheusData) Equal(that interface{}) bool

func (*PrometheusData) GetResult

func (m *PrometheusData) GetResult() []SampleStream

func (*PrometheusData) GetResultType

func (m *PrometheusData) GetResultType() string

func (*PrometheusData) GoString

func (this *PrometheusData) GoString() string

func (*PrometheusData) Marshal

func (m *PrometheusData) Marshal() (dAtA []byte, err error)

func (*PrometheusData) MarshalTo

func (m *PrometheusData) MarshalTo(dAtA []byte) (int, error)

func (*PrometheusData) MarshalToSizedBuffer

func (m *PrometheusData) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*PrometheusData) ProtoMessage

func (*PrometheusData) ProtoMessage()

func (*PrometheusData) Reset

func (m *PrometheusData) Reset()

func (*PrometheusData) Size

func (m *PrometheusData) Size() (n int)

func (*PrometheusData) String

func (this *PrometheusData) String() string

func (*PrometheusData) Unmarshal

func (m *PrometheusData) Unmarshal(dAtA []byte) error

func (*PrometheusData) XXX_DiscardUnknown

func (m *PrometheusData) XXX_DiscardUnknown()

func (*PrometheusData) XXX_Marshal

func (m *PrometheusData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*PrometheusData) XXX_Merge

func (m *PrometheusData) XXX_Merge(src proto.Message)

func (*PrometheusData) XXX_Size

func (m *PrometheusData) XXX_Size() int

func (*PrometheusData) XXX_Unmarshal

func (m *PrometheusData) XXX_Unmarshal(b []byte) error

type PrometheusRequest

type PrometheusRequest struct {
	Path           string                                 `protobuf:"bytes,1,opt,name=path,proto3" json:"path,omitempty"`
	Start          time.Time                              `protobuf:"bytes,2,opt,name=start,proto3,stdtime" json:"start"`
	End            time.Time                              `protobuf:"bytes,3,opt,name=end,proto3,stdtime" json:"end"`
	Step           int64                                  `protobuf:"varint,4,opt,name=step,proto3" json:"step,omitempty"`
	Timeout        time.Duration                          `protobuf:"bytes,5,opt,name=timeout,proto3,stdduration" json:"timeout"`
	Query          string                                 `protobuf:"bytes,6,opt,name=query,proto3" json:"query,omitempty"`
	CachingOptions resultscache.CachingOptions            `protobuf:"bytes,7,opt,name=cachingOptions,proto3" json:"cachingOptions"`
	Headers        []*definitions.PrometheusRequestHeader `protobuf:"bytes,8,rep,name=Headers,proto3" json:"-"`
}

func (*PrometheusRequest) Descriptor

func (*PrometheusRequest) Descriptor() ([]byte, []int)

func (*PrometheusRequest) Equal

func (this *PrometheusRequest) Equal(that interface{}) bool

func (*PrometheusRequest) GetCachingOptions

func (m *PrometheusRequest) GetCachingOptions() resultscache.CachingOptions

func (*PrometheusRequest) GetEnd

func (m *PrometheusRequest) GetEnd() time.Time

func (*PrometheusRequest) GetHeaders

func (*PrometheusRequest) GetPath

func (m *PrometheusRequest) GetPath() string

func (*PrometheusRequest) GetQuery

func (m *PrometheusRequest) GetQuery() string

func (*PrometheusRequest) GetStart

func (m *PrometheusRequest) GetStart() time.Time

func (*PrometheusRequest) GetStep

func (m *PrometheusRequest) GetStep() int64

func (*PrometheusRequest) GetTimeout

func (m *PrometheusRequest) GetTimeout() time.Duration

func (*PrometheusRequest) GoString

func (this *PrometheusRequest) GoString() string

func (*PrometheusRequest) LogToSpan

func (q *PrometheusRequest) LogToSpan(sp opentracing.Span)

LogToSpan logs the current `PrometheusRequest` parameters to the specified span.

func (*PrometheusRequest) Marshal

func (m *PrometheusRequest) Marshal() (dAtA []byte, err error)

func (*PrometheusRequest) MarshalTo

func (m *PrometheusRequest) MarshalTo(dAtA []byte) (int, error)

func (*PrometheusRequest) MarshalToSizedBuffer

func (m *PrometheusRequest) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*PrometheusRequest) ProtoMessage

func (*PrometheusRequest) ProtoMessage()

func (*PrometheusRequest) Reset

func (m *PrometheusRequest) Reset()

func (*PrometheusRequest) Size

func (m *PrometheusRequest) Size() (n int)

func (*PrometheusRequest) String

func (this *PrometheusRequest) String() string

func (*PrometheusRequest) Unmarshal

func (m *PrometheusRequest) Unmarshal(dAtA []byte) error

func (*PrometheusRequest) WithQuery

func (q *PrometheusRequest) WithQuery(query string) Request

WithQuery clones the current `PrometheusRequest` with a new query.

func (*PrometheusRequest) WithStartEnd

func (q *PrometheusRequest) WithStartEnd(start, end time.Time) Request

WithStartEnd clones the current `PrometheusRequest` with a new `start` and `end` timestamp.

func (*PrometheusRequest) WithStartEndForCache

func (q *PrometheusRequest) WithStartEndForCache(s time.Time, e time.Time) resultscache.Request

WithStartEndForCache implements resultscache.Request.

func (*PrometheusRequest) XXX_DiscardUnknown

func (m *PrometheusRequest) XXX_DiscardUnknown()

func (*PrometheusRequest) XXX_Marshal

func (m *PrometheusRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*PrometheusRequest) XXX_Merge

func (m *PrometheusRequest) XXX_Merge(src proto.Message)

func (*PrometheusRequest) XXX_Size

func (m *PrometheusRequest) XXX_Size() int

func (*PrometheusRequest) XXX_Unmarshal

func (m *PrometheusRequest) XXX_Unmarshal(b []byte) error

type PrometheusRequestHeader

type PrometheusRequestHeader = definitions.PrometheusRequestHeader

type PrometheusResponse

type PrometheusResponse struct {
	Status    string                                  `protobuf:"bytes,1,opt,name=Status,proto3" json:"status"`
	Data      PrometheusData                          `protobuf:"bytes,2,opt,name=Data,proto3" json:"data,omitempty"`
	ErrorType string                                  `protobuf:"bytes,3,opt,name=ErrorType,proto3" json:"errorType,omitempty"`
	Error     string                                  `protobuf:"bytes,4,opt,name=Error,proto3" json:"error,omitempty"`
	Headers   []*definitions.PrometheusResponseHeader `protobuf:"bytes,5,rep,name=Headers,proto3" json:"-"`
	Warnings  []string                                `protobuf:"bytes,6,rep,name=Warnings,proto3" json:"warnings,omitempty"`
}

func NewEmptyPrometheusResponse

func NewEmptyPrometheusResponse(v model.ValueType) *PrometheusResponse

NewEmptyPrometheusResponse returns an empty successful Prometheus query range response.

func (*PrometheusResponse) Descriptor

func (*PrometheusResponse) Descriptor() ([]byte, []int)

func (*PrometheusResponse) Equal

func (this *PrometheusResponse) Equal(that interface{}) bool

func (*PrometheusResponse) GetData

func (m *PrometheusResponse) GetData() PrometheusData

func (*PrometheusResponse) GetError

func (m *PrometheusResponse) GetError() string

func (*PrometheusResponse) GetErrorType

func (m *PrometheusResponse) GetErrorType() string

func (*PrometheusResponse) GetHeaders

func (*PrometheusResponse) GetStatus

func (m *PrometheusResponse) GetStatus() string

func (*PrometheusResponse) GetWarnings

func (m *PrometheusResponse) GetWarnings() []string

func (*PrometheusResponse) GoString

func (this *PrometheusResponse) GoString() string

func (*PrometheusResponse) Marshal

func (m *PrometheusResponse) Marshal() (dAtA []byte, err error)

func (*PrometheusResponse) MarshalTo

func (m *PrometheusResponse) MarshalTo(dAtA []byte) (int, error)

func (*PrometheusResponse) MarshalToSizedBuffer

func (m *PrometheusResponse) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*PrometheusResponse) ProtoMessage

func (*PrometheusResponse) ProtoMessage()

func (*PrometheusResponse) Reset

func (m *PrometheusResponse) Reset()

func (*PrometheusResponse) SetHeader

func (resp *PrometheusResponse) SetHeader(name, value string)

func (*PrometheusResponse) Size

func (m *PrometheusResponse) Size() (n int)

func (*PrometheusResponse) String

func (this *PrometheusResponse) String() string

func (*PrometheusResponse) Unmarshal

func (m *PrometheusResponse) Unmarshal(dAtA []byte) error

func (*PrometheusResponse) WithHeaders

func (resp *PrometheusResponse) WithHeaders(h []PrometheusResponseHeader) Response

func (*PrometheusResponse) XXX_DiscardUnknown

func (m *PrometheusResponse) XXX_DiscardUnknown()

func (*PrometheusResponse) XXX_Marshal

func (m *PrometheusResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*PrometheusResponse) XXX_Merge

func (m *PrometheusResponse) XXX_Merge(src proto.Message)

func (*PrometheusResponse) XXX_Size

func (m *PrometheusResponse) XXX_Size() int

func (*PrometheusResponse) XXX_Unmarshal

func (m *PrometheusResponse) XXX_Unmarshal(b []byte) error

type PrometheusResponseExtractor

type PrometheusResponseExtractor struct{}

PrometheusResponseExtractor helps extracting specific info from Query Response.

func (PrometheusResponseExtractor) Extract

Extract extracts response for specific a range from a response.

func (PrometheusResponseExtractor) ResponseWithoutHeaders

func (PrometheusResponseExtractor) ResponseWithoutHeaders(resp Response) Response

ResponseWithoutHeaders is useful in caching data without headers since we anyways do not need headers for sending back the response so this saves some space by reducing size of the objects.

type PrometheusResponseHeader

type PrometheusResponseHeader = definitions.PrometheusResponseHeader

type Request

type Request = definitions.Request

type RequestResponse

type RequestResponse struct {
	Request  Request
	Response Response
}

RequestResponse contains a request response and the respective request that was used.

func DoRequests

func DoRequests(ctx context.Context, downstream Handler, reqs []Request, parallelism int) ([]RequestResponse, error)

DoRequests executes a list of requests in parallel.

type Response

type Response = definitions.Response

type ResultsCacheConfig

type ResultsCacheConfig struct {
	resultscache.Config `yaml:",inline"`
}

ResultsCacheConfig is the config for the results cache.

func (*ResultsCacheConfig) RegisterFlags

func (cfg *ResultsCacheConfig) RegisterFlags(f *flag.FlagSet)

RegisterFlags registers flags.

type ResultsCacheMetrics

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

func NewResultsCacheMetrics

func NewResultsCacheMetrics(registerer prometheus.Registerer) *ResultsCacheMetrics

type RetryMiddlewareMetrics

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

func NewRetryMiddlewareMetrics

func NewRetryMiddlewareMetrics(registerer prometheus.Registerer, metricsNamespace string) *RetryMiddlewareMetrics

type RoundTripFunc

type RoundTripFunc func(*http.Request) (*http.Response, error)

RoundTripFunc is to http.RoundTripper what http.HandlerFunc is to http.Handler.

func (RoundTripFunc) RoundTrip

func (f RoundTripFunc) RoundTrip(r *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper.

type SampleStream

type SampleStream struct {
	Labels  []github_com_grafana_loki_v3_pkg_logproto.LabelAdapter `protobuf:"bytes,1,rep,name=labels,proto3,customtype=github.com/grafana/loki/v3/pkg/logproto.LabelAdapter" json:"metric"`
	Samples []logproto.LegacySample                                `protobuf:"bytes,2,rep,name=samples,proto3" json:"values"`
}

func FromResult

func FromResult(res *promql.Result) ([]SampleStream, error)

FromResult transforms a promql query result into a samplestream

func FromValue

func FromValue(value parser.Value) ([]SampleStream, error)

func ResponseToSamples

func ResponseToSamples(resp Response) ([]SampleStream, error)

ResponseToSamples is needed to map back from api response to the underlying series data

func (*SampleStream) Descriptor

func (*SampleStream) Descriptor() ([]byte, []int)

func (*SampleStream) Equal

func (this *SampleStream) Equal(that interface{}) bool

func (*SampleStream) GetSamples

func (m *SampleStream) GetSamples() []logproto.LegacySample

func (*SampleStream) GoString

func (this *SampleStream) GoString() string

func (*SampleStream) Marshal

func (m *SampleStream) Marshal() (dAtA []byte, err error)

func (*SampleStream) MarshalJSON

func (s *SampleStream) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*SampleStream) MarshalTo

func (m *SampleStream) MarshalTo(dAtA []byte) (int, error)

func (*SampleStream) MarshalToSizedBuffer

func (m *SampleStream) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*SampleStream) ProtoMessage

func (*SampleStream) ProtoMessage()

func (*SampleStream) Reset

func (m *SampleStream) Reset()

func (*SampleStream) Size

func (m *SampleStream) Size() (n int)

func (*SampleStream) String

func (this *SampleStream) String() string

func (*SampleStream) Unmarshal

func (m *SampleStream) Unmarshal(dAtA []byte) error

func (*SampleStream) UnmarshalJSON

func (s *SampleStream) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*SampleStream) XXX_DiscardUnknown

func (m *SampleStream) XXX_DiscardUnknown()

func (*SampleStream) XXX_Marshal

func (m *SampleStream) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*SampleStream) XXX_Merge

func (m *SampleStream) XXX_Merge(src proto.Message)

func (*SampleStream) XXX_Size

func (m *SampleStream) XXX_Size() int

func (*SampleStream) XXX_Unmarshal

func (m *SampleStream) XXX_Unmarshal(b []byte) error

type ShardLabelSeries

type ShardLabelSeries struct {
	storage.Series
	// contains filtered or unexported fields
}

ShardLabelSeries allows extending a Series with new labels. This is helpful for adding cortex shard labels

func (*ShardLabelSeries) Labels

func (s *ShardLabelSeries) Labels() labels.Labels

Labels impls storage.Series

type ShouldCacheFn

type ShouldCacheFn func(ctx context.Context, r Request) bool

ShouldCacheFn checks whether the current request should go to cache or not. If not, just send the request to next handler.

type Tripperware

type Tripperware func(http.RoundTripper) http.RoundTripper

Tripperware is a signature for all http client-side middleware.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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