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

[discover] async query and caching #7943

Merged
merged 13 commits into from
Sep 3, 2024

Conversation

kavilla
Copy link
Member

@kavilla kavilla commented Aug 30, 2024

Description

Async query feature for S3 type on Discover. Due to the time to click and verify I end up implementing the cache to avoid waiting too long per every re-build.

What this PR does:

  • Poll for query
  • Cache data structures and refetches them from session storage
  • Poll based on the data type

What this PR does NOT do yet:

  • SessionId for search strategy, working fine for selector
  • isCacheable field property
  • Abort signal on server

Issues Resolved

n/a

Screenshot

Testing the changes

Changelog

  • feat: async query search and caching, also adding tests to related components

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

Copy link
Contributor

❌ Empty Changelog Section

The Changelog section in your PR description is empty. Please add a valid changelog entry or entries. If you did add a changelog entry, check to make sure that it was not accidentally included inside the comment block in the Changelog section.

this.storage = createStorage({ engine: window.localStorage, prefix: 'opensearchDashboards.' });
this.sessionStorage = createStorage({
engine: window.sessionStorage,
prefix: 'opensearchDashboards.',
Copy link
Member Author

Choose a reason for hiding this comment

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

this prefix has to be opensearchDashboards. BWC

Copy link

codecov bot commented Aug 30, 2024

Codecov Report

Attention: Patch coverage is 25.67568% with 55 lines in your changes missing coverage. Please review.

Project coverage is 61.10%. Comparing base (edabe3b) to head (eeb0dec).
Report is 99 commits behind head on main.

Files with missing lines Patch % Lines
src/plugins/query_enhancements/common/utils.ts 20.00% 16 Missing ⚠️
...gins/query_enhancements/public/datasets/s3_type.ts 6.66% 14 Missing ⚠️
...ry/query_string/dataset_service/dataset_service.ts 52.17% 9 Missing and 2 partials ⚠️
...c/plugins/query_enhancements/server/utils/facet.ts 0.00% 8 Missing ⚠️
.../data/common/search/search_source/search_source.ts 0.00% 4 Missing ⚠️
src/plugins/data/public/plugin.ts 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7943      +/-   ##
==========================================
+ Coverage   61.03%   61.10%   +0.06%     
==========================================
  Files        3688     3691       +3     
  Lines       87232    87309      +77     
  Branches    13425    13433       +8     
==========================================
+ Hits        53241    53348     +107     
+ Misses      30763    30713      -50     
- Partials     3228     3248      +20     
Flag Coverage Δ
Linux_1 29.32% <0.00%> (-0.02%) ⬇️
Linux_2 56.24% <0.00%> (-0.01%) ⬇️
Linux_3 ?
Linux_4 29.59% <6.75%> (-0.01%) ⬇️
Windows_1 29.36% <0.00%> (-0.02%) ⬇️
Windows_2 56.19% <0.00%> (-0.01%) ⬇️
Windows_3 37.93% <45.16%> (+0.13%) ⬆️
Windows_4 29.59% <6.75%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


constructor(initializerContext: PluginInitializerContext<ConfigSchema>) {
this.searchService = new SearchService(initializerContext);
this.uiService = new UiService(initializerContext);
this.queryService = new QueryService();
this.fieldFormatsService = new FieldFormatsService();
this.autocomplete = new AutocompleteService(initializerContext);
this.storage = createStorage({ engine: window.localStorage, prefix: 'opensearch_dashboards.' });
this.storage = createStorage({ engine: window.localStorage, prefix: 'opensearchDashboards.' });
Copy link
Member

Choose a reason for hiding this comment

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

Lets not change the key. Else users stored cache will be wiped out with a version update

Copy link
Member Author

Choose a reason for hiding this comment

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

correct, the original prefix was opensearchDashboards. so this was restoring it back to the older key.

const cacheKey = `${dataType}.${lastPathItem.id}`;

const cachedDataStructure = this.sessionStorage.get<CachedDataStructure>(cacheKey);
if (cachedDataStructure.children?.length > 0) {
Copy link
Member

Choose a reason for hiding this comment

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

What if the datastructure has no children?

Copy link
Member Author

Choose a reason for hiding this comment

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

should attempt the fetch correct? we could check hasNext but to me in makes sense to refetch always if no children.

const query = this.buildQuery(strategy);

return fetch(context, query).pipe(
return fetch(context, this.queryService.queryString.getQuery()).pipe(
Copy link
Member

Choose a reason for hiding this comment

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

doesnt the request object already have the whole query? why ae we fetching the query from the service?

Copy link
Member Author

Choose a reason for hiding this comment

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

you are right. this is an existing issue i will need to fix in a subsequent PR.

Copy link
Contributor

❌ Empty Changelog Section

The Changelog section in your PR description is empty. Please add a valid changelog entry or entries. If you did add a changelog entry, check to make sure that it was not accidentally included inside the comment block in the Changelog section.

export const buildQueryStatusConfig = (response: any) => {
return {
queryId: response.data.queryId,
sessionId: response.data.sessionId,
Copy link
Member

Choose a reason for hiding this comment

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

Can we please make sure the sessionId is stored per - MDS cluster and flint datasource?

Signed-off-by: Kawika Avilla <kavilla414@gmail.com>
abbyhu2000
abbyhu2000 previously approved these changes Sep 3, 2024
LDrago27
LDrago27 previously approved these changes Sep 3, 2024
@@ -440,11 +440,15 @@ export class SearchSource {
await this.setDataFrame(dataFrameResponse.body as IDataFrame);
return onResponse(searchRequest, convertResult(response as IDataFrameResponse));
}
if ((response as IDataFrameResponse).type === DATA_FRAME_TYPES.POLLING) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Can we combine both the if condition
(response as IDataFrameResponse).type === DATA_FRAME_TYPES.DEFAULT) || (response as IDataFrameResponse).type === DATA_FRAME_TYPES.POLLING)
since the body of the both the condition are same.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes good catch. i put this here but i'm planning on removing this type difference

if (temporaryIndexPattern) {
this.indexPatterns?.saveToCache(dataset.id, temporaryIndexPattern);
}
}
}

public fetchOptions(
public async fetchOptions(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we want to give an option to users to explicitly cache burst fetchOptions ?

Signed-off-by: Kawika Avilla <kavilla414@gmail.com>
@kavilla kavilla dismissed stale reviews from LDrago27 and abbyhu2000 via eeb0dec September 3, 2024 21:54
try {
const response = await handleQueryStatus({
fetchStatus: () =>
http.fetch('../../api/enhancements/datasource/jobs', {
Copy link
Member

Choose a reason for hiding this comment

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

why do we need ../../?

@kavilla kavilla merged commit 8c9abe2 into opensearch-project:main Sep 3, 2024
52 of 54 checks passed
@kavilla
Copy link
Member Author

kavilla commented Sep 3, 2024

will address the comments in fast follows

@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 128

To backport manually, run these commands in your terminal:

# Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/OpenSearch-Dashboards/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/OpenSearch-Dashboards/backport-2.x
# Create a new branch
git switch --create backport/backport-7943-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 8c9abe2e32ccf7a47c0998d574c68b2ead111026
# Push it to GitHub
git push --set-upstream origin backport/backport-7943-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/OpenSearch-Dashboards/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-7943-to-2.x.

@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 128

To backport manually, run these commands in your terminal:

# Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/OpenSearch-Dashboards/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/OpenSearch-Dashboards/backport-2.x
# Create a new branch
git switch --create backport/backport-7943-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 8c9abe2e32ccf7a47c0998d574c68b2ead111026
# Push it to GitHub
git push --set-upstream origin backport/backport-7943-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/OpenSearch-Dashboards/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-7943-to-2.x.

kavilla added a commit to kavilla/OpenSearch-Dashboards-1 that referenced this pull request Sep 3, 2024
Async query feature for S3 type on Discover. Due to the time to click and verify I end up implementing the cache to avoid waiting too long per every re-build.

What this PR does:

    Poll for query
    Cache data structures and refetches them from session storage
    Poll based on the data type

What this PR does NOT do yet:

    SessionId for search strategy, working fine for selector
    isCacheable field property
    Abort signal on server

---------

Signed-off-by: Kawika Avilla <kavilla414@gmail.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
(cherry picked from commit 8c9abe2)
kavilla added a commit that referenced this pull request Sep 3, 2024
Async query feature for S3 type on Discover. Due to the time to click and verify I end up implementing the cache to avoid waiting too long per every re-build.

What this PR does:

    Poll for query
    Cache data structures and refetches them from session storage
    Poll based on the data type

What this PR does NOT do yet:

    SessionId for search strategy, working fine for selector
    isCacheable field property
    Abort signal on server

---------

Signed-off-by: Kawika Avilla <kavilla414@gmail.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
(cherry picked from commit 8c9abe2)
@AMoo-Miki
Copy link
Collaborator

Manually backported to 2.x with #7979

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.

7 participants