tripperware

package
v1.16.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 43 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxStep = 11000
)

Variables

View Source
var (
	ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowQuery   = fmt.Errorf("proto: integer overflow")
)
View Source
var (
	ErrSubQueryStepTooSmall = "exceeded maximum resolution of %d points per timeseries in subquery. Try increasing the step size of your subquery"
)

Functions

func BodyBuffer

func BodyBuffer(res *http.Response, logger log.Logger) ([]byte, error)

func BodyBufferFromHTTPGRPCResponse added in v1.16.0

func BodyBufferFromHTTPGRPCResponse(res *httpgrpc.HTTPResponse, logger log.Logger) ([]byte, error)

func EncodeTime

func EncodeTime(t int64) string

func MergeSampleStreams

func MergeSampleStreams(output map[string]SampleStream, sampleStreams []SampleStream)

MergeSampleStreams deduplicates sample streams using a map.

func NewRoundTripper

func NewRoundTripper(next http.RoundTripper, codec Codec, headers []string, middlewares ...Middleware) http.RoundTripper

NewRoundTripper merges a set of middlewares into an handler, then inject it into the `next` roundtripper using the codec to translate requests and responses.

func PrometheusResponseQueryableSamplesStatsPerStepJsoniterDecode

func PrometheusResponseQueryableSamplesStatsPerStepJsoniterDecode(ptr unsafe.Pointer, iter *jsoniter.Iterator)

func PrometheusResponseQueryableSamplesStatsPerStepJsoniterEncode

func PrometheusResponseQueryableSamplesStatsPerStepJsoniterEncode(ptr unsafe.Pointer, stream *jsoniter.Stream)

func SubQueryStepSizeCheck added in v1.16.0

func SubQueryStepSizeCheck(query string, defaultSubQueryInterval time.Duration, maxStep int64) error

SubQueryStepSizeCheck ensures the query doesn't contain too small step size in subqueries.

func TestQueryShardQuery

func TestQueryShardQuery(t *testing.T, instantQueryCodec Codec, shardedPrometheusCodec Codec)

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 Codec

type Codec interface {
	Merger
	// DecodeRequest decodes a Request from an http request.
	DecodeRequest(_ context.Context, request *http.Request, forwardHeaders []string) (Request, error)
	// DecodeResponse decodes a Response from an http response.
	// The original request is also passed as a parameter this is useful for implementation that needs the request
	// to merge result or build the result correctly.
	DecodeResponse(context.Context, *http.Response, Request) (Response, error)
	// EncodeRequest encodes a Request into an http request.
	EncodeRequest(context.Context, Request) (*http.Request, error)
	// EncodeResponse encodes a Response into an http response.
	EncodeResponse(context.Context, Response) (*http.Response, error)
}

Codec is used to encode/decode query range requests and responses so they can be passed down to middlewares.

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) *InstrumentMiddlewareMetrics

NewInstrumentMiddlewareMetrics makes a new InstrumentMiddlewareMetrics.

type Limits

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

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

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

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

	// QueryVerticalShardSize returns the maximum number of queriers that can handle requests for this user.
	QueryVerticalShardSize(userID string) int
}

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

type Merger

type Merger interface {
	// MergeResponse merges responses from multiple requests into a single Response
	MergeResponse(context.Context, Request, ...Response) (Response, error)
}

Merger is used by middlewares making multiple requests to merge back all responses into a single one.

type Middleware

type Middleware interface {
	Wrap(Handler) Handler
}

Middleware is a higher order Handler.

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 ShardByMiddleware

func ShardByMiddleware(logger log.Logger, limits Limits, merger Merger, queryAnalyzer querysharding.Analyzer) Middleware

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 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(ctx context.Context, method, statusCode string, start time.Time)

After implements instrument.Collector.

func (*NoopCollector) Before

func (c *NoopCollector) Before(ctx context.Context, method string, start time.Time)

Before implements instrument.Collector.

