datasource

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitSecretFlags

func InitSecretFlags()

InitSecretFlags must be called after flag.Parse and before any logging

func LabelCompare

func LabelCompare(a, b Labels) int

LabelCompare return negative if a is less than b, return 0 if they are the same eg. a=[]Label{{Name: "a", Value: "1"}},b=[]Label{{Name: "b", Value: "1"}}, return -1 a=[]Label{{Name: "a", Value: "2"}},b=[]Label{{Name: "a", Value: "1"}}, return 1 a=[]Label{{Name: "a", Value: "1"}},b=[]Label{{Name: "a", Value: "1"}}, return 0

func ShowDatasourceURL

func ShowDatasourceURL() bool

ShowDatasourceURL whether to show -datasource.url with sensitive information

Types

type Client

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

Client is a datasource entity for reading data, supported clients are enumerated in datasourceType. WARN: when adding a new field, remember to check if Clone() method needs to be updated.

func NewPrometheusClient

func NewPrometheusClient(baseURL string, authCfg *promauth.Config, appendTypePrefix bool, c *http.Client) *Client

NewPrometheusClient returns a new prometheus datasource client.

func (*Client) ApplyParams

func (c *Client) ApplyParams(params QuerierParams) *Client

ApplyParams - changes given querier params.

func (*Client) BuildWithParams

func (c *Client) BuildWithParams(params QuerierParams) Querier

BuildWithParams - implements interface.

func (*Client) Clone

func (c *Client) Clone() *Client

Clone clones shared http client and other configuration to the new client.

func (*Client) Query

func (c *Client) Query(ctx context.Context, query string, ts time.Time) (Result, *http.Request, error)

Query executes the given query and returns parsed response

func (*Client) QueryRange

func (c *Client) QueryRange(ctx context.Context, query string, start, end time.Time) (res Result, err error)

QueryRange executes the given query on the given time range. For Prometheus type see https://prometheus.io/docs/prometheus/latest/querying/api/#range-queries Graphite type isn't supported.

type FakeQuerier

type FakeQuerier struct {
	sync.Mutex
	// contains filtered or unexported fields
}

FakeQuerier is a mock querier that return predefined results and error message

func (*FakeQuerier) Add

func (fq *FakeQuerier) Add(metrics ...Metric)

Add appends metrics to querier result metrics

func (*FakeQuerier) BuildWithParams

func (fq *FakeQuerier) BuildWithParams(_ QuerierParams) Querier

BuildWithParams return FakeQuerier itself

func (*FakeQuerier) Query

func (fq *FakeQuerier) Query(_ context.Context, _ string, _ time.Time) (Result, *http.Request, error)

Query returns metrics restored in querier

func (*FakeQuerier) QueryRange

func (fq *FakeQuerier) QueryRange(ctx context.Context, q string, _, _ time.Time) (Result, error)

QueryRange performs query

func (*FakeQuerier) Reset

func (fq *FakeQuerier) Reset()

Reset reset querier's error message and results

func (*FakeQuerier) SetErr

func (fq *FakeQuerier) SetErr(err error)

SetErr sets query error message

type FakeQuerierWithDelay

type FakeQuerierWithDelay struct {
	FakeQuerier
	Delay time.Duration
}

FakeQuerierWithDelay mock querier with given delay duration

func (*FakeQuerierWithDelay) BuildWithParams

func (fqd *FakeQuerierWithDelay) BuildWithParams(_ QuerierParams) Querier

BuildWithParams returns itself

func (*FakeQuerierWithDelay) Query

func (fqd *FakeQuerierWithDelay) Query(ctx context.Context, expr string, ts time.Time) (Result, *http.Request, error)

Query returns query result after delay duration

type FakeQuerierWithRegistry

type FakeQuerierWithRegistry struct {
	sync.Mutex
	// contains filtered or unexported fields
}

FakeQuerierWithRegistry can store different results for different query expr

func (*FakeQuerierWithRegistry) BuildWithParams

func (fqr *FakeQuerierWithRegistry) BuildWithParams(_ QuerierParams) Querier

