metricsreader

package
v1.3.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	LabelNameInstance = "instance"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BackendReader added in v1.2.0

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

func NewBackendReader added in v1.2.0

func NewBackendReader(lg *zap.Logger, cfgGetter config.ConfigGetter, httpCli *http.Client, etcdCli *clientv3.Client,
	backendFetcher TopologyFetcher, cfg *config.HealthCheck) *BackendReader

func (*BackendReader) AddQueryRule added in v1.2.0

func (br *BackendReader) AddQueryRule(key string, rule QueryRule)

func (*BackendReader) Close added in v1.2.0

func (br *BackendReader) Close()

func (*BackendReader) GetBackendMetrics added in v1.2.0

func (br *BackendReader) GetBackendMetrics() []byte

func (*BackendReader) GetQueryResult added in v1.2.0

func (br *BackendReader) GetQueryResult(key string) QueryResult

func (*BackendReader) OnElected added in v1.2.0

func (br *BackendReader) OnElected()

func (*BackendReader) OnRetired added in v1.2.0

func (br *BackendReader) OnRetired()

func (*BackendReader) PreClose added in v1.2.0

func (br *BackendReader) PreClose()

func (*BackendReader) ReadMetrics added in v1.2.0

func (br *BackendReader) ReadMetrics(ctx context.Context) error

func (*BackendReader) RemoveQueryRule added in v1.2.0

func (br *BackendReader) RemoveQueryRule(key string)

func (*BackendReader) Start added in v1.2.0

func (br *BackendReader) Start(ctx context.Context) error

type DefaultMetricsReader

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

func NewDefaultMetricsReader

func NewDefaultMetricsReader(lg *zap.Logger, promFetcher PromInfoFetcher, backendFetcher TopologyFetcher, httpCli *http.Client,
	etcdCli *clientv3.Client, cfg *config.HealthCheck, cfgGetter config.ConfigGetter) *DefaultMetricsReader

func (*DefaultMetricsReader) AddQueryExpr

func (dmr *DefaultMetricsReader) AddQueryExpr(key string, queryExpr QueryExpr, queryRule QueryRule)

func (*DefaultMetricsReader) Close

func (dmr *DefaultMetricsReader) Close()

func (*DefaultMetricsReader) GetBackendMetrics added in v1.2.0

func (dmr *DefaultMetricsReader) GetBackendMetrics() []byte

func (*DefaultMetricsReader) GetQueryResult

func (dmr *DefaultMetricsReader) GetQueryResult(key string) QueryResult

GetQueryResult returns an empty result if the key or the result is not found.

func (*DefaultMetricsReader) PreClose added in v1.2.0

func (dmr *DefaultMetricsReader) PreClose()

func (*DefaultMetricsReader) RemoveQueryExpr

func (dmr *DefaultMetricsReader) RemoveQueryExpr(key string)

func (*DefaultMetricsReader) Start

func (dmr *DefaultMetricsReader) Start(ctx context.Context) error

type MetricsReader

type MetricsReader interface {
	Start(ctx context.Context) error
	AddQueryExpr(key string, queryExpr QueryExpr, queryRule QueryRule)
	RemoveQueryExpr(key string)
	GetQueryResult(key string) QueryResult
	GetBackendMetrics() []byte
	PreClose()
	Close()
}

type PromInfoFetcher

type PromInfoFetcher interface {
	GetPromInfo(ctx context.Context) (*infosync.PrometheusInfo, error)
}

PromInfoFetcher is an interface to fetch the Prometheus info from ETCD.

type PromReader added in v1.2.0

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

func NewPromReader added in v1.2.0

func NewPromReader(lg *zap.Logger, promFetcher PromInfoFetcher, cfg *config.HealthCheck) *PromReader

func (*PromReader) AddQueryExpr added in v1.2.0

func (pr *PromReader) AddQueryExpr(key string, queryExpr QueryExpr)

func (*PromReader) Close added in v1.2.0

func (pr *PromReader) Close()

func (*PromReader) GetQueryResult added in v1.2.0

func (pr *PromReader) GetQueryResult(key string) QueryResult

func (*PromReader) ReadMetrics added in v1.2.0

func (pr *PromReader) ReadMetrics(ctx context.Context) error

func (*PromReader) RemoveQueryExpr added in v1.2.0

func (pr *PromReader) RemoveQueryExpr(key string)

type QueryExpr

type QueryExpr struct {
	PromQL   string
	Range    time.Duration
	HasLabel bool
}

QueryExpr is used for querying Prometheus.

func (QueryExpr) PromRange

func (qe QueryExpr) PromRange(curTime time.Time) promv1.Range

type QueryResult

type QueryResult struct {
	Value      model.Value
	UpdateTime time.Time
}

func (QueryResult) Empty

func (qr QueryResult) Empty() bool

func (QueryResult) GetSample4Backend

func (qr QueryResult) GetSample4Backend(backend policy.BackendCtx) *model.Sample

GetSample4Backend returns metric of a backend from a vector.

func (QueryResult) GetSamplePair4Backend

func (qr QueryResult) GetSamplePair4Backend(backend policy.BackendCtx) []model.SamplePair

GetSamplePair4Backend returns metric of a backend from a matrix.

type QueryRule added in v1.2.0

type QueryRule struct {
	// Names are the metric names that to be extracted from backend metrics.
	Names []string
	// Retention is the retention time of the metrics. Older metrics are expired.
	Retention time.Duration
	// Metric2Value defines the process from backend metrics (at a timepoint) to a float value.
	// E.g. division or aggregation.
	Metric2Value func(mfs map[string]*dto.MetricFamily) model.SampleValue
	// Range2Value defines the process from a time range of values to a float value.
	// E.g. irate[30s] or increase[1m].
	Range2Value func(pairs []model.SamplePair) model.SampleValue
	// ResultType indicates returning a vector or matrix as the final result.
	ResultType model.ValueType
}

QueryRule is used for processing the result from backend HTTP metrics API. It's too complicated for the BackendReader to parse PromQL, so let the caller to define the process function.

type TopologyFetcher added in v1.2.0

type TopologyFetcher interface {
	GetTiDBTopology(ctx context.Context) (map[string]*infosync.TiDBTopologyInfo, error)
}

TopologyFetcher is an interface to fetch the tidb topology from ETCD.

Jump to

Keyboard shortcuts

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