prometheus

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API interface {
	Query(ctx context.Context, query string, ts time.Time, opts ...apiv1.Option) (model.Value, apiv1.Warnings, error)
	QueryRange(ctx context.Context, query string, r apiv1.Range, opts ...apiv1.Option) (model.Value, apiv1.Warnings, error)
}

API is a subset of Prometheus API interface. https://github.com/prometheus/client_golang/blob/release-1.14/api/prometheus/v1/api.go#L221-L266 This subset allows us to implement in our tests only the functions we use, while allowing compatibility with Prometheus API interface.

type Configuration

type Configuration struct {
	PrometheusURL                 string `default:"http://localhost:9090" validate:"url"`
	MetricsUpdateIntervalInMS     int    `default:"1000" validate:"range:[0,]"`
	HealthcheckUpdateIntervalInMS int    `default:"60000" validate:"range:[0,]"`
}

type Helper

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

func NewHelper

func NewHelper(prometheusURL string) (*Helper, error)

NewHelper creates a helper with the standard Prometheus client and API inside it, encapsulating all Prometheus dependencies.

func (*Helper) Matrix

func (p *Helper) Matrix(query string, startTime, endTime time.Time) (model.Matrix, error)

Matrix returns the matrix of metrics of a query in the given duration. It ensures that the returned matrix has atleast one row.

func (*Helper) SetAPI

func (p *Helper) SetAPI(api API)

SetAPI is used to replace the API interface used to communicate with Prometheus. Helpful to mock tests from other packages.

func (*Helper) VectorFirst

func (p *Helper) VectorFirst(query string) (float64, error)

VectorFirst returns the first element from a vector query.

type Query

type Query struct {
	// The description for the query.
	Description string `validate:"notempty"`
	// The PromQL query to be run.
	Query string `validate:"notempty"`
	// The value over which the performance monitor will fire an alert
	// to the coordinator's feedback loop.
	Threshold float64 `validate:"range:[0,]"`
	// The minimum amount of time (in seconds) that needs to have passed
	// since the start of the monitoring process before the query can be run.
	MinIntervalSec int `validate:"range:[0,]"`
	// The value indicating whether or not to fire an alert.
	Alert bool
}

Query contains the needed information to perform a query.

Jump to

Keyboard shortcuts

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