-
Notifications
You must be signed in to change notification settings - Fork 532
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
Improve observability of enqueuing requests to query-scheduler #5818
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0b1598a
Add events to help diagnose queuing request mystery.
charleskorn 74dea1f
Extract method.
charleskorn e354aa4
Create span while enqueuing request in scheduler, and fix incorrect e…
charleskorn 04cdb91
Add changelog entry.
charleskorn ca81afd
Update pkg/frontend/v2/frontend_scheduler_worker.go
charleskorn 41a0793
Merge branch 'main' into charleskorn/scheduler-observability
charleskorn 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
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 |
---|---|---|
|
@@ -25,6 +25,7 @@ import ( | |
"github.com/grafana/mimir/pkg/scheduler/schedulerdiscovery" | ||
"github.com/grafana/mimir/pkg/scheduler/schedulerpb" | ||
"github.com/grafana/mimir/pkg/util/servicediscovery" | ||
"github.com/grafana/mimir/pkg/util/spanlogger" | ||
) | ||
|
||
const ( | ||
|
@@ -332,60 +333,10 @@ func (w *frontendSchedulerWorker) schedulerLoop(loop schedulerpb.SchedulerForFro | |
return nil | ||
|
||
case req := <-w.requestsCh: | ||
err := loop.Send(&schedulerpb.FrontendToScheduler{ | ||
Type: schedulerpb.ENQUEUE, | ||
QueryID: req.queryID, | ||
UserID: req.userID, | ||
HttpRequest: req.request, | ||
FrontendAddress: w.frontendAddr, | ||
StatsEnabled: req.statsEnabled, | ||
}) | ||
w.enqueuedRequests.Inc() | ||
|
||
if err != nil { | ||
req.enqueue <- enqueueResult{status: failed} | ||
if err := w.enqueueRequest(loop, req); err != nil { | ||
return err | ||
} | ||
|
||
resp, err := loop.Recv() | ||
if err != nil { | ||
req.enqueue <- enqueueResult{status: failed} | ||
return err | ||
} | ||
|
||
switch resp.Status { | ||
case schedulerpb.OK: | ||
req.enqueue <- enqueueResult{status: waitForResponse, cancelCh: w.cancelCh} | ||
// Response will come from querier. | ||
|
||
case schedulerpb.SHUTTING_DOWN: | ||
// Scheduler is shutting down, report failure to enqueue and stop this loop. | ||
req.enqueue <- enqueueResult{status: failed} | ||
return errors.New("scheduler is shutting down") | ||
|
||
case schedulerpb.ERROR: | ||
req.enqueue <- enqueueResult{status: waitForResponse} | ||
req.response <- &frontendv2pb.QueryResultRequest{ | ||
HttpResponse: &httpgrpc.HTTPResponse{ | ||
Code: http.StatusInternalServerError, | ||
Body: []byte(err.Error()), | ||
}, | ||
} | ||
|
||
case schedulerpb.TOO_MANY_REQUESTS_PER_TENANT: | ||
req.enqueue <- enqueueResult{status: waitForResponse} | ||
req.response <- &frontendv2pb.QueryResultRequest{ | ||
HttpResponse: &httpgrpc.HTTPResponse{ | ||
Code: http.StatusTooManyRequests, | ||
Body: []byte("too many outstanding requests"), | ||
}, | ||
} | ||
|
||
default: | ||
level.Error(w.log).Log("msg", "unknown response status from the scheduler", "resp", resp, "queryID", req.queryID) | ||
req.enqueue <- enqueueResult{status: failed} | ||
} | ||
|
||
case reqID := <-w.cancelCh: | ||
err := loop.Send(&schedulerpb.FrontendToScheduler{ | ||
Type: schedulerpb.CANCEL, | ||
|
@@ -408,3 +359,71 @@ func (w *frontendSchedulerWorker) schedulerLoop(loop schedulerpb.SchedulerForFro | |
} | ||
} | ||
} | ||
|
||
// enqueueRequest sends a request to this worker's scheduler, and returns an error if no further requests should be sent to the scheduler. | ||
func (w *frontendSchedulerWorker) enqueueRequest(loop schedulerpb.SchedulerForFrontend_FrontendLoopClient, req *frontendRequest) error { | ||
spanLogger, _ := spanlogger.NewWithLogger(req.ctx, w.log, "frontendSchedulerWorker.enqueueRequest") | ||
spanLogger.Span.SetTag("scheduler_address", w.conn.Target()) | ||
defer spanLogger.Span.Finish() | ||
|
||
err := loop.Send(&schedulerpb.FrontendToScheduler{ | ||
Type: schedulerpb.ENQUEUE, | ||
QueryID: req.queryID, | ||
UserID: req.userID, | ||
HttpRequest: req.request, | ||
FrontendAddress: w.frontendAddr, | ||
StatsEnabled: req.statsEnabled, | ||
}) | ||
w.enqueuedRequests.Inc() | ||
|
||
if err != nil { | ||
level.Warn(spanLogger).Log("msg", "received error while sending request to scheduler", "err", err) | ||
req.enqueue <- enqueueResult{status: failed} | ||
return err | ||
} | ||
|
||
resp, err := loop.Recv() | ||
if err != nil { | ||
level.Warn(spanLogger).Log("msg", "received error while receiving response", "err", err) | ||
req.enqueue <- enqueueResult{status: failed} | ||
return err | ||
} | ||
|
||
switch resp.Status { | ||
case schedulerpb.OK: | ||
req.enqueue <- enqueueResult{status: waitForResponse, cancelCh: w.cancelCh} | ||
// Response will come from querier. | ||
|
||
case schedulerpb.SHUTTING_DOWN: | ||
// Scheduler is shutting down, report failure to enqueue and stop this loop. | ||
level.Warn(spanLogger).Log("msg", "scheduler reported that it is shutting down") | ||
req.enqueue <- enqueueResult{status: failed} | ||
return errors.New("scheduler is shutting down") | ||
|
||
case schedulerpb.ERROR: | ||
level.Warn(spanLogger).Log("msg", "scheduler returned error", "err", resp.Error) | ||
req.enqueue <- enqueueResult{status: waitForResponse} | ||
req.response <- &frontendv2pb.QueryResultRequest{ | ||
HttpResponse: &httpgrpc.HTTPResponse{ | ||
Code: http.StatusInternalServerError, | ||
Body: []byte(resp.Error), | ||
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 catch! |
||
}, | ||
} | ||
|
||
case schedulerpb.TOO_MANY_REQUESTS_PER_TENANT: | ||
level.Warn(spanLogger).Log("msg", "scheduler reported it has too many outstanding requests") | ||
req.enqueue <- enqueueResult{status: waitForResponse} | ||
req.response <- &frontendv2pb.QueryResultRequest{ | ||
HttpResponse: &httpgrpc.HTTPResponse{ | ||
Code: http.StatusTooManyRequests, | ||
Body: []byte("too many outstanding requests"), | ||
}, | ||
} | ||
|
||
default: | ||
level.Error(spanLogger).Log("msg", "unknown response status from the scheduler", "resp", resp, "queryID", req.queryID) | ||
req.enqueue <- enqueueResult{status: failed} | ||
} | ||
|
||
return nil | ||
} |
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.
Note to reviewers: I've deliberately added this request started event and the "request succeeded" event below despite adding the span in
enqueueRequest
, as it's possible there's a delay between a request being added tof.requestsCh
and it being picked up and enqueued by a worker.