ddqp

package module
v0.0.0-...-44b54cc Latest Latest
Warning

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

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

README

DDQP (DataDog Query Parser)

This package is intended to make the parsing of DataDog queries easier by providing a parser around which clients/tooling can be built. Looking around the DataDog community it was difficult to find a package for programatically interacting with existing queries or building up new queries. Thus this package was developed in an attempt to make parsing queries easier.

This package is not a client, it just provides structure around which clients or other tools can be built.

Architecture

This package is built around participle, which takes away the effort of building a full parser and instead allows us to focus on capturing the variations present in the DataDog query "language".

Developmemt

This project uses Hermit for managing dependencies and go tools.

Each portion of the parser is divided into its own file, and each file has an associated test file for validating the parser discreet pieces. The end goal is to combine each unit of a query into one top-level struct that encapsulates a full query. For example, a MetricQuery parser is built upon a MetricFilter parser.

Supported Queries

Currently there is only support for a simple metric query, but the goal is to layer in more functionality.

Documentation

Overview

Package ddqp aims to provide a parser for DataDog queries so that queries can be programatically generated and parsed within Go applications/utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bool

type Bool bool

func (*Bool) Capture

func (b *Bool) Capture(v []string) error

func (*Bool) String

func (b *Bool) String() string

type ExprValue

type ExprValue struct {
	Subexpression *MetricExpression `  "(" @@ ")"`
	MetricQuery   *MetricQuery      `| @@`
	Number        *float64          `| @Ident`
}

func (*ExprValue) GetQueries

func (expr *ExprValue) GetQueries() []string

func (*ExprValue) String

func (expr *ExprValue) String() string

type Factor

type Factor struct {
	Base *ExprValue `@@`
}

func (*Factor) GetQueries

func (f *Factor) GetQueries() []string

func (*Factor) String

func (f *Factor) String() string

type FilterKey

type FilterKey struct {
	Negative bool   `@"!"?`
	Key      string `@Ident`
}

func (*FilterKey) String

func (fk *FilterKey) String() string

type FilterSeparator

type FilterSeparator struct {
	Colon  bool `@":"`
	In     bool `| @("IN" | "in") `
	NotIn  bool `| @("NOT" "IN" | "not" "in")`
	AndNot bool `| @("AND" "NOT" | "and" "not")`
}

func (*FilterSeparator) String

func (fs *FilterSeparator) String() string

type FilterValue

type FilterValue struct {
	SimpleValue *Value   `	@@`
	ListValue   []*Value `| ( "(" @@* ")" )?`
}

func (*FilterValue) String

func (fv *FilterValue) String() string

type FilterValueSeparator

type FilterValueSeparator struct {
	Comma  bool ` @","`
	AndNot bool `| @("AND" "NOT" | "and" "not")`
	And    bool `| @("AND" | "and")`
	Or     bool `| @("OR" | "or")`
	In     bool `| @("IN" | "in")`
}

func (*FilterValueSeparator) String

func (fvs *FilterValueSeparator) String() string

type Function

type Function struct {
	Name string   `"." @Ident`
	Args []*Value `"(" ( @@ ( "," @@ )* )? ")"`
}

func (*Function) String

func (f *Function) String() string

type GroupedFilter

type GroupedFilter struct {
	Parameters []*Param `( @@* | "*" )?`
}

func (*GroupedFilter) String

func (gf *GroupedFilter) String() string

type MetricExpression

type MetricExpression struct {
	Pos lexer.Position

	Left  *Term     `@@`
	Right []*OpTerm `@@*`
}

func (*MetricExpression) GetQueries

func (me *MetricExpression) GetQueries() map[string]string

func (*MetricExpression) String

func (me *MetricExpression) String() string

type MetricExpressionFormula

type MetricExpressionFormula struct {
	Expressions map[string]string
	Formula     string
}

MetricExpressionFormula breaks down a query into its formulaic parts

func NewMetricExpressionFormula

func NewMetricExpressionFormula(expr *MetricExpression) *MetricExpressionFormula

type MetricExpressionParser

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

MetricExpressionParser is parser returned when calling NewMetricExpressionParser.

func NewMetricExpressionParser

func NewMetricExpressionParser() *MetricExpressionParser

NewMetricExpressionParser returns a Parser which is capable of interpretting a metric expression.

func (*MetricExpressionParser) Parse

func (mep *MetricExpressionParser) Parse(expr string) (*MetricExpression, error)

Parse sanitizes the query string and returns the AST and any error.

type MetricFilter

type MetricFilter struct {
	Pos lexer.Position

	Left       *Param   `(@@ | "*" )`
	Parameters []*Param `( @@* )`
}

func (*MetricFilter) String

func (mf *MetricFilter) String() string

type MetricMonitor

type MetricMonitor struct {
	Pos lexer.Position

	Aggregation      string       `@Ident`
	EvaluationWindow string       `"(" @Ident ")" ":"`
	MetricQuery      *MetricQuery `@@`
	Comparator       string       `@( ">" | ">" "=" | "<" | "<" "=" )`
	Threshold        float64      `@(Ident)`
}

func (*MetricMonitor) String

func (mm *MetricMonitor) String() string

String returns the string representation of the metric monitor.

type MetricMonitorParser

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

MetricMonitorParser is parser returned when calling NewMetricMonitorParser.

func NewMetricMonitorParser

func NewMetricMonitorParser() *MetricMonitorParser

NewMetricMonitorParser returns a Parser which is capable of interpretting a metric query.

func (*MetricMonitorParser) Parse

func (mmp *MetricMonitorParser) Parse(query string) (*MetricMonitor, error)

Parse sanitizes the query string and returns the AST and any error.

type MetricQuery

type MetricQuery struct {
	Pos lexer.Position

	Query []*Query `parser:"@@"`
}

func (*MetricQuery) String

func (mq *MetricQuery) String() string

type MetricQueryParser

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

MetricQueryParser is parser returned when calling NewMetricQueryParser.

func NewMetricQueryParser

func NewMetricQueryParser() *MetricQueryParser

NewMetricQueryParser returns a Parser which is capable of interpretting a metric query.

func (*MetricQueryParser) Parse

func (mqp *MetricQueryParser) Parse(query string) (*MetricQuery, error)

Parse sanitizes the query string and returns the AST and any error.

type OpFactor

type OpFactor struct {
	Operator Operator `@("*" | "/")`
	Factor   *Factor  `@@`
}

func (*OpFactor) String

func (o *OpFactor) String() string

type OpTerm

type OpTerm struct {
	Operator Operator `@("+" | "-")`
	Term     *Term    `@@`
}

func (*OpTerm) String

func (o *OpTerm) String() string

type Operator

type Operator int
const (
	OpMul Operator = iota
	OpDiv
	OpAdd
	OpSub
)

func (*Operator) Capture

func (o *Operator) Capture(s []string) error

func (Operator) String

func (o Operator) String() string

type Param

type Param struct {
	GroupedFilter *GroupedFilter        ` "(" @@ ")"`
	Separator     *FilterValueSeparator `| @@`
	SimpleFilter  *SimpleFilter         `| @@`
	Asterisk      bool                  `| @"*"`
}

func (*Param) String

func (p *Param) String() string

type Query

type Query struct {
	Pos lexer.Position

	Aggregator                string        `parser:"@Ident"`
	SpaceAggregationCondition string        `parser:"( '(' @SpaceAggregatorCondition ')' )?"`
	Separator                 string        `parser:"':'"`
	MetricName                string        `parser:"@Ident( @'.' @Ident)*"`
	Filters                   *MetricFilter `parser:"'{' @@ '}'"`
	By                        string        `parser:"Ident?"`
	Grouping                  []string      `parser:"'{'? ( @Ident ( ',' @Ident )* )? '}'?"`
	Function                  []*Function   `parser:"( @@ ( '.' @@ )* )?"`
}

func (*Query) String

func (q *Query) String() string

type SimpleFilter

type SimpleFilter struct {
	Negative        bool             `@"!"?`
	FilterKey       string           `@Ident`
	FilterSeparator *FilterSeparator `@@`
	FilterValue     *FilterValue     `@@`
}

func (*SimpleFilter) String

func (sf *SimpleFilter) String() string

type Term

type Term struct {
	Left  *Factor     `@@`
	Right []*OpFactor `@@*`
}

func (*Term) GetQueries

func (t *Term) GetQueries() []string

func (*Term) String

func (t *Term) String() string

type Value

type Value struct {
	Separator  *FilterValueSeparator ` @@`
	Boolean    *Bool                 `|  @("true"|"false")`
	Identifier *string               `| "!"? @Ident ( @"." @Ident )*`
	Str        *string               `| @(String)`
	Number     *float64              `| @(Float|Int)`
}

func (*Value) String

func (v *Value) String() string

Directories

Path Synopsis
_examples

Jump to

Keyboard shortcuts

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