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

Support real query cancelling for web console #11738

Merged
merged 11 commits into from
Oct 5, 2021

Conversation

ChihyunChang
Copy link
Contributor

@ChihyunChang ChihyunChang commented Sep 23, 2021

Description

This is a follow up to #11643 When a user presses the cancel query button in the web-console, a query cancel request should be sent to Druid to cancel the already running query

Generating queryId, added queryId in context when submitting POST request.
After cancelToken, check isSql then call DELETE request with the corresponding queryId URL

DELETE https://ROUTER:8888/druid/v2/{queryId}
DELETE https://ROUTER:8888/druid/v2/sql/{sqlQueryId}

Return status 202 shows running query deleted successfully


Key changed/added classes in this PR
  • Druid SQL's HTTP DELETE method
  • query-view

This PR has:

  • been self-reviewed.

@suneet-s suneet-s closed this Sep 23, 2021
@suneet-s suneet-s reopened this Sep 23, 2021
@suneet-s
Copy link
Contributor

close and re-open to try and trigger travis

@@ -196,6 +196,10 @@ export class QueryView extends React.PureComponent<QueryViewProps, QueryViewStat
return Api.instance.post(`/druid/v2${isSql ? '/sql' : ''}`, payload, { cancelToken });
});

const generateQueryId = (): string => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think druid query ids are normally UUID v4 by convention. it would be best to stick to that. Use an off the shelf uuid v4 library like https://www.npmjs.com/package/uuid instead on hand rolling a random number generator here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted it ! install uuid --save and use it to generate our queryId

@@ -205,14 +209,23 @@ export class QueryView extends React.PureComponent<QueryViewProps, QueryViewStat

const query = QueryView.isJsonLike(queryString) ? Hjson.parse(queryString) : queryString;

const queryId = generateQueryId();

const isSql = !QueryView.isJsonLike(queryString);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to call QueryView.isJsonLike(queryString) twice in 3 lines, call it once up top and then reuse the variable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, i should do this. Initialed isSql variable and reuse it in query and delete api url.

let context: Record<string, any> | undefined;
if (!isEmptyContext(queryContext) || wrapQueryLimit || mandatoryQueryContext) {
context = { ...queryContext, ...(mandatoryQueryContext || {}) };
context.sqlQueryId = queryId;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where are you setting the context.queryId if this is not a SQL query?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake, i didn't setting the sqlQueryId and it still be able to cancel the query. Added it now

if (typeof wrapQueryLimit !== 'undefined') {
context.sqlOuterLimit = wrapQueryLimit + 1;
}
}

void cancelToken.promise.then(() => {
void Api.instance.delete(`/druid/v2/${isSql ? '/sql' : ''}/${queryId}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will void here be enough to make sure nothing complains about an unhandled promise rejection (we do not want to trigger https://developer.mozilla.org/en-US/docs/Web/API/Window/unhandledrejection_event)? Can you try this when it fails? Does the error get fully ignored or is there a need for .catch(() => {}) ? If I was in your place I would add the .catch(() => {}) just to be sure (and to save time on doing the proper research)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, you are right, void would not be enough to handle the promise reject. i added catch and throw new DruidError(e). But i did not handle the cancel api response yet.

@vogievetsky
Copy link
Contributor

It would be really cool to add a e2e test to this. I am picturing the test opening the query view, typing in a query with a sleep in it. Then canceling it all the while making sure that the right stuff is sent over the wire with https://playwright.dev/docs/network/#network-events

@ChihyunChang
Copy link
Contributor Author

It would be really cool to add a e2e test to this. I am picturing the test opening the query view, typing in a query with a sleep in it. Then canceling it all the while making sure that the right stuff is sent over the wire with https://playwright.dev/docs/network/#network-events

yes of course. i will finish our e2e test by the end of this week

@suneet-s suneet-s closed this Sep 29, 2021
@suneet-s suneet-s reopened this Sep 29, 2021
Copy link
Contributor

@vogievetsky vogievetsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thank you for addressing all the feedback. Will merge after CI passes.

@ChihyunChang
Copy link
Contributor Author

the e2e test passes on my machine but seems to fail in CI, going to investigate why

@suneet-s suneet-s closed this Oct 1, 2021
@suneet-s suneet-s reopened this Oct 1, 2021
@vogievetsky vogievetsky closed this Oct 4, 2021
@vogievetsky vogievetsky reopened this Oct 4, 2021
@vogievetsky
Copy link
Contributor

Come on, Travis, you can do it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants