-
Notifications
You must be signed in to change notification settings - Fork 454
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] Refactor query code, add warnings to prom output #2265
Conversation
src/query/api/v1/handler/close.go
Outdated
|
||
func (c *ctxCanceller) WatchForCancel( | ||
ctx context.Context, | ||
cancel context.CancelFunc, |
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.
Probably don't need cancel func here since not used?
"warnings": [ | ||
"foo_bar", | ||
"baz_qux" | ||
], |
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.
👍
promReadMetrics: newPromReadMetrics(taggedScope), | ||
// timeoutOps: opts.TimeoutOpts(), | ||
// keepEmpty: opts.Config().ResultOptions.KeepNans, | ||
// instrumentOpts: opts.InstrumentOpts(), |
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.
Believe can remove the comments now?
return h | ||
} | ||
|
||
func (h *PromReadHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | ||
timer := h.promReadMetrics.fetchTimerSuccess.Start() | ||
fetchOpts, rErr := h.fetchOptionsBuilder.NewFetchOptions(r) | ||
defer timer.Stop() |
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.
👍
ctx := context.WithValue(r.Context(), handler.HeaderKey, r.Header) | ||
logger := logging.WithContext(ctx, h.opts.InstrumentOpts()) | ||
|
||
ParsedOptions, rErr := ParseRequest(ctx, r, h.opts) |
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 is a local var, so can just be lower camel cased yeah? i.e. parsedOpts
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, must have gotten dragged into a rename
opentracingext.Error.Set(sp, true) | ||
logger.Error("range query error", | ||
zap.Error(err), | ||
zap.Any("ParsedOptions", ParsedOptions)) |
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.
Name here I assume can be zap.Any("parsedOpts", parsedOpts)
numSteps := int64(params.End.Sub(params.Start) / params.Step) | ||
maxComputedDatapoints := h.limitsCfg.MaxComputedDatapoints() | ||
if maxComputedDatapoints > 0 && numSteps > maxComputedDatapoints { | ||
func validateRequest(params *models.RequestParams, maxPoints int) error { |
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.
Does params
necessarily need to be a pointer type? Could it be just params models.RequestParams
(I notice we do ¶ms
when we call this which might be unnecessary)?
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.
Don't think so; just kept the types as is generally
@@ -77,6 +72,12 @@ func read( | |||
return emptyResult, err | |||
} | |||
|
|||
// Detect clients closing connections. | |||
if cancelWatcher != nil { | |||
ctx, cancel := context.WithTimeout(ctx, fetchOpts.Timeout) |
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.
Do we want to defer cancel()
here?
w.Header().Set("Content-Type", "application/json") | ||
handleroptions.AddWarningHeaders(w, result.meta) | ||
return result.series, params, nil | ||
return ParsedOptions{ |
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 reason not to create the cancel watcher here instead of later and tacking onto the ParsedOptions
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'm trying to avoid taking a http.ResponseWriter
into the read function
@@ -159,7 +170,8 @@ func testPromReadInstantHandler( | |||
] | |||
} | |||
} | |||
`, at0.Unix(), value0, at1.Unix(), value1)) | |||
`, jsonWarnings, at0.Unix(), value0, at1.Unix(), value1)) |
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 we should get rid of the fmt.Sprintf stuff and introduce types JSONMap
, JSONArray
and then add a MustPrettyJSONObject(t, ....)
.
I prototyped this here, looks easy to drop in I think?
https://play.golang.org/p/sTatAL6vaEE
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.
Hah, nice :)
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.
Actually, wouldn't using maps lead to mismatches in data? Also, just from my experience doing it in the last few minutes, building these structures seems more error prone than just writing up the expected JSON?
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.
If we MustPrettyJSON both of them, then they should get the correct ordering as per JSON pretty printing behavior, should actually mean less possibility of writing a wrong JSON output matcher.
} | ||
|
||
data, err := proto.Marshal(resp) | ||
if err != nil { | ||
h.promReadMetrics.fetchErrorsServer.Inc(1) | ||
// h.promReadMetrics.fetchErrorsServer.Inc(1) |
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 restore this?
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.
The metrics will get incremented in the calling function, which has the actual metrics
result, err := h.engine.ExecuteProm(ctx, query, queryOpts, fetchOpts) | ||
// Detect clients closing connections. | ||
if cancelWatcher != nil { | ||
cancelWatcher.WatchForCancel(ctx, cancel) |
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.
Seems like we pepper cancel watchers in a ton of places, is there a way to basically make this middleware instead?
Just seems very messy the setup/tear down of it (even though its useful itself).
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; I only saw these in a few places tbh; wouldn't be opposed to pulling it into some sort of middleware
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 add a todo for this?
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
No description provided.