Using eval() in Metric expressions


What happens if the start and end passed to the eval() metric function are different from the start and end of the query range (specified by EvalMetricSpec, not to be confused with eval())?



Let’s work this through an example:

Let’s say our expression = “sum(eval(‘HOUR’, SomeMetric, dateTime(‘2014-01-01’), dateTime(‘2015-01-01’))” that we want to evaluate.

and the remaining spec is as under:
spec = EvalMetricSpec.make({
id: “test”,
interval: “MONTH”,
expression: expression, // the expression above
start: “2015-01-01”,
end : “2016-01-01”

Now the EvalMetricSpec is querying for data at MONTH interval and for the year 2015. Since eval function overrides the interval and time range passed in the by spec, we evaluate the expression not at the interval and time range that is specified in the EvalMetricSpec but what is provided to us in the “eval” function as arguments. i.e. at “HOUR” interval and for the year 2014.

Now the results that we obtain from the eval function are then converted (aggregated / disaggregated) according to the aggregation function provided to the interval requested in the EvalMetricSpec i.e. MONTH in this case.

It is also possible that the time range specified in the eval function is less or more than what is requested in the EvalMetricSpec. In this case, the results of the eval function will be snapped towards the end of the query end and the extra points will be dropped (if eval period was larger) or filled with 0s (if eval period was smaller)

1 Like

listed #3