This PR is a rewrite of the hitcount function in order to match Graphite web's behavior. There are two major issues that were discovered:
1) When the interval parameter was set to a value smaller than the fetched data's step between data points, it results were incorrectly shifted left, such that all of the hit counts were concentrated towards the left buckets, and there were empty buckets on the right. For example:
The result will be []float64{1200, 2400, 3600, 0, 0, 0}. The hit values are all concentrated on the left half of the buckets.
2) Upon looking at Graphite web's implementation of hitcount, when the alignToInterval parameter is set to true, the start time is adjusted and the data is re-fetched. In CarbonAPI, the start time was adjusted, but data was not re-fetched.
Major changes in this PR:
The hitcount function was completely rewritten to match the behavior of Graphite web. This helps address the issue with intervals smaller than the data's step, as well as fixes discrepancies in results that were occurring with CarbonAPI tests that were tested in Graphite web.
The Metrics() function in pkg/parser.go was updated to pass in the from/to of the request, and code was added to determine the correct start time for the data being fetched for the hitcount function when alignToInterval is set to true. The new start time is determined based on the request's from value and the interval specified. This is intended to prevent needing to re-fetch the data as is done in Graphite web.
Hi @Civil, when you get the chance could you take a look at this PR? It's a pretty significant refactor. We have tested it pretty thoroughly on our end, including against Graphite-web.
This PR is a rewrite of the hitcount function in order to match Graphite web's behavior. There are two major issues that were discovered:
1) When the
interval
parameter was set to a value smaller than the fetched data's step between data points, it results were incorrectly shifted left, such that all of the hit counts were concentrated towards the left buckets, and there were empty buckets on the right. For example:hitcount(metric1, "6m") []*types.MetricData{{"metric1", 0, 1}: {types.MakeMetricData("metric1", []float64{2, 4, 6}, 600, 100)},} // 10m step
The result will be []float64{1200, 2400, 3600, 0, 0, 0}. The hit values are all concentrated on the left half of the buckets.
2) Upon looking at Graphite web's implementation of hitcount, when the
alignToInterval
parameter is set to true, the start time is adjusted and the data is re-fetched. In CarbonAPI, the start time was adjusted, but data was not re-fetched.Major changes in this PR:
alignToInterval
is set to true. The new start time is determined based on the request's from value and the interval specified. This is intended to prevent needing to re-fetch the data as is done in Graphite web.