go-graphite / carbonapi

Implementation of graphite API (graphite-web) in golang
Other
309 stars 140 forks source link

Fix smartSummarize to properly handle alignTo start time and intervals smaller than data StepTime #764

Closed carrieedwards closed 1 year ago

carrieedwards commented 1 year ago

This PR rewrites the smartSummarize function in order to correct two issues that were discovered (similar to the recent fix to hitcount, see #132).

When the interval parameter was set to a value smaller than the fetched data's step between data points, it results were incorrect. The results were a copy of the data points for each series in the list. For example: smartSummarize(metric1,'6m','sum', 'minutes') []*types.MetricData{{"metric1", 0, 1}: {types.MakeMetricData("metric1", []float64{2, 4, 6}, 600, 0)},} // 10m step

The result will be []float64{2, 4, 6}. Issuing the same query with the same data in Graphite-web yielded results of [2, 4, None, 6, None]. This is due to the interval being smaller than the step, and therefore some resulting values will be NaN.

Additionally, in Graphite-web's implement of smartSummarize, the start time of the request is adjusted based on the alignTo value, and the data is re-fetched. In CarbonAPI, the start time was adjusted, but data was not re-fetched.

Major changes in this PR: