Skip to content
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

Merged
merged 7 commits into from
Jul 5, 2019

Conversation

robskillington
Copy link
Collaborator

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?:

NONE

Does this PR require updating code package or user-facing documentation?:

NONE

Copy link
Collaborator

@benraskin92 benraskin92 left a 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?

Copy link
Collaborator

@benraskin92 benraskin92 left a 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"
Copy link
Collaborator

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 {
Copy link
Collaborator

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?

Copy link
Collaborator

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
Copy link
Collaborator

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)

Copy link
Collaborator Author

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
Copy link
Collaborator

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 {
Copy link
Collaborator

@arnikola arnikola Jul 5, 2019

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

Copy link
Collaborator Author

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)
Copy link
Collaborator

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

Copy link
Collaborator Author

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

Copy link
Collaborator

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",
Copy link
Collaborator

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?

Copy link
Collaborator Author

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
Copy link
Collaborator

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,
Copy link
Collaborator

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

Copy link
Collaborator

@arnikola arnikola left a 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

@robskillington robskillington merged commit 4528364 into master Jul 5, 2019
@robskillington robskillington deleted the r/specify-lookback branch July 5, 2019 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants