astmapper

package
v1.3.0-rc.1.0...-65594da Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// QueryLabel is a reserved label containing an embedded query
	QueryLabel = "__cortex_queries__"
	// EmbeddedQueriesMetricName is a reserved label (metric name) denoting an embedded query
	EmbeddedQueriesMetricName = "__embedded_queries__"
)
View Source
const (
	// ShardLabel is a reserved label referencing a cortex shard
	ShardLabel = "__cortex_shard__"
	// ShardLabelFmt is the fmt of the ShardLabel key.
	ShardLabelFmt = "%d_of_%d"
)

Variables

View Source
var JSONCodec jsonCodec

JSONCodec is a Codec that uses JSON representations of EmbeddedQueries structs

View Source
var (
	// ShardLabelRE matches a value in ShardLabelFmt
	ShardLabelRE = regexp.MustCompile("^[0-9]+_of_[0-9]+$")
)

Functions

func CanParallelize

func CanParallelize(node parser.Node) bool

CanParallelize tests if a subtree is parallelizable. A subtree is parallelizable if all of its components are parallelizable.

func CloneNode

func CloneNode(node parser.Node) (parser.Node, error)

CloneNode is a helper function to clone a node.

func ParallelizableFunc

func ParallelizableFunc(f parser.Function) bool

ParallelizableFunc ensures that a promql function can be part of a parallel query.

func Predicate

func Predicate(node parser.Node, fn predicate) (bool, error)

Predicate is a helper which uses parser.Walk under the hood determine if any node in a subtree returns true for a specified function

func VectorSquasher

func VectorSquasher(nodes ...parser.Node) (parser.Expr, error)

VectorSquash reduces an AST into a single vector query which can be hijacked by a Queryable impl. It always uses a VectorSelector as the substitution node. This is important because logical/set binops can only be applied against vectors and not matrices.

Types

type ASTMapper

type ASTMapper interface {
	Map(node parser.Node) (parser.Node, error)
}

ASTMapper is the exported interface for mapping between multiple AST representations

func NewShardSummer

func NewShardSummer(shards int, squasher squasher, shardedQueries prometheus.Counter) (ASTMapper, error)

NewShardSummer instantiates an ASTMapper which will fan out sum queries by shard

func NewSubtreeFolder

func NewSubtreeFolder() ASTMapper

NewSubtreeFolder creates a subtreeFolder which can reduce an AST to one embedded query if it contains no embedded queries yet

type ASTNodeMapper

type ASTNodeMapper struct {
	NodeMapper
}

ASTNodeMapper is an ASTMapper adapter which uses a NodeMapper internally.

func NewASTNodeMapper

func NewASTNodeMapper(mapper NodeMapper) ASTNodeMapper

NewASTNodeMapper creates an ASTMapper from a NodeMapper

func (ASTNodeMapper) Map

func (nm ASTNodeMapper) Map(node parser.Node) (parser.Node, error)

Map implements ASTMapper from a NodeMapper

type EmbeddedQueries

type EmbeddedQueries struct {
	Concat []string `json:"Concat"`
}

EmbeddedQueries is a wrapper type for encoding queries

type MapperFunc

type MapperFunc func(node parser.Node) (parser.Node, error)

MapperFunc is a function adapter for ASTMapper

func (MapperFunc) Map

func (fn MapperFunc) Map(node parser.Node) (parser.Node, error)

Map applies a mapperfunc as an ASTMapper

type MultiMapper

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

MultiMapper can compose multiple ASTMappers

func NewMultiMapper

func NewMultiMapper(xs ...ASTMapper) *MultiMapper

NewMultiMapper instaniates an ASTMapper from multiple ASTMappers

func (*MultiMapper) Map

func (m *MultiMapper) Map(node parser.Node) (parser.Node, error)

Map implements ASTMapper

func (*MultiMapper) Register

func (m *MultiMapper) Register(xs ...ASTMapper)

Register adds ASTMappers into a multimapper. Since registered functions are applied in the order they're registered, it's advised to register them in decreasing priority and only operate on nodes that each function cares about, defaulting to CloneNode.

type NodeMapper

type NodeMapper interface {
	MapNode(node parser.Node) (mapped parser.Node, finished bool, err error)
}

NodeMapper either maps a single AST node or returns the unaltered node. It also returns a bool to signal that no further recursion is necessary. This is helpful because it allows mappers to only implement logic for node types they want to change. It makes some mappers trivially easy to implement

type NodeMapperFunc

type NodeMapperFunc func(node parser.Node) (parser.Node, bool, error)

NodeMapperFunc is an adapter for NodeMapper

func (NodeMapperFunc) MapNode

func (f NodeMapperFunc) MapNode(node parser.Node) (parser.Node, bool, error)

MapNode applies a NodeMapperFunc as a NodeMapper

type ShardAnnotation

type ShardAnnotation struct {
	Shard int
	Of    int
}

ShardAnnotation is a convenience struct which holds data from a parsed shard label

func ParseShard

func ParseShard(input string) (parsed ShardAnnotation, err error)

ParseShard will extract the shard information encoded in ShardLabelFmt

func ShardFromMatchers

func ShardFromMatchers(matchers []*labels.Matcher) (shard *ShardAnnotation, idx int, err error)

ShardFromMatchers extracts a ShardAnnotation and the index it was pulled from in the matcher list

func (ShardAnnotation) Label

func (shard ShardAnnotation) Label() labels.Label

Label generates the ShardAnnotation as a label

func (ShardAnnotation) String

func (shard ShardAnnotation) String() string

String encodes a shardAnnotation into a label value

Jump to

Keyboard shortcuts

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