Documentation
¶
Index ¶
- Constants
- Variables
- func CanParallelize(node promql.Node) bool
- func CloneNode(node promql.Node) (promql.Node, error)
- func ParallelizableFunc(f promql.Function) bool
- func Predicate(node promql.Node, fn predicate) (bool, error)
- func VectorSquasher(nodes ...promql.Node) (promql.Expr, error)
- type ASTMapper
- type ASTNodeMapper
- type EmbeddedQueries
- type MapperFunc
- type MultiMapper
- type NodeMapper
- type NodeMapperFunc
- type ShardAnnotation
Constants ¶
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__"
)
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 ¶
var JSONCodec jsonCodec
JSONCodec is a Codec that uses JSON representations of EmbeddedQueries structs
var (
// ShardLabelRE matches a value in ShardLabelFmt
ShardLabelRE = regexp.MustCompile("^[0-9]+_of_[0-9]+$")
)
Functions ¶
func CanParallelize ¶
func CanParallelize(node promql.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 promql.Node) (promql.Node, error)
CloneNode is a helper function to clone a node.
func ParallelizableFunc ¶
func ParallelizableFunc(f promql.Function) bool
ParallelizableFunc ensures that a promql function can be part of a parallel query.
func Predicate ¶
func Predicate(node promql.Node, fn predicate) (bool, error)
Predicate is a helper which uses promql.Walk under the hood determine if any node in a subtree returns true for a specified function
func VectorSquasher ¶
func VectorSquasher(nodes ...promql.Node) (promql.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 promql.Node) (promql.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
type EmbeddedQueries ¶
type EmbeddedQueries struct {
Concat []string `json:"Concat"`
}
EmbeddedQueries is a wrapper type for encoding queries
type MapperFunc ¶
type MapperFunc func(node promql.Node) (promql.Node, error)
MapperFunc is a function adapter for 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 promql.Node) (promql.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 promql.Node) (mapped promql.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 promql.Node) (promql.Node, bool, error)
NodeMapperFunc is an adapter for 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