-
Notifications
You must be signed in to change notification settings - Fork 452
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
[query][coordinator] Add time range limit with M3-Limit-Max-Range to restrict time range of a query #3538
Merged
Merged
[query][coordinator] Add time range limit with M3-Limit-Max-Range to restrict time range of a query #3538
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
cfd863d
[query][coordinator] Add time range limit with M3-Limit-Max-Range and…
robskillington 294f212
Merge branch 'master' into r/query-time-range-limit
robskillington 6eb454c
Write test data to unaggregated namespace explicitly
robskillington 158d8ec
Test using existing written metrics
robskillington 8610ae0
Propagate range limit when converting to M3 query options
robskillington b6cee94
Return verbose error including range limit reached info
robskillington 4fd1c9d
Apply changes client side instead of server side
robskillington 5c977fb
Always re-evaluate end
robskillington 6512db3
Add tests
robskillington 7fe4983
Merge branch 'master' into r/query-time-range-limit
robskillington 1381390
Fix lint
robskillington 920cb9c
Modify original start/end
robskillington f7bbd42
Revert "Modify original start/end"
robskillington 304e7ee
Do not mutate and use the modified options
robskillington File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
coordinator: {} | ||
db: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,11 +22,13 @@ package storage | |
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/m3db/m3/src/dbnode/storage/index" | ||
"github.com/m3db/m3/src/m3ninx/idx" | ||
"github.com/m3db/m3/src/query/models" | ||
"github.com/m3db/m3/src/query/storage/m3/consolidators" | ||
xerrors "github.com/m3db/m3/src/x/errors" | ||
"github.com/m3db/m3/src/x/ident" | ||
xtime "github.com/m3db/m3/src/x/time" | ||
) | ||
|
@@ -69,17 +71,56 @@ func TagsToIdentTagIterator(tags models.Tags) ident.TagIterator { | |
} | ||
|
||
// FetchOptionsToM3Options converts a set of coordinator options to M3 options. | ||
func FetchOptionsToM3Options(fetchOptions *FetchOptions, fetchQuery *FetchQuery) index.QueryOptions { | ||
func FetchOptionsToM3Options( | ||
fetchOptions *FetchOptions, | ||
fetchQuery *FetchQuery, | ||
) (index.QueryOptions, error) { | ||
start, end, err := convertStartEndWithRangeLimit(fetchQuery.Start, | ||
fetchQuery.End, fetchOptions) | ||
if err != nil { | ||
return index.QueryOptions{}, err | ||
} | ||
|
||
return index.QueryOptions{ | ||
SeriesLimit: fetchOptions.SeriesLimit, | ||
InstanceMultiple: fetchOptions.InstanceMultiple, | ||
DocsLimit: fetchOptions.DocsLimit, | ||
RequireExhaustive: fetchOptions.RequireExhaustive, | ||
RequireNoWait: fetchOptions.RequireNoWait, | ||
Source: fetchOptions.Source, | ||
StartInclusive: xtime.ToUnixNano(fetchQuery.Start), | ||
EndExclusive: xtime.ToUnixNano(fetchQuery.End), | ||
StartInclusive: xtime.ToUnixNano(start), | ||
EndExclusive: xtime.ToUnixNano(end), | ||
}, nil | ||
} | ||
|
||
func convertStartEndWithRangeLimit( | ||
start, end time.Time, | ||
fetchOptions *FetchOptions, | ||
) (time.Time, time.Time, error) { | ||
fetchRangeLimit := fetchOptions.RangeLimit | ||
if fetchRangeLimit <= 0 { | ||
return start, end, nil | ||
} | ||
|
||
fetchRange := end.Sub(start) | ||
if fetchRange <= fetchRangeLimit { | ||
return start, end, nil | ||
} | ||
|
||
if fetchOptions.RequireExhaustive { | ||
// Fail the query. | ||
msg := fmt.Sprintf("query exceeded limit: require_exhaustive=%v, "+ | ||
"range_limit=%s, range_matched=%s", | ||
fetchOptions.RequireExhaustive, | ||
fetchRangeLimit.String(), | ||
fetchRange.String()) | ||
err := xerrors.NewInvalidParamsError(consolidators.NewLimitError(msg)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, should this emit a metric too to match the other limit exceeded errors? |
||
return time.Time{}, time.Time{}, err | ||
} | ||
|
||
// Truncate the range. | ||
start = end.Add(-1 * fetchRangeLimit) | ||
return start, end, nil | ||
} | ||
|
||
func convertAggregateQueryType(completeNameOnly bool) index.AggregationType { | ||
|
@@ -95,20 +136,26 @@ func convertAggregateQueryType(completeNameOnly bool) index.AggregationType { | |
func FetchOptionsToAggregateOptions( | ||
fetchOptions *FetchOptions, | ||
tagQuery *CompleteTagsQuery, | ||
) index.AggregationOptions { | ||
) (index.AggregationOptions, error) { | ||
start, end, err := convertStartEndWithRangeLimit(tagQuery.Start.ToTime(), | ||
tagQuery.End.ToTime(), fetchOptions) | ||
if err != nil { | ||
return index.AggregationOptions{}, err | ||
} | ||
|
||
return index.AggregationOptions{ | ||
QueryOptions: index.QueryOptions{ | ||
SeriesLimit: fetchOptions.SeriesLimit, | ||
DocsLimit: fetchOptions.DocsLimit, | ||
Source: fetchOptions.Source, | ||
RequireExhaustive: fetchOptions.RequireExhaustive, | ||
RequireNoWait: fetchOptions.RequireNoWait, | ||
StartInclusive: tagQuery.Start, | ||
EndExclusive: tagQuery.End, | ||
StartInclusive: xtime.ToUnixNano(start), | ||
EndExclusive: xtime.ToUnixNano(end), | ||
}, | ||
FieldFilter: tagQuery.FilterNameTags, | ||
Type: convertAggregateQueryType(tagQuery.CompleteNameOnly), | ||
} | ||
}, nil | ||
} | ||
|
||
// FetchQueryToM3Query converts an m3coordinator fetch query to an M3 query. | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nice, how did you even find this heh
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 think I had touched this file by accident and linter had gone off, then I reverted but the fix stayed. Good old linter hah.