-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix smartSummarize to properly handle alignTo start time and intervals smaller than data StepTime #137
Conversation
This comment has been minimized.
This comment has been minimized.
2 similar comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@@ -62,28 +86,6 @@ func (f *smartSummarize) Do(ctx context.Context, e parser.Expr, from, until int6 | |||
return nil, err | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add a check after line 74 to make sure bucketSizeInt32 > 0
. I tried passing a negative interval '-5m'
and it panicked.
} | ||
} | ||
|
||
func TestSmartSummarizeAlignTo1Year(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think our current code can align past days, it's doing:
for _, v := range []int64{86400, 3600, 60} {
if int64(interval) >= v {
start -= start % v
break
}
}
I think these tests are passing because their start time is 0
, which is already aligned to years (and is also aligned to days). Same thing applies to TestSmartSummarizeAlignToMonths
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Working on adding support the other interval formats as well
} | ||
} | ||
|
||
func TestSmartSummarizeAlignToWeeksThursday(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These GraphiteWeb tests are actually passing weeks4
to align it to a Thursday: https://github.com/graphite-project/graphite-web/blob/dca59dc72ae28ffdae659232c10c60aa598536eb/webapp/tests/test_functions.py#L5646
I think these translated tests pass here because the start times of the inputs are 0, and the epoch January 1st 1970 was actually a Thursday. This is a funny coincidence 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, for now I just used 'weeks' because IntervalString fails to parse weeks4. But I will work on fixing that in IntervalString
} | ||
} | ||
|
||
func TestSmartSummarizeAlignToDays(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For these tests, I would use start times that are not multiple of 86400
. Otherwise it's not aligning much
} | ||
} | ||
|
||
func TestSmartSummarizeAlignToHours(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For these I would use start times that are not multiple of 3600
} | ||
} | ||
|
||
func TestSmartSummarizeAlignToMinutes(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For these not multiple of 60
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
37a53da
to
e5ac035
Compare
This comment has been minimized.
This comment has been minimized.
Go coverage report: Click to expand.
Go lint report: No issues found. 😎 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
For the alignment tests: I think we should change the TestSummarizeEvalExpr
helper so the from/to times can be adjusted; otherwise the alignment is not being tested. But I don't want to put that as a blocker now
I will do that and update the tests in a separate PR, since this PR is already a pretty large one. |
…s smaller than data StepTime (#137) * Enable parser to adjust start time for smartSummarize based on interval * Fix smartSummarize handling intervals that are smaller than the step time of the data * Add additional tests for smartSummarize * Optimize algorithm for smartSummarize * Calculate bucket limits with integer division * Add additional tests to cover Graphite web test cases * Add support for alignTo values of seconds, weeks, months and years * Error with negative intervals --------- Co-authored-by: Nicolás Pazos <npazosmendez@gmail.com>
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:
The smartSummarize function was completely rewritten to match the behavior of Graphite web, as well as adding some optimizations in the algorithm. 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 adjust the start time of a metric request with a target of smartSummarize, so that the start time reflects the alignTo parameter's value. This is intended to prevent needing to re-fetch the data during smartSummarize function execution as is done in Graphite web. Additionally, previously, only 'minutes', 'hours', and 'days' was supported, so support was extended for seconds, weeks, months and years.
More testcases were added, including ones that cover the situation where the specific interval is smaller than the fetched data's step, as well as test cases translated from Graphite web for smartSummarize.