query

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Equal         = nameToOperator("=")   // Value = 1. Equal translates to using '=' operator.
	NotEqual      = nameToOperator("!=")  // NotEqual translates to using '!=' operator.
	EqualRegex    = nameToOperator("=~")  // EqualRegex translates to using '=~' operator.
	NotEqualRegex = nameToOperator("!=~") // NotEqualRegex translates to using '!=~' operator.
)

Starting indices from 1 to not have Equal as the default matching operator. This also helps checking if a matching operator was provided. If the value is 0, then it would indicate that no matching operator was provided.

View Source
var (
	Other        = labelTypeIota() // Default label type.
	TaskID       = labelTypeIota() // Indicates a dedicated label that can be keyed in to get unique task identifier.
	TaskHostname = labelTypeIota() // Indicates a dedicated label that can be keyed in to get name of host on which task is running.
)

By default, label matchers are assigned the "Other" type. However, if the label in a label matcher can be used to fetch the task identifier and/or name of the host on which the task is currently running, the type of the label matcher should be set to TaskID or TaskHostname respectively.

View Source
var (
	Seconds = nameToUnit("s") // Value = 1
	Minutes = nameToUnit("m")
	Hours   = nameToUnit("h")
	Days    = nameToUnit("d")
	Weeks   = nameToUnit("w")
	Years   = nameToUnit("y")
	None    = nameToUnit("none") // Represents nil value for TimeUnit.
)

Starting indices from 1 to not have Seconds as the default time unit. This also helps checking if a time unit was provided. If the value is 0, then it would indicate that time unit was not provided.

Functions

This section is empty.

Types

type Builder

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

Builder represents a query builder that is used to build a query string in promQL format.

func NewBuilder added in v0.4.0

func NewBuilder(options ...Option) *Builder

NewBuilder returns a new Builder by applying all the given options.

func (Builder) BuildQuery

func (b Builder) BuildQuery() string

BuildQuery builds and returns the query string.

type LabelMatchOperator

type LabelMatchOperator int

Label match operator to use when filtering time series data.

func (LabelMatchOperator) IsValid

func (o LabelMatchOperator) IsValid() bool

IsValid returns if an operator is valid.

func (LabelMatchOperator) String

func (o LabelMatchOperator) String() string

String returns the string representation of the operator.

type LabelMatcher

type LabelMatcher struct {
	// Type of the label matcher.
	// This information is used internally and is not required to build the prometheus query.
	// If Type != Other, then label matcher is considered a dedicated label matcher.
	Type LabelType
	// Label name used to filter the time series data.
	Label string
	// Operator is used to specify the operator to use when matching (=, !=, =~, !=~).
	Operator LabelMatchOperator
	// Value to match for.
	// If the regex matching, then value represents the regular expression.
	Value string
}

LabelMatcher represents a single label matcher containing the label name (key), the matching operator and the value.

func (LabelMatcher) String

func (m LabelMatcher) String() string

String returns the label, operator and value in the format <Label><Operator>"<Value>". This string can directly be used in the query string.

type LabelType added in v0.3.0

type LabelType int

Type of the label.

func (LabelType) IsValid added in v0.3.0

func (t LabelType) IsValid() bool

IsValid returns if the label type is valid.

type Option

type Option func(*Builder)

func WithLabelMatchers

func WithLabelMatchers(labelMatchers ...*LabelMatcher) Option

WithLabelMatchers returns an option that initializes the label matchers to use as filters in the query string.

func WithMetric

func WithMetric(metric string) Option

WithMetric returns an option that initializes the name of the metric to query.

func WithRange

func WithRange(timeUnit TimeUnit, durationQty uint) Option

WithRange returns an option that initializes the time unit and the duration when performing range queries.

type TimeUnit

type TimeUnit int

func (TimeUnit) IsValid

func (t TimeUnit) IsValid() bool

IsValid returns if a time unit is valid.

func (TimeUnit) String

func (t TimeUnit) String() string

Return the string representation of the time unit used in range queries.

Jump to

Keyboard shortcuts

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