querytee

package
v0.0.0-...-9698ad8 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2024 License: AGPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ComparisonSuccess = ComparisonResult("success")
	ComparisonFailed  = ComparisonResult("fail")
	ComparisonSkipped = ComparisonResult("skip")
)

Variables

This section is empty.

Functions

func AddMissingTimeParam

func AddMissingTimeParam(r *http.Request, body []byte, logger *spanlogger.SpanLogger) (*http.Request, []byte, error)

AddMissingTimeParam adds a 'time' parameter to any query request that does not have one.

Instant queries without a 'time' parameter use the current time on the executing backend. However, this can vary between backends for the same request, which can cause comparison failures.

So, to make comparisons more reliable, we add the 'time' parameter in the proxy to ensure all backends use the same value.

Types

type ComparisonResult

type ComparisonResult string

type Proxy

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

func NewProxy

func NewProxy(cfg ProxyConfig, logger log.Logger, routes []Route, registerer prometheus.Registerer) (*Proxy, error)

func (*Proxy) Await

func (p *Proxy) Await()

func (*Proxy) Start

func (p *Proxy) Start() error

func (*Proxy) Stop

func (p *Proxy) Stop() error

type ProxyBackend

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

ProxyBackend holds the information of a single backend.

func (*ProxyBackend) Endpoint

func (b *ProxyBackend) Endpoint() *url.URL

func (*ProxyBackend) ForwardRequest

func (b *ProxyBackend) ForwardRequest(ctx context.Context, orig *http.Request, body io.ReadCloser) (time.Duration, int, []byte, *http.Response, error)

func (*ProxyBackend) Name

func (b *ProxyBackend) Name() string

func (*ProxyBackend) Preferred

func (b *ProxyBackend) Preferred() bool

type ProxyBackendInterface

type ProxyBackendInterface interface {
	Name() string
	Endpoint() *url.URL
	Preferred() bool
	ForwardRequest(ctx context.Context, orig *http.Request, body io.ReadCloser) (time.Duration, int, []byte, *http.Response, error)
}

func NewProxyBackend

func NewProxyBackend(name string, endpoint *url.URL, timeout time.Duration, preferred bool, skipTLSVerify bool) ProxyBackendInterface

NewProxyBackend makes a new ProxyBackend

type ProxyConfig

type ProxyConfig struct {
	ServerHTTPServiceAddress            string
	ServerHTTPServicePort               int
	ServerGracefulShutdownTimeout       time.Duration
	ServerGRPCServiceAddress            string
	ServerGRPCServicePort               int
	BackendEndpoints                    string
	PreferredBackend                    string
	BackendReadTimeout                  time.Duration
	CompareResponses                    bool
	LogSlowQueryResponseThreshold       time.Duration
	ValueComparisonTolerance            float64
	UseRelativeError                    bool
	PassThroughNonRegisteredRoutes      bool
	SkipRecentSamples                   time.Duration
	RequireExactErrorMatch              bool
	BackendSkipTLSVerify                bool
	AddMissingTimeParamToInstantQueries bool
	SecondaryBackendsRequestProportion  float64
}

func (*ProxyConfig) RegisterFlags

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

type ProxyEndpoint

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

func NewProxyEndpoint

func NewProxyEndpoint(backends []ProxyBackendInterface, route Route, metrics *ProxyMetrics, logger log.Logger, comparator ResponsesComparator, slowResponseThreshold time.Duration, secondaryBackendRequestProportion float64) *ProxyEndpoint

func (*ProxyEndpoint) ServeHTTP

func (p *ProxyEndpoint) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ProxyMetrics

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

func NewProxyMetrics

func NewProxyMetrics(registerer prometheus.Registerer) *ProxyMetrics

type RequestTransformer

type RequestTransformer func(r *http.Request, body []byte, logger *spanlogger.SpanLogger) (*http.Request, []byte, error)

RequestTransformer manipulates a proxied request before it is sent to downstream endpoints.

r.Body is ignored, use body instead.

type ResponsesComparator

type ResponsesComparator interface {
	Compare(expected, actual []byte) (ComparisonResult, error)
}

type Route

type Route struct {
	Path                string
	RouteName           string
	Methods             []string
	ResponseComparator  ResponsesComparator
	RequestTransformers []RequestTransformer
}

type SampleComparisonOptions

type SampleComparisonOptions struct {
	Tolerance              float64
	UseRelativeError       bool
	SkipRecentSamples      time.Duration
	RequireExactErrorMatch bool
}

type SamplesComparator

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

func NewSamplesComparator

func NewSamplesComparator(opts SampleComparisonOptions) *SamplesComparator

func (*SamplesComparator) Compare

func (s *SamplesComparator) Compare(expectedResponse, actualResponse []byte) (ComparisonResult, error)

func (*SamplesComparator) RegisterSamplesType

func (s *SamplesComparator) RegisterSamplesType(samplesType string, comparator SamplesComparatorFunc)

RegisterSamplesType registers custom sample types.

type SamplesComparatorFunc

type SamplesComparatorFunc func(expected, actual json.RawMessage, opts SampleComparisonOptions) error

SamplesComparatorFunc helps with comparing different types of samples coming from /api/v1/query and /api/v1/query_range routes.

type SamplesResponse

type SamplesResponse struct {
	Status    string
	ErrorType string
	Error     string
	Warnings  []string
	Infos     []string
	Data      struct {
		ResultType string
		Result     json.RawMessage
	}
}

Jump to

Keyboard shortcuts

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