BuildWithParams returns itself

func (*FakeQuerierWithRegistry) Query

Query returns metrics restored in querier registry

func (*FakeQuerierWithRegistry) QueryRange

func (fqr *FakeQuerierWithRegistry) QueryRange(ctx context.Context, q string, _, _ time.Time) (Result, error)

QueryRange performs query

func (*FakeQuerierWithRegistry) Reset

func (fqr *FakeQuerierWithRegistry) Reset()

Reset clean querier's results registry

func (*FakeQuerierWithRegistry) Set

func (fqr *FakeQuerierWithRegistry) Set(key string, metrics ...Metric)

Set stores query result for given key

type Label

type Label struct {
	Name  string
	Value string
}

Label represents metric's label

type Labels

type Labels []Label

Labels is collection of Label

func ConvertToLabels

func ConvertToLabels(m map[string]string) (labelset Labels)

ConvertToLabels convert map to Labels

func (Labels) Len

func (ls Labels) Len() int

func (Labels) Less

func (ls Labels) Less(i, j int) bool

func (Labels) String

func (ls Labels) String() string

func (Labels) Swap

func (ls Labels) Swap(i, j int)

type Metric

type Metric struct {
	Labels     []Label
	Timestamps []int64
	Values     []float64
}

Metric is the basic entity which should be return by datasource

func (*Metric) AddLabel

func (m *Metric) AddLabel(key, value string)

AddLabel appends the given label to the label set

func (*Metric) DelLabel

func (m *Metric) DelLabel(key string)

DelLabel deletes the given label from the label set

func (*Metric) Label

func (m *Metric) Label(key string) string

Label returns the given label value. If label is missing empty string will be returned

func (*Metric) SetLabel

func (m *Metric) SetLabel(key, value string)

SetLabel adds or updates existing one label by the given key and label

func (*Metric) SetLabels

func (m *Metric) SetLabels(ls map[string]string)

SetLabels sets the given map as Metric labels

type Param

type Param struct {
	Key, Value string
}

Param represents an HTTP GET param

type Querier

type Querier interface {
	// Query executes instant request with the given query at the given ts.
	// It returns list of Metric in response, the http.Request used for sending query
	// and error if any. Returned http.Request can't be reused and its body is already read.
	// Query should stop once ctx is cancelled.
	Query(ctx context.Context, query string, ts time.Time) (Result, *http.Request, error)
	// QueryRange executes range request with the given query on the given time range.
	// It returns list of Metric in response and error if any.
	// QueryRange should stop once ctx is cancelled.
	QueryRange(ctx context.Context, query string, from, to time.Time) (Result, error)
}

Querier interface wraps Query and QueryRange methods

type QuerierBuilder

type QuerierBuilder interface {
	// BuildWithParams creates a new Querier object with the given params
	BuildWithParams(params QuerierParams) Querier
}

QuerierBuilder builds Querier with given params.

func Init

func Init(extraParams url.Values) (QuerierBuilder, error)

Init creates a Querier from provided flag values. Provided extraParams will be added as GET params for each request.

type QuerierParams

type QuerierParams struct {
	DataSourceType string
	// ApplyIntervalAsTimeFilter is only valid for vlogs datasource.
	// Set to true if there is no [timeFilter](https://docs.victoriametrics.com/victorialogs/logsql/#time-filter) in the rule expression,
	// and we will add evaluation interval as an additional timeFilter when querying.
	ApplyIntervalAsTimeFilter bool
	EvaluationInterval        time.Duration
	QueryParams               url.Values
	Headers                   map[string]string
	Debug                     bool
}

QuerierParams params for Querier.

type Result

type Result struct {
	// Data contains list of received Metric
	Data []Metric
	// SeriesFetched contains amount of time series processed by datasource
	// during query evaluation.
	// If nil, then this feature is not supported by the datasource.
	// SeriesFetched is supported by VictoriaMetrics since v1.90.
	SeriesFetched *int
}

Result represents expected response from the datasource

Jump to

Keyboard shortcuts

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