formula - Overview
This file provides functionality to process and evaluate mathematical expressions on time series data, enabling operations like joining series based on labels and applying formulas.
Detailed Documentation
ExpressionEvalFunc
- Purpose: Defines a function type for evaluating a
govaluate.EvaluableExpression
with given parameters. - Parameters:
expression
(*govaluate.EvaluableExpression): The expression to evaluate.parameters
(map[string]float64): The parameters (variables and their values) for the expression.
- Returns: float64: The result of the expression evaluation.
isSubset
- Purpose: Checks if one label set (
sub
) is a subset of another label set (super
). - Parameters:
super
(map[string]string): The superset label set.sub
(map[string]string): The potential subset label set.
- Returns: bool:
true
ifsub
is a subset ofsuper
,false
otherwise.
findUniqueLabelSets
- Purpose: Identifies unique label sets from a list of results, considering only those associated with queries present in the provided expression. Uniqueness is determined by whether a label set is not a subset of any of the already identified unique label sets.
- Parameters:
results
([]*v3.Result): A slice of query results.queriesInExpression
(map[string]struct{}): A map of query names present in the expression.
- Returns: []map[string]string: A slice containing the unique label sets.
joinAndCalculate
- Purpose: Joins series based on timestamps and calculates new values using a given expression.
- Parameters:
results
([]*v3.Result): A slice of query results.uniqueLabelSet
(map[string]string): The label set to match series against.expression
(*govaluate.EvaluableExpression): The expression to evaluate.canDefaultZero
(map[string]bool): A map indicating whether a variable in the expression can default to zero if not found in the series.
- Returns:
*v3.Series
: The resulting series after joining and calculation.error
: An error, if any occurred.
processResults
- Purpose: Processes a list of query results, finds unique label sets, joins series based on these label sets, and calculates new values using the provided expression.
- Parameters:
results
([]*v3.Result): A slice of query results.expression
(*govaluate.EvaluableExpression): The expression to evaluate.canDefaultZero
(map[string]bool): A map indicating whether a variable in the expression can default to zero if not found in the series.
- Returns:
*v3.Result
: The resultingv3.Result
containing the processed series.error
: An error, if any occurred during processing.
SupportedFunctions
- Purpose: Defines a list of supported function names for use in expressions.
- Type:
[]string
- Example:
var SupportedFunctions = ["exp", "log", "ln", "exp2", "log2", "exp10", "log10", "sqrt", "cbrt", "erf", "erfc", "lgamma", "tgamma", "sin", "cos", "tan", "asin", "acos", "atan", "degrees", "radians", "now", "toUnixTimestamp"];
EvalFuncs
- Purpose: Returns a map of function names to their corresponding
govaluate.ExpressionFunction
implementations. These functions are used when evaluating expressions. - Returns: map[string]govaluate.ExpressionFunction: A map containing the supported functions. The keys are the function names (strings), and the values are the corresponding
govaluate.ExpressionFunction
implementations.
Code Examples
None
Include in Getting Started: NO