Documentation
¶
Index ¶
- func Build(promql string, opts ...Option) (*query.Spec, error)
- func NewRangeOp(rng, offset time.Duration) (*query.Operation, error)
- func NewWhereOperation(metricName string, labels []*LabelMatcher) (*query.Operation, error)
- func Parse(filename string, b []byte, opts ...Option) (interface{}, error)
- func ParseFile(filename string, opts ...Option) (i interface{}, err error)
- func ParsePromQL(promql string, opts ...Option) (interface{}, error)
- func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error)
- type Aggregate
- type AggregateExpr
- type Arg
- type ArgKind
- type Comment
- type Duration
- type Identifier
- type LabelMatcher
- type MatchKind
- type Number
- type Operator
- type OperatorKind
- type Option
- type QueryBuilder
- type Selector
- type Stats
- type StringLiteral
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewWhereOperation ¶
func NewWhereOperation(metricName string, labels []*LabelMatcher) (*query.Operation, error)
func ParsePromQL ¶
Types ¶
type Aggregate ¶
type Aggregate struct { Without bool `json:"without,omitempty"` By bool `json:"by,omitempty"` KeepCommon bool `json:"keep_common,omitempty"` Labels []*Identifier `json:"labels,omitempty"` }
type AggregateExpr ¶
type AggregateExpr struct { Op *Operator `json:"op,omitempty"` Selector *Selector `json:"selector,omitempty"` Aggregate *Aggregate `json:"aggregate,omitempty"` }
func NewAggregateExpr ¶
func NewAggregateExpr(op *Operator, selector *Selector, group interface{}) (*AggregateExpr, error)
type Identifier ¶
type Identifier struct {
Name string `json:"name,omitempty"`
}
func NewIdentifierList ¶
func NewIdentifierList(first *Identifier, rest interface{}) ([]*Identifier, error)
func (*Identifier) Type ¶
func (id *Identifier) Type() ArgKind
func (*Identifier) Value ¶
func (id *Identifier) Value() interface{}
type LabelMatcher ¶
type LabelMatcher struct { Name string `json:"name,omitempty"` Kind MatchKind `json:"kind,omitempty"` Value Arg `json:"value,omitempty"` }
func NewLabelMatcher ¶
func NewLabelMatcher(ident *Identifier, kind MatchKind, value Arg) (*LabelMatcher, error)
func NewLabelMatches ¶
func NewLabelMatches(first *LabelMatcher, rest interface{}) ([]*LabelMatcher, error)
type Operator ¶
type Operator struct { Kind OperatorKind `json:"kind,omitempty"` Arg Arg `json:"arg,omitempty"` }
type OperatorKind ¶
type OperatorKind int
const ( UnknownOpKind OperatorKind = iota CountValuesKind TopKind BottomKind QuantileKind SumKind MinKind MaxKind AvgKind StdevKind StdVarKind CountKind )
func ToOperatorKind ¶
func ToOperatorKind(op string) OperatorKind
type Option ¶
type Option func(*parser) Option
Option is a function that can set an option on the parser. It returns the previous setting as an Option.
func Debug ¶
Debug creates an Option to set the debug flag to b. When set to true, debugging information is printed to stdout while parsing.
The default is false.
func GlobalStore ¶
GlobalStore creates an Option to set a key to a certain value in the globalStore.
func MaxExpressions ¶
MaxExpressions creates an Option to stop parsing after the provided number of expressions have been parsed, if the value is 0 then the parser will parse for as many steps as needed (possibly an infinite number).
The default for maxExprCnt is 0.
func Memoize ¶
Memoize creates an Option to set the memoize flag to b. When set to true, the parser will cache all results so each expression is evaluated only once. This guarantees linear parsing time even for pathological cases, at the expense of more memory and slower times for typical cases.
The default is false.
func Recover ¶
Recover creates an Option to set the recover flag to b. When set to true, this causes the parser to recover from panics and convert it to an error. Setting it to false can be useful while debugging to access the full stack trace.
The default is true.
func Statistics ¶
Statistics adds a user provided Stats struct to the parser to allow the user to process the results after the parsing has finished. Also the key for the "no match" counter is set.
Example usage:
input := "input" stats := Stats{} _, err := Parse("input-file", []byte(input), Statistics(&stats, "no match")) if err != nil { log.Panicln(err) } b, err := json.MarshalIndent(stats.ChoiceAltCnt, "", " ") if err != nil { log.Panicln(err) } fmt.Println(string(b))
type QueryBuilder ¶
type Selector ¶
type Selector struct { Name string `json:"name,omitempty"` Range time.Duration `json:"range,omitempty"` Offset time.Duration `json:"offset,omitempty"` LabelMatchers []*LabelMatcher `json:"label_matchers,omitempty"` }
func NewSelector ¶
func NewSelector(metric *Identifier, block, rng, offset interface{}) (*Selector, error)
type Stats ¶
type Stats struct { // ExprCnt counts the number of expressions processed during parsing // This value is compared to the maximum number of expressions allowed // (set by the MaxExpressions option). ExprCnt uint64 // ChoiceAltCnt is used to count for each ordered choice expression, // which alternative is used how may times. // These numbers allow to optimize the order of the ordered choice expression // to increase the performance of the parser // // The outer key of ChoiceAltCnt is composed of the name of the rule as well // as the line and the column of the ordered choice. // The inner key of ChoiceAltCnt is the number (one-based) of the matching alternative. // For each alternative the number of matches are counted. If an ordered choice does not // match, a special counter is incremented. The name of this counter is set with // the parser option Statistics. // For an alternative to be included in ChoiceAltCnt, it has to match at least once. ChoiceAltCnt map[string]map[string]int }
Stats stores some statistics, gathered during parsing
type StringLiteral ¶
type StringLiteral struct {
String string `json:"string,omitempty"`
}
func (*StringLiteral) Type ¶
func (s *StringLiteral) Type() ArgKind
func (*StringLiteral) Value ¶
func (s *StringLiteral) Value() interface{}