-
Notifications
You must be signed in to change notification settings - Fork 968
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
[Discover] Cancel S3 Queries Using SQL Plugin #9355
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
feat: | ||
- Deletes S3 Jobs in Backend when Original Query is Canceled ([#9355](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9355)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import { | |
DS_API, | ||
DSM_API, | ||
S3_CLUSTER, | ||
JOBS_API, | ||
} from '../../../../../utils/apps/query_enhancements/constants'; | ||
import { getRandomizedWorkspaceName } from '../../../../../utils/apps/query_enhancements/shared'; | ||
import { prepareTestSuite } from '../../../../../utils/helpers'; | ||
|
@@ -90,6 +91,11 @@ const s3DatasetTestSuite = () => { | |
cy.deleteWorkspaceByName(workspace); | ||
cy.visit('/app/home'); | ||
cy.osd.createInitialWorkspaceWithDataSource(S3_CLUSTER.name, workspace); | ||
cy.navigateToWorkSpaceSpecificPage({ | ||
workspaceName: workspace, | ||
page: 'discover', | ||
isEnhancement: true, | ||
}); | ||
}); | ||
afterEach(() => { | ||
cy.deleteWorkspaceByName(workspace); | ||
|
@@ -141,6 +147,40 @@ const s3DatasetTestSuite = () => { | |
cy.getElementByTestId('docTable').should('be.visible'); | ||
cy.getElementByTestId('docTable').find('tr').should('have.length', 11); | ||
}); | ||
|
||
it('aborts and cancels previous query when new query is started', function () { | ||
cy.getElementByTestId(`datasetSelectorButton`).click(); | ||
cy.getElementByTestId(`datasetSelectorAdvancedButton`).click(); | ||
|
||
cy.get(`[title="S3 Connections"]`).click(); | ||
cy.get(`[title="BasicS3Connection"]`).click(); | ||
cy.get(`[title="mys3"]`).click(); | ||
cy.get(`[title="default"]`).click(); | ||
cy.get(`[title="http_logs"]`).click(); | ||
cy.getElementByTestId('datasetSelectorNext').click(); | ||
cy.get(`[class="euiModalHeader__title"]`).should('contain', 'Step 2: Configure data'); | ||
|
||
cy.getElementByTestId('advancedSelectorLanguageSelect').select('OpenSearch SQL'); | ||
cy.getElementByTestId('advancedSelectorConfirmButton').click(); | ||
|
||
// Need to wait a bit for initial query to start | ||
cy.wait(3000); | ||
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. how come? not blocker but something we should address is avoiding abritraty wait times like a env variable that we can control globally. step 2 would be using other features that help us wait without waiting and assuming everything will happen within 3 secs like i said tho we shouldn't address this in this pr |
||
|
||
cy.intercept('DELETE', `**/${JOBS_API.DELETE}*`).as('cancelRequest'); | ||
cy.getElementByTestId(`querySubmitButton`).click(); | ||
|
||
cy.wait('@cancelRequest').then((interception) => { | ||
console.log('interception.request.url:', interception.request.url); | ||
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. did we want to console log? |
||
// Verify the request had the correct query parameters | ||
expect(interception.request.url).to.include('queryId='); | ||
expect(interception.request.url).to.include('id='); | ||
}); | ||
|
||
cy.waitForSearch(); | ||
cy.get(`[data-test-subj="queryResultCompleteMsg"]`).should('be.visible'); | ||
cy.getElementByTestId('docTable').should('be.visible'); | ||
cy.getElementByTestId('docTable').find('tr').should('have.length', 11); | ||
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. could we potentially luck out on this being 11? for no matter what table. would it be better if we modify the query to be something we know like |
||
}); | ||
}); | ||
} | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
QueryStatusConfig, | ||
QueryStatusOptions, | ||
} from './types'; | ||
import { API } from './constants'; | ||
|
||
export const formatDate = (dateString: string) => { | ||
const date = new Date(dateString); | ||
|
@@ -57,13 +58,34 @@ | |
pollQueryResultsParams: context.body?.pollQueryResultsParams, | ||
timeRange: context.body?.timeRange, | ||
}); | ||
|
||
return from( | ||
http.fetch({ | ||
method: 'POST', | ||
path, | ||
body, | ||
signal, | ||
}) | ||
http | ||
.fetch({ | ||
method: 'POST', | ||
path, | ||
body, | ||
signal, | ||
}) | ||
.catch(async (error) => { | ||
if (error.name === 'AbortError' && context.body?.pollQueryResultsParams?.queryId) { | ||
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. i can't remember but does the current UI abort requests when user clicks Run query before the previous one finishes? For example,
If the request in step 3 is aborted, then this would work. But if user runs another query during step 5, would this abort and delete job for the previous query? 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. In this scenario, yes, it will abort if another query is run in between the short polling requests. 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. could you explain a bit why would it abort? i thought during waiting time, the last |
||
// Cancel job | ||
try { | ||
await http.fetch({ | ||
method: 'DELETE', | ||
path: API.DATA_SOURCE.ASYNC_JOBS, | ||
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. should this allow each dataset type config to define the action to delete query job? there might be other type configs using 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. One of our followup items to discuss is how we will add the cancel button, which is why I haven't included it in this PR. However, adding a dataset type config would be a good way to do that implementation, thanks for that tip. 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. got it, it might be better if S3 type config provides this catch logic as an error handler |
||
query: { | ||
id: query.dataset?.dataSource?.id, | ||
queryId: context.body?.pollQueryResultsParams.queryId, | ||
}, | ||
}); | ||
} catch (cancelError) { | ||
// eslint-disable-next-line no-console | ||
console.error('Failed to cancel query:', cancelError); | ||
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. should it throw the cancel 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. Don't think it's necessary, since we don't want this thrown error to stop any other process. 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. but should we let user know if it failed? For example if I accidentally ran a |
||
} | ||
throw error; | ||
} | ||
}) | ||
); | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,4 +99,31 @@ | |
} | ||
} | ||
); | ||
|
||
router.delete( | ||
{ | ||
path: API.DATA_SOURCE.ASYNC_JOBS, | ||
validate: { | ||
query: schema.object({ | ||
id: schema.string(), | ||
joshuali925 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
queryId: schema.nullable(schema.string()), | ||
}), | ||
}, | ||
}, | ||
async (context, request, response) => { | ||
try { | ||
const client = request.query.id | ||
? context.dataSource.opensearch.legacy.getClient(request.query.id).callAPI | ||
: defaultClient.asScoped(request).callAsCurrentUser; | ||
|
||
await client('enhancements.deleteJob', { | ||
queryId: request.query.queryId, | ||
}); | ||
return response.noContent(); | ||
} catch (error) { | ||
const statusCode = error.statusCode === 500 ? 503 : error.statusCode || 503; | ||
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. Can you describe more or may be add comment what exactly the action being taken with these error codes, also can we write it like to make it more readable? 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. This was added as a way to handle specific errors from SQL plugin. Was mimicking the other routes, which were added in this PR. |
||
return response.custom({ statusCode, body: error.message }); | ||
} | ||
} | ||
); | ||
} |
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: given that this test just verify if it aborts verifyhing if selecting the title has this increases potential points of failure unrelated to this test.
in this test it would be better to just navigate to the page with a s3 query run it and then run it again focusing on the test name.
but this should be addressed later not now.