Documentation ¶
Index ¶
- Constants
- Variables
- func FromResult(res *promql.Result) ([]tripperware.SampleStream, error)
- func Middlewares(cfg Config, log log.Logger, limits tripperware.Limits, ...) ([]tripperware.Middleware, cache.Cache, error)
- func NewLimitsMiddleware(l tripperware.Limits, lookbackDelta time.Duration) tripperware.Middleware
- func NewPrometheusCodec(sharded bool, compressionStr string, defaultCodecTypeStr string) *prometheusCodec
- func NewResultsCacheMiddleware(logger log.Logger, cfg ResultsCacheConfig, splitter CacheSplitter, ...) (tripperware.Middleware, cache.Cache, error)
- func SplitByIntervalMiddleware(interval IntervalFn, limits tripperware.Limits, merger tripperware.Merger, ...) tripperware.Middleware
- type CacheSplitter
- type Config
- type Extractor
- type IntervalFn
- type PrometheusData
- func (*PrometheusData) Descriptor() ([]byte, []int)
- func (this *PrometheusData) Equal(that interface{}) bool
- func (m *PrometheusData) GetResult() []tripperware.SampleStream
- func (m *PrometheusData) GetResultType() string
- func (m *PrometheusData) GetStats() *tripperware.PrometheusResponseStats
- func (this *PrometheusData) GoString() string
- func (m *PrometheusData) Marshal() (dAtA []byte, err error)
- func (m *PrometheusData) MarshalTo(dAtA []byte) (int, error)
- func (m *PrometheusData) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*PrometheusData) ProtoMessage()
- func (m *PrometheusData) Reset()
- func (m *PrometheusData) Size() (n int)
- func (this *PrometheusData) String() string
- func (m *PrometheusData) Unmarshal(dAtA []byte) error
- func (m *PrometheusData) XXX_DiscardUnknown()
- func (m *PrometheusData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *PrometheusData) XXX_Merge(src proto.Message)
- func (m *PrometheusData) XXX_Size() int
- func (m *PrometheusData) XXX_Unmarshal(b []byte) error
- type PrometheusResponse
- func (*PrometheusResponse) Descriptor() ([]byte, []int)
- func (this *PrometheusResponse) Equal(that interface{}) bool
- func (m *PrometheusResponse) GetData() PrometheusData
- func (m *PrometheusResponse) GetError() string
- func (m *PrometheusResponse) GetErrorType() string
- func (m *PrometheusResponse) GetHeaders() []*tripperware.PrometheusResponseHeader
- func (m *PrometheusResponse) GetInfos() []string
- func (m *PrometheusResponse) GetStatus() string
- func (m *PrometheusResponse) GetWarnings() []string
- func (this *PrometheusResponse) GoString() string
- func (resp *PrometheusResponse) HTTPHeaders() map[string][]string
- func (m *PrometheusResponse) Marshal() (dAtA []byte, err error)
- func (m *PrometheusResponse) MarshalTo(dAtA []byte) (int, error)
- func (m *PrometheusResponse) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*PrometheusResponse) ProtoMessage()
- func (m *PrometheusResponse) Reset()
- func (m *PrometheusResponse) Size() (n int)
- func (this *PrometheusResponse) String() string
- func (m *PrometheusResponse) Unmarshal(dAtA []byte) error
- func (m *PrometheusResponse) XXX_DiscardUnknown()
- func (m *PrometheusResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *PrometheusResponse) XXX_Merge(src proto.Message)
- func (m *PrometheusResponse) XXX_Size() int
- func (m *PrometheusResponse) XXX_Unmarshal(b []byte) error
- type PrometheusResponseExtractor
- func (PrometheusResponseExtractor) Extract(start, end int64, from tripperware.Response) tripperware.Response
- func (PrometheusResponseExtractor) ResponseWithoutHeaders(resp tripperware.Response) tripperware.Response
- func (PrometheusResponseExtractor) ResponseWithoutStats(resp tripperware.Response) tripperware.Response
- type ResultsCacheConfig
- type ShouldCacheFn
Constants ¶
const StatusSuccess = "success"
StatusSuccess Prometheus success result.
Variables ¶
var ( ErrInvalidLengthQueryrange = fmt.Errorf("proto: negative length found during unmarshaling") ErrIntOverflowQueryrange = fmt.Errorf("proto: integer overflow") )
var StepAlignMiddleware = tripperware.MiddlewareFunc(func(next tripperware.Handler) tripperware.Handler {
return stepAlign{
next: next,
}
})
StepAlignMiddleware aligns the start and end of request to the step to improve the cacheability of the query results.
Functions ¶
func FromResult ¶
func FromResult(res *promql.Result) ([]tripperware.SampleStream, error)
FromResult transforms a promql query result into a samplestream
func Middlewares ¶
func Middlewares( cfg Config, log log.Logger, limits tripperware.Limits, cacheExtractor Extractor, registerer prometheus.Registerer, queryAnalyzer querysharding.Analyzer, prometheusCodec tripperware.Codec, shardedPrometheusCodec tripperware.Codec, lookbackDelta time.Duration, ) ([]tripperware.Middleware, cache.Cache, error)
Middlewares returns list of middlewares that should be applied for range query.
func NewLimitsMiddleware ¶
func NewLimitsMiddleware(l tripperware.Limits, lookbackDelta time.Duration) tripperware.Middleware
NewLimitsMiddleware creates a new Middleware that enforces query limits.
func NewPrometheusCodec ¶ added in v1.16.0
func NewResultsCacheMiddleware ¶
func NewResultsCacheMiddleware( logger log.Logger, cfg ResultsCacheConfig, splitter CacheSplitter, limits tripperware.Limits, merger tripperware.Merger, extractor Extractor, shouldCache ShouldCacheFn, reg prometheus.Registerer, ) (tripperware.Middleware, cache.Cache, 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 SplitByIntervalMiddleware ¶
func SplitByIntervalMiddleware(interval IntervalFn, limits tripperware.Limits, merger tripperware.Merger, registerer prometheus.Registerer) tripperware.Middleware
SplitByIntervalMiddleware creates a new Middleware that splits requests by a given interval.
Types ¶
type CacheSplitter ¶
type CacheSplitter interface {
GenerateCacheKey(userID string, r tripperware.Request) string
}
CacheSplitter generates cache keys. This is a useful interface for downstream consumers who wish to implement their own strategies.
type Config ¶
type Config struct { SplitQueriesByInterval time.Duration `yaml:"split_queries_by_interval"` AlignQueriesWithStep bool `yaml:"align_queries_with_step"` ResultsCacheConfig `yaml:"results_cache"` CacheResults bool `yaml:"cache_results"` MaxRetries int `yaml:"max_retries"` // List of headers which query_range middleware chain would forward to downstream querier. ForwardHeaders flagext.StringSlice `yaml:"forward_headers_list"` // Populated based on the query configuration VerticalShardSize int `yaml:"-"` }
Config for query_range middleware chain.
func (*Config) RegisterFlags ¶
RegisterFlags adds the flags required to config this to the given FlagSet.
type Extractor ¶
type Extractor interface { // Extract extracts a subset of a response from the `start` and `end` timestamps in milliseconds in the `from` response. Extract(start, end int64, from tripperware.Response) tripperware.Response ResponseWithoutHeaders(resp tripperware.Response) tripperware.Response ResponseWithoutStats(resp tripperware.Response) tripperware.Response }
Extractor is used by the cache to extract a subset of a response from a cache entry.
type IntervalFn ¶
type IntervalFn func(r tripperware.Request) time.Duration
type PrometheusData ¶
type PrometheusData struct { ResultType string `protobuf:"bytes,1,opt,name=ResultType,proto3" json:"resultType"` Result []tripperware.SampleStream `protobuf:"bytes,2,rep,name=Result,proto3" json:"result"` Stats *tripperware.PrometheusResponseStats `protobuf:"bytes,3,opt,name=stats,proto3" json:"stats,omitempty"` }
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() []tripperware.SampleStream
func (*PrometheusData) GetResultType ¶
func (m *PrometheusData) GetResultType() string
func (*PrometheusData) GetStats ¶
func (m *PrometheusData) GetStats() *tripperware.PrometheusResponseStats
func (*PrometheusData) GoString ¶
func (this *PrometheusData) GoString() string
func (*PrometheusData) Marshal ¶
func (m *PrometheusData) Marshal() (dAtA []byte, err 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 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 []*tripperware.PrometheusResponseHeader `protobuf:"bytes,5,rep,name=Headers,proto3" json:"-"` Warnings []string `protobuf:"bytes,6,rep,name=Warnings,proto3" json:"warnings,omitempty"` Infos []string `protobuf:"bytes,7,rep,name=Infos,proto3" json:"infos,omitempty"` }
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 (m *PrometheusResponse) GetHeaders() []*tripperware.PrometheusResponseHeader
func (*PrometheusResponse) GetInfos ¶
func (m *PrometheusResponse) GetInfos() []string
func (*PrometheusResponse) GetStatus ¶
func (m *PrometheusResponse) GetStatus() string
func (*PrometheusResponse) GetWarnings ¶ added in v1.18.0
func (m *PrometheusResponse) GetWarnings() []string
func (*PrometheusResponse) GoString ¶
func (this *PrometheusResponse) GoString() string
func (*PrometheusResponse) HTTPHeaders ¶
func (resp *PrometheusResponse) HTTPHeaders() map[string][]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) 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) 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 ¶
func (PrometheusResponseExtractor) Extract(start, end int64, from tripperware.Response) tripperware.Response
Extract extracts response for specific a range from a response.
func (PrometheusResponseExtractor) ResponseWithoutHeaders ¶
func (PrometheusResponseExtractor) ResponseWithoutHeaders(resp tripperware.Response) tripperware.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.
func (PrometheusResponseExtractor) ResponseWithoutStats ¶
func (PrometheusResponseExtractor) ResponseWithoutStats(resp tripperware.Response) tripperware.Response
ResponseWithoutStats is returns the response without the stats information
type ResultsCacheConfig ¶
type ResultsCacheConfig struct { CacheConfig cache.Config `yaml:"cache"` Compression string `yaml:"compression"` CacheQueryableSamplesStats bool `yaml:"cache_queryable_samples_stats"` }
ResultsCacheConfig is the config for the results cache.
func (*ResultsCacheConfig) RegisterFlags ¶
func (cfg *ResultsCacheConfig) RegisterFlags(f *flag.FlagSet)
RegisterFlags registers flags.
type ShouldCacheFn ¶
type ShouldCacheFn func(r tripperware.Request) bool
ShouldCacheFn checks whether the current request should go to cache or not. If not, just send the request to next handler.