types.isNumeric
is very slow. So filter metrics with that function before downsampling with an aggregateWindow
function is not really an option. But because not every _value
is a number I have to use types.isNumeric
if I want to avoid to create a downsampling method naming all numeric values.
I had an idea to run types.isNumeric
only once per chunk in aggregateWindow
and decide only once how to handle all _values
in this one chunk, theoretically this should work, because measurement
is part of the group and don’t change type (at least in my situation).
Here is the not working script I have so far.
import "types"
from(bucket: "production")
|> range(start: -30m)
|> aggregateWindow(every: 10m,
fn: (tables=<-, column) =>
{
first_element = tables |> first()
return if types.isNumeric(v: first_element._value)
then tables |> mean()
else tables |> last()
}
, createEmpty: false)
|> to(bucket: "production-archive")
And here are the errors I get
error @11:39-11:44: expected {A with _value: B} (record) but found stream[C]
I know that first_element
is a stream here, and I want a record, but I don’t know how get a record out of a stream, and also don’t know if |> first()
consumed already the first element or even the whole stream.