github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/pkg/querier/queryrange/queryrangebase/definitions/interface.go (about) 1 package definitions 2 3 import ( 4 "context" 5 "net/http" 6 7 "github.com/gogo/protobuf/proto" 8 "github.com/opentracing/opentracing-go" 9 ) 10 11 // Codec is used to encode/decode query range requests and responses so they can be passed down to middlewares. 12 type Codec interface { 13 Merger 14 // DecodeRequest decodes a Request from an http request. 15 DecodeRequest(_ context.Context, request *http.Request, forwardHeaders []string) (Request, error) 16 // DecodeResponse decodes a Response from an http response. 17 // The original request is also passed as a parameter this is useful for implementation that needs the request 18 // to merge result or build the result correctly. 19 DecodeResponse(context.Context, *http.Response, Request) (Response, error) 20 // EncodeRequest encodes a Request into an http request. 21 EncodeRequest(context.Context, Request) (*http.Request, error) 22 // EncodeResponse encodes a Response into an http response. 23 EncodeResponse(context.Context, Response) (*http.Response, error) 24 } 25 26 // Merger is used by middlewares making multiple requests to merge back all responses into a single one. 27 type Merger interface { 28 // MergeResponse merges responses from multiple requests into a single Response 29 MergeResponse(...Response) (Response, error) 30 } 31 32 // Request represents a query range request that can be process by middlewares. 33 type Request interface { 34 // GetStart returns the start timestamp of the request in milliseconds. 35 GetStart() int64 36 // GetEnd returns the end timestamp of the request in milliseconds. 37 GetEnd() int64 38 // GetStep returns the step of the request in milliseconds. 39 GetStep() int64 40 // GetQuery returns the query of the request. 41 GetQuery() string 42 // GetCachingOptions returns the caching options. 43 GetCachingOptions() CachingOptions 44 // WithStartEnd clone the current request with different start and end timestamp. 45 WithStartEnd(startTime int64, endTime int64) Request 46 // WithQuery clone the current request with a different query. 47 WithQuery(string) Request 48 proto.Message 49 // LogToSpan writes information about this request to an OpenTracing span 50 LogToSpan(opentracing.Span) 51 } 52 53 // Response represents a query range response. 54 type Response interface { 55 proto.Message 56 // GetHeaders returns the HTTP headers in the response. 57 GetHeaders() []*PrometheusResponseHeader 58 }