astmapper

package
v0.0.0-...-ae9624b Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EmbeddedQueriesLabelName is a reserved label name containing embedded queries.
	EmbeddedQueriesLabelName = "__queries__"

	// EmbeddedQueriesMetricName is a reserved metric name denoting a special metric which contains embedded queries.
	EmbeddedQueriesMetricName = "__embedded_queries__"
)
View Source
const (
	SkippedReasonSmallInterval = SkippedReason("small-interval")
	SkippedReasonSubquery      = SkippedReason("subquery")
	SkippedReasonNonSplittable = SkippedReason("non-splittable")
)

Possible skipped reasons

Variables

View Source
var FuncsWithDefaultTimeArg = []string{
	"day_of_month",
	"day_of_week",
	"day_of_year",
	"days_in_month",
	"hour",
	"minute",
	"month",
	"year",
}

FuncsWithDefaultTimeArg is the list of functions that extract date information from a variadic list of params, which defaults to be just time() otherwise.

View Source
var JSONCodec jsonCodec

JSONCodec is a Codec that uses JSON representations of EmbeddedQueries structs

View Source
var NonParallelFuncs = []string{

	"absent",
	"absent_over_time",
	"info",
	"histogram_quantile",
	"limitk",
	"limit_ratio",
	"sort_desc",
	"sort_by_label",
	"sort_by_label_desc",
	"sort",
	"time",
	"vector",

	"histogram_avg",
}

NonParallelFuncs is the list of functions that shouldn't be parallelized.

Functions

func CanParallelize

func CanParallelize(expr parser.Expr, logger log.Logger) bool

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

func ParallelizableFunc

func ParallelizableFunc(f parser.Function) bool

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

func VectorSquasher

func VectorSquasher(exprs ...EmbeddedQuery) (parser.Expr, error)

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

Types

type ASTExprMapper

type ASTExprMapper struct {
	ExprMapper
}

ASTExprMapper is an ASTMapper adapter which uses a ExprMapper internally.

func NewASTExprMapper

func NewASTExprMapper(mapper ExprMapper) ASTExprMapper

NewASTExprMapper creates an ASTMapper from a ExprMapper

func (ASTExprMapper) Map

func (em ASTExprMapper) Map(expr parser.Expr) (parser.Expr, error)

Map implements ASTMapper from a ExprMapper

type ASTMapper

type ASTMapper interface {
	// Map the input expr and returns the mapped expr.
	Map(expr parser.Expr) (mapped parser.Expr, err error)
}

ASTMapper is the exported interface for mapping between multiple AST representations

func NewInstantQuerySplitter

func NewInstantQuerySplitter(ctx context.Context, interval time.Duration, logger log.Logger, stats *InstantSplitterStats) ASTMapper

NewInstantQuerySplitter creates a new query range mapper.

func NewQueryPruner

func NewQueryPruner(ctx context.Context, logger log.Logger) ASTMapper

func NewQueryShardSummer

func NewQueryShardSummer(ctx context.Context, shards int, squasher Squasher, logger log.Logger, stats *MapperStats) (ASTMapper, error)

NewQueryShardSummer instantiates an ASTMapper which will fan out sum queries by shard.

func NewShardSummerWithLabeller

func NewShardSummerWithLabeller(ctx context.Context, shards int, squasher Squasher, logger log.Logger, stats *MapperStats, labeller ShardLabeller) (ASTMapper, error)

func NewSharding

func NewSharding(shardSummer ASTMapper) ASTMapper

NewSharding creates a new query sharding mapper.

type EmbeddedQueries

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

EmbeddedQueries is a wrapper type for encoding queries

type EmbeddedQuery

type EmbeddedQuery struct {
	Expr   string            `json:"Expr"`
	Params map[string]string `json:"Params,omitempty"`
}

func NewEmbeddedQuery

func NewEmbeddedQuery(expr string, params map[string]string) EmbeddedQuery

type ExprMapper

type ExprMapper interface {
	// MapExpr either maps a single AST expr or returns the unaltered expr.
	// It returns a finished bool to signal whether no further recursion is necessary.
	MapExpr(expr parser.Expr) (mapped parser.Expr, finished bool, err error)
}

type InstantSplitterStats

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

func NewInstantSplitterStats

func NewInstantSplitterStats() *InstantSplitterStats

func (*InstantSplitterStats) AddSplitQueries

func (s *InstantSplitterStats) AddSplitQueries(num int)

AddSplitQueries add num split queries to the counter.

func (*InstantSplitterStats) GetSkippedReason

func (s *InstantSplitterStats) GetSkippedReason() SkippedReason

GetSkippedReason returns the reason a query is a no operation. If number of split queries is greater than 0, it means the query is splittable Otherwise, if no skipped reason is set, it means the query is non-splittable

func (*InstantSplitterStats) GetSplitQueries

func (s *InstantSplitterStats) GetSplitQueries() int

GetSplitQueries returns the number of split queries.

func (*InstantSplitterStats) SetSkippedReason

func (s *InstantSplitterStats) SetSkippedReason(reason SkippedReason)

SetSkippedReason set no operation reason for query.

type MapperStats

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

func NewMapperStats

func NewMapperStats() *MapperStats

func (*MapperStats) AddShardedQueries

func (s *MapperStats) AddShardedQueries(num int)

AddShardedQueries add num sharded queries to the counter.

func (*MapperStats) GetShardedQueries

func (s *MapperStats) GetShardedQueries() int

GetShardedQueries returns the number of sharded queries.

type MultiMapper

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

MultiMapper can compose multiple ASTMappers

func NewMultiMapper

func NewMultiMapper(xs ...ASTMapper) *MultiMapper

NewMultiMapper instantiates an ASTMapper from multiple ASTMappers.

func (*MultiMapper) Map

func (m *MultiMapper) Map(expr parser.Expr) (parser.Expr, 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 exprs that each function cares about, defaulting to cloneExpr.

type ShardLabeller

type ShardLabeller interface {
	GetLabelMatcher(shard int) (*labels.Matcher, error)
	GetParams(shard int) map[string]string
}

type SkippedReason

type SkippedReason string

type Squasher

type Squasher = func(...EmbeddedQuery) (parser.Expr, error)

Jump to

Keyboard shortcuts

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