-
Notifications
You must be signed in to change notification settings - Fork 453
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] Allow lookback duration to be set in query parameters #1793
Conversation
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.
Can you add something to docs?
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.
Couple comments but LGTM
@@ -52,6 +52,7 @@ const ( | |||
debugParam = "debug" | |||
endExclusiveParam = "end-exclusive" | |||
blockTypeParam = "block-type" | |||
lookbackParam = "lookback" |
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.
Maybe 'lookbackDur' or something similar so it's a little easier to grok what it is?
return 0, false, nil | ||
} | ||
|
||
if lookback == stepParam { |
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.
Curious if lookbackDuration is > stepSize should it default to stepSize?
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 this is for the special case of &lookback=step
; although it reads a little weird since it's being compared to a variable named xxxParam
return 0, false, err | ||
} | ||
|
||
return value, true, nil |
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.
Might have to check that step > 0
otherwise you may have a bad time (although that case is handled elsewhere so it shouldn't panic, but might be better to catch it early)
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.
Sure thing will do.
return value, nil | ||
} | ||
|
||
// Try parsing as a float value specifying seconds, the Prometheus default |
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.
meganit: .
at end of comment
seconds, floatErr := strconv.ParseFloat(str, 64) | ||
if floatErr == nil { | ||
ts := seconds * float64(time.Second) | ||
if ts > maxInt64 || ts < minInt64 { |
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.
Should the lower bound just check ts <= 0
? Negative seems invalid for duration parsing
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.
This was existing code, I could update though.
|
||
if lookback == StepParam { | ||
// Use the step size as lookback. | ||
step, err := parseStep(r, StepParam) |
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.
Maybe should explicitly add a sanity check for step > 0
? It should fail already on ParseStep
but sanity check here may be useful
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.
Yup so I added that inside parseStep
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.
Oops, I'm blind
}, | ||
{ | ||
name: "can set lookback duration based on step", | ||
query: "lookback=step&step=10s", |
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.
May be worth adding in lookback=step
, lookback=step&step=invalid
, lookback=step&step=-1
cases here?
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.
Sure thing.
@@ -206,6 +209,9 @@ func TestEncodeDecodeFetchQuery(t *testing.T) { | |||
MetricsType: storage.AggregatedMetricsType, | |||
StoragePolicy: policy.MustParseStoragePolicy("1m:14d"), | |||
} | |||
lookback := time.Minute | |||
fetchOpts.LookbackDuration = &lookback |
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.
Any worth in adding one without a specified lookback to ensure it uses the config one correctly?
return e.opts.Store().Fetch(ctx, query, fetchOpts) | ||
} | ||
|
||
func (e *engine) ExecuteExpr( | ||
ctx context.Context, | ||
parser parser.Parser, | ||
opts *QueryOptions, | ||
fetchOpts *storage.FetchOptions, |
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; set opts as last param here
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 bar a few nits
What this PR does / why we need it:
This allows callers to set lookback as a request param for per-request specification of the lookback for a query.
Special notes for your reviewer:
Does this PR introduce a user-facing and/or backwards incompatible change?:
Does this PR require updating code package or user-facing documentation?: