How to check if a timeseries is all 0?



What’s the fastest way to check if a timeseries is all 0?

I was intending to check for ts.optimizedData().length == 1 && ts.optimizedData()[0] == 0 but for some of my metrics that return a 0-timeseries, ts.optimizedData() is a large array of 0 (instead of being a single value array).

Next strategy could be to check ts.aggregate('SUM').optimizedData()[0] (my series is >= 0) or directly iterate through ts.optimizedData() and check each value, but those don’t sound too optimal or very elegant.

Do you have anything else in mind?




I have a similar use case; Given 2 Timeseries objects with the same start/end/interval are already loaded into memory, I need to identify whether both series are flat, i.e. the same value throughout the metric. Initially I thought the same as the post above - optimizedData().length should be 1 in this scenario. However, this doesn’t seem to be the case.

Is there a more performant way to determining whether a Timeseries is flat besides the following?

ts.aggregate('MIN').optimizedData()[0] === ts.aggregate('MAX').optimizedData()[0]

Unfortunately, this is how we currently determine if a timeseries is flat. @rohit.sureka can you speak to whether there are plans to optimize flat data?

1 Like

Yes that is correct, we try to do a best job estimate of trying to keep the optimized data as small as possible, but when multiple ts are interacting with each other there is a chance when this is not a single element.

Most elegant way would be to do aggregate sum and then check the value. In cases where it has optimized data it will do the right thing, in other cases it will be an O(n) operation

1 Like