func (*NoopCollector) Register

func (c *NoopCollector) Register()

Register implements instrument.Collector.

type PrometheusRequestHeader

type PrometheusRequestHeader struct {
	Name   string   `protobuf:"bytes,1,opt,name=Name,proto3" json:"-"`
	Values []string `protobuf:"bytes,2,rep,name=Values,proto3" json:"-"`
}

func (*PrometheusRequestHeader) Descriptor

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

func (*PrometheusRequestHeader) Equal

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

func (*PrometheusRequestHeader) GetName

func (m *PrometheusRequestHeader) GetName() string

func (*PrometheusRequestHeader) GetValues

func (m *PrometheusRequestHeader) GetValues() []string

func (*PrometheusRequestHeader) GoString

func (this *PrometheusRequestHeader) GoString() string

func (*PrometheusRequestHeader) Marshal

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

func (*PrometheusRequestHeader) MarshalTo

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

func (*PrometheusRequestHeader) MarshalToSizedBuffer

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

func (*PrometheusRequestHeader) ProtoMessage

func (*PrometheusRequestHeader) ProtoMessage()

func (*PrometheusRequestHeader) Reset

func (m *PrometheusRequestHeader) Reset()

func (*PrometheusRequestHeader) Size

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

func (*PrometheusRequestHeader) String

func (this *PrometheusRequestHeader) String() string

func (*PrometheusRequestHeader) Unmarshal

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

func (*PrometheusRequestHeader) XXX_DiscardUnknown

func (m *PrometheusRequestHeader) XXX_DiscardUnknown()

func (*PrometheusRequestHeader) XXX_Marshal

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

func (*PrometheusRequestHeader) XXX_Merge

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

func (*PrometheusRequestHeader) XXX_Size

func (m *PrometheusRequestHeader) XXX_Size() int

func (*PrometheusRequestHeader) XXX_Unmarshal

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

type PrometheusResponseHeader

type PrometheusResponseHeader struct {
	Name   string   `protobuf:"bytes,1,opt,name=Name,proto3" json:"-"`
	Values []string `protobuf:"bytes,2,rep,name=Values,proto3" json:"-"`
}

func (*PrometheusResponseHeader) Descriptor

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

func (*PrometheusResponseHeader) Equal

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

func (*PrometheusResponseHeader) GetName

func (m *PrometheusResponseHeader) GetName() string

func (*PrometheusResponseHeader) GetValues

func (m *PrometheusResponseHeader) GetValues() []string

func (*PrometheusResponseHeader) GoString

func (this *PrometheusResponseHeader) GoString() string

func (*PrometheusResponseHeader) Marshal

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

func (*PrometheusResponseHeader) MarshalTo

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

func (*PrometheusResponseHeader) MarshalToSizedBuffer

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

func (*PrometheusResponseHeader) ProtoMessage

func (*PrometheusResponseHeader) ProtoMessage()

func (*PrometheusResponseHeader) Reset

func (m *PrometheusResponseHeader) Reset()

func (*PrometheusResponseHeader) Size

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

func (*PrometheusResponseHeader) String

func (this *PrometheusResponseHeader) String() string

func (*PrometheusResponseHeader) Unmarshal

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

func (*PrometheusResponseHeader) XXX_DiscardUnknown

func (m *PrometheusResponseHeader) XXX_DiscardUnknown()

func (*PrometheusResponseHeader) XXX_Marshal

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

func (*PrometheusResponseHeader) XXX_Merge

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

func (*PrometheusResponseHeader) XXX_Size

func (m *PrometheusResponseHeader) XXX_Size() int

func (*PrometheusResponseHeader) XXX_Unmarshal

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

type PrometheusResponseQueryableSamplesStatsPerStep

type PrometheusResponseQueryableSamplesStatsPerStep struct {
	Value       int64 `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"`
	TimestampMs int64 `protobuf:"varint,2,opt,name=timestamp_ms,json=timestampMs,proto3" json:"timestamp_ms,omitempty"`
}

func (*PrometheusResponseQueryableSamplesStatsPerStep) Descriptor

func (*PrometheusResponseQueryableSamplesStatsPerStep) Equal

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

func (*PrometheusResponseQueryableSamplesStatsPerStep) GetTimestampMs

func (*PrometheusResponseQueryableSamplesStatsPerStep) GetValue

func (*PrometheusResponseQueryableSamplesStatsPerStep) GoString

func (*PrometheusResponseQueryableSamplesStatsPerStep) Marshal

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

func (*PrometheusResponseQueryableSamplesStatsPerStep) MarshalTo

func (*PrometheusResponseQueryableSamplesStatsPerStep) MarshalToSizedBuffer

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

func (*PrometheusResponseQueryableSamplesStatsPerStep) ProtoMessage

func (*PrometheusResponseQueryableSamplesStatsPerStep) Reset

func (*PrometheusResponseQueryableSamplesStatsPerStep) Size

func (*PrometheusResponseQueryableSamplesStatsPerStep) String

func (*PrometheusResponseQueryableSamplesStatsPerStep) Unmarshal

func (*PrometheusResponseQueryableSamplesStatsPerStep) XXX_DiscardUnknown

func (m *PrometheusResponseQueryableSamplesStatsPerStep) XXX_DiscardUnknown()

func (*PrometheusResponseQueryableSamplesStatsPerStep) XXX_Marshal

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

func (*PrometheusResponseQueryableSamplesStatsPerStep) XXX_Merge

func (*PrometheusResponseQueryableSamplesStatsPerStep) XXX_Size

func (*PrometheusResponseQueryableSamplesStatsPerStep) XXX_Unmarshal

type PrometheusResponseSamplesStats

type PrometheusResponseSamplesStats struct {
	TotalQueryableSamples        int64                                             `protobuf:"varint,1,opt,name=totalQueryableSamples,proto3" json:"totalQueryableSamples"`
	TotalQueryableSamplesPerStep []*PrometheusResponseQueryableSamplesStatsPerStep `protobuf:"bytes,2,rep,name=totalQueryableSamplesPerStep,proto3" json:"totalQueryableSamplesPerStep"`
}

func (*PrometheusResponseSamplesStats) Descriptor

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

func (*PrometheusResponseSamplesStats) Equal

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

func (*PrometheusResponseSamplesStats) GetTotalQueryableSamples

func (m *PrometheusResponseSamplesStats) GetTotalQueryableSamples() int64

func (*PrometheusResponseSamplesStats) GetTotalQueryableSamplesPerStep

func (*PrometheusResponseSamplesStats) GoString

func (this *PrometheusResponseSamplesStats) GoString() string

func (*PrometheusResponseSamplesStats) Marshal

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

func (*PrometheusResponseSamplesStats) MarshalTo

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

func (*PrometheusResponseSamplesStats) MarshalToSizedBuffer

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

func (*PrometheusResponseSamplesStats) ProtoMessage

func (*PrometheusResponseSamplesStats) ProtoMessage()

func (*PrometheusResponseSamplesStats) Reset

func (m *PrometheusResponseSamplesStats) Reset()

func (*PrometheusResponseSamplesStats) Size

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

func (*PrometheusResponseSamplesStats) String

func (this *PrometheusResponseSamplesStats) String() string

func (*PrometheusResponseSamplesStats) Unmarshal

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

func (*PrometheusResponseSamplesStats) XXX_DiscardUnknown

func (m *PrometheusResponseSamplesStats) XXX_DiscardUnknown()

func (*PrometheusResponseSamplesStats) XXX_Marshal

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

func (*PrometheusResponseSamplesStats) XXX_Merge

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

func (*PrometheusResponseSamplesStats) XXX_Size

func (m *PrometheusResponseSamplesStats) XXX_Size() int

func (*PrometheusResponseSamplesStats) XXX_Unmarshal

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

type PrometheusResponseStats

type PrometheusResponseStats struct {
	Samples *PrometheusResponseSamplesStats `protobuf:"bytes,1,opt,name=samples,proto3" json:"samples"`
}

func (*PrometheusResponseStats) Descriptor

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

func (*PrometheusResponseStats) Equal

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

func (*PrometheusResponseStats) GetSamples

func (*PrometheusResponseStats) GoString

func (this *PrometheusResponseStats) GoString() string

func (*PrometheusResponseStats) Marshal

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

func (*PrometheusResponseStats) MarshalTo

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

func (*PrometheusResponseStats) MarshalToSizedBuffer

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

func (*PrometheusResponseStats) ProtoMessage

func (*PrometheusResponseStats) ProtoMessage()

func (*PrometheusResponseStats) Reset

func (m *PrometheusResponseStats) Reset()

func (*PrometheusResponseStats) Size

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

func (*PrometheusResponseStats) String

func (this *PrometheusResponseStats) String() string

func (*PrometheusResponseStats) Unmarshal

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

func (*PrometheusResponseStats) XXX_DiscardUnknown

func (m *PrometheusResponseStats) XXX_DiscardUnknown()

func (*PrometheusResponseStats) XXX_Marshal

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

func (*PrometheusResponseStats) XXX_Merge

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

func (*PrometheusResponseStats) XXX_Size

func (m *PrometheusResponseStats) XXX_Size() int

func (*PrometheusResponseStats) XXX_Unmarshal

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

type Request

type Request interface {
	// GetStart returns the start timestamp of the request in milliseconds.
	GetStart() int64
	// GetEnd returns the end timestamp of the request in milliseconds.
	GetEnd() int64
	// GetStep returns the step of the request in milliseconds.
	GetStep() int64
	// GetQuery returns the query of the request.
	GetQuery() string
	// WithStartEnd clone the current request with different start and end timestamp.
	WithStartEnd(startTime int64, endTime int64) Request
	// WithQuery clone the current request with a different query.
	WithQuery(string) Request
	proto.Message
	// LogToSpan writes information about this request to an OpenTracing span
	LogToSpan(opentracing.Span)
	// GetStats returns the stats of the request.
	GetStats() string
	// WithStats clones the current `PrometheusRequest` with a new stats.
	WithStats(stats string) Request
}

Request represents a query range request that can be process by middlewares.

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, limits Limits) ([]RequestResponse, error)

DoRequests executes a list of requests in parallel. The limits parameters is used to limit parallelism per single request.

type Response

type Response interface {
	proto.Message
	// HTTPHeaders returns the HTTP headers in the response.
	HTTPHeaders() map[string][]string
}

Response represents a query range response.

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_cortexproject_cortex_pkg_cortexpb.LabelAdapter `protobuf:"bytes,1,rep,name=labels,proto3,customtype=github.com/cortexproject/cortex/pkg/cortexpb.LabelAdapter" json:"metric"`
	Samples []cortexpb.Sample                                           `protobuf:"bytes,2,rep,name=samples,proto3" json:"values"`
}

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() []cortexpb.Sample

func (*SampleStream) GoString

func (this *SampleStream) GoString() string

func (*SampleStream) Marshal

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

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 Tripperware

type Tripperware func(http.RoundTripper) http.RoundTripper

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

func NewQueryTripperware

func NewQueryTripperware(
	log log.Logger,
	registerer prometheus.Registerer,
	forwardHeaders []string,
	queryRangeMiddleware []Middleware,
	instantRangeMiddleware []Middleware,
	queryRangeCodec Codec,
	instantQueryCodec Codec,
	limits Limits,
	queryAnalyzer querysharding.Analyzer,
	defaultSubQueryInterval time.Duration,
	maxSubQuerySteps int64,
) Tripperware

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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