gnocchixyz / gnocchi

Timeseries database
Apache License 2.0
298 stars 84 forks source link

The returned data is not expected of gnocchi api: `GET /v1/metric/<metric_id>/measures` #1368

Closed magiceses closed 7 months ago

magiceses commented 7 months ago

Before reporting an issue on Gnocchi, please be sure to provide all necessary information.

How to reproduce your problem

access to GET /v1/metric/<metric_id>/measures?start=2023-12-21T10:43:00&granularity=300&stop=2023-12-21T10:48:00

What is the result that you get

i get two measures: [["2023-12-21T10:40:00+00:00", 300.0, 0.020833230056639], ["2023-12-21T10:45:00+00:00", 300.0, 0.018328995401186002]]

What is result that you expected

i want to get data is between 2023-12-21T10:43:00 and 2023-12-21T10:48:00

So why the 2023-12-21T10:40:00+00:00 data is returned? Is this a bug or is it designed this way? Somebody can help?

chungg commented 7 months ago

that is correct. the granularity is relative to unix epoch so in the case above, it's creating 300s grouping relative to that: 1970-01-01T00:00:00, 1970-01-01T00:05:00, 1970-01-01T00:10:00, etc... you can see the logic here: https://github.com/gnocchixyz/gnocchi/blob/0e7d9dc79c362d641836714a0e8909b018e08701/gnocchi/carbonara.py#L65-L67

i don't believe there's a way for gnocchi to directly return data in grouping like above. you would need to configure metric with policy that would capture granularity of 60s (or less). that would return you data from 2023-12-21T10:43:00 and 2023-12-21T10:48:00. from there, you would need reaggregate outside of gnocchi if you want a single value.

magiceses commented 7 months ago

Got it,thanks very much @chungg