Documentation ¶
Index ¶
- Constants
- Variables
- func CanParallelize(node parser.Node) bool
- func CloneNode(node parser.Node) (parser.Node, error)
- func ParallelizableFunc(f parser.Function) bool
- func Predicate(node parser.Node, fn predicate) (bool, error)
- func VectorSquasher(nodes ...parser.Node) (parser.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 ¶
CanParallelize tests if a subtree is parallelizable. A subtree is parallelizable if all of its components are parallelizable.
func ParallelizableFunc ¶
ParallelizableFunc ensures that a promql function can be part of a parallel query.
func Predicate ¶
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 ¶
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 ¶
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 ¶
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) 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 ¶
NodeMapperFunc is an adapter for NodeMapper
type ShardAnnotation ¶
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) Match ¶
func (shard ShardAnnotation) Match(fp model.Fingerprint) bool
func (ShardAnnotation) String ¶
func (shard ShardAnnotation) String() string
String encodes a shardAnnotation into a label value
func (ShardAnnotation) TSDB ¶
func (shard ShardAnnotation) TSDB() index.ShardAnnotation