-
Notifications
You must be signed in to change notification settings - Fork 455
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] Add resolution exceeds query range warning #2429
Changes from all commits
c0f9809
7250ff7
d68d7e3
93f81f1
37abf0a
b88a130
8adebc0
0bc9709
b0fe401
d61e57d
8dd8377
b6c0210
67ed2dd
f4fd465
ad8cc9f
bc43532
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,9 @@ package block | |
|
||
import ( | ||
"fmt" | ||
"sort" | ||
"strings" | ||
"time" | ||
|
||
"github.com/m3db/m3/src/query/models" | ||
) | ||
|
@@ -64,7 +67,7 @@ type ResultMetadata struct { | |
// incomplete results. | ||
Warnings Warnings | ||
// Resolutions is a list of resolutions for series obtained by this query. | ||
Resolutions []int64 | ||
Resolutions []time.Duration | ||
} | ||
|
||
// NewResultMetadata creates a new result metadata. | ||
|
@@ -75,7 +78,7 @@ func NewResultMetadata() ResultMetadata { | |
} | ||
} | ||
|
||
func combineResolutions(a, b []int64) []int64 { | ||
func combineResolutions(a, b []time.Duration) []time.Duration { | ||
if len(a) == 0 { | ||
if len(b) != 0 { | ||
return b | ||
|
@@ -85,7 +88,7 @@ func combineResolutions(a, b []int64) []int64 { | |
return a | ||
} | ||
|
||
combined := make([]int64, 0, len(a)+len(b)) | ||
combined := make([]time.Duration, 0, len(a)+len(b)) | ||
combined = append(combined, a...) | ||
combined = append(combined, b...) | ||
return combined | ||
|
@@ -158,6 +161,31 @@ func (m ResultMetadata) IsDefault() bool { | |
return m.Exhaustive && m.LocalOnly && len(m.Warnings) == 0 | ||
} | ||
|
||
// VerifyTemporalRange will verify that each resolution seen is below the | ||
// given step size, adding warning headers if it is not. | ||
func (m *ResultMetadata) VerifyTemporalRange(step time.Duration) { | ||
// NB: this map is unlikely to have more than 2 elements in real execution, | ||
// since these correspond to namespace count. | ||
invalidResolutions := make(map[time.Duration]struct{}, 10) | ||
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. Maybe a silly question, but why not use 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. It's a map not a slice :p Realistically not expecting this to have more than 2 or at most 3 different values, which is why I'm only initing to 10 here 👍 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. lol, missed that! My bad. SGTM |
||
for _, res := range m.Resolutions { | ||
if res > step { | ||
invalidResolutions[res] = struct{}{} | ||
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. Do we really need this map and also the sorting? Probably simpler to just compile |
||
} | ||
} | ||
|
||
if len(invalidResolutions) > 0 { | ||
warnings := make([]string, 0, len(invalidResolutions)) | ||
for k := range invalidResolutions { | ||
warnings = append(warnings, fmt.Sprintf("%v", time.Duration(k))) | ||
} | ||
|
||
sort.Strings(warnings) | ||
warning := fmt.Sprintf("range: %v, resolutions: %s", | ||
step, strings.Join(warnings, ", ")) | ||
m.AddWarning("resolution larger than query range", warning) | ||
} | ||
} | ||
|
||
// AddWarning adds a warning to the result metadata. | ||
// NB: warnings are expected to be small in general, so it's better to iterate | ||
// over the array rather than introduce a map. | ||
|
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.
nit: Separate internal/external imports?