forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[discover] async query and caching (opensearch-project#7943)
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 <[email protected]> Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> (cherry picked from commit 8c9abe2)
- Loading branch information
Showing
38 changed files
with
971 additions
and
344 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
feat: | ||
- Async query search and caching, also adding tests to related components ([#7943](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7943)) |
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
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
86 changes: 86 additions & 0 deletions
86
src/plugins/data/public/query/query_string/dataset_service/dataset_service.test.ts
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { DatasetService } from './dataset_service'; | ||
import { coreMock } from '../../../../../../core/public/mocks'; | ||
import { DataStorage } from 'src/plugins/data/common'; | ||
import { DataStructure } from '../../../../common'; | ||
import { IDataPluginServices } from '../../../types'; | ||
|
||
describe('DatasetService', () => { | ||
let service: DatasetService; | ||
let uiSettings: ReturnType<typeof coreMock.createSetup>['uiSettings']; | ||
let sessionStorage: DataStorage; | ||
let mockDataPluginServices: jest.Mocked<IDataPluginServices>; | ||
|
||
beforeEach(() => { | ||
uiSettings = coreMock.createSetup().uiSettings; | ||
sessionStorage = new DataStorage(window.sessionStorage, 'opensearchDashboards.'); | ||
mockDataPluginServices = {} as jest.Mocked<IDataPluginServices>; | ||
|
||
service = new DatasetService(uiSettings, sessionStorage); | ||
}); | ||
|
||
test('registerType and getType', () => { | ||
const mockType = { | ||
id: 'test-type', | ||
title: 'Test Type', | ||
meta: { icon: { type: 'test' } }, | ||
toDataset: jest.fn(), | ||
fetch: jest.fn(), | ||
fetchFields: jest.fn(), | ||
supportedLanguages: jest.fn(), | ||
}; | ||
|
||
service.registerType(mockType); | ||
expect(service.getType('test-type')).toBe(mockType); | ||
}); | ||
|
||
test('getTypes returns all registered types', () => { | ||
const mockType1 = { id: 'type1', title: 'Type 1', meta: { icon: { type: 'test1' } } }; | ||
const mockType2 = { id: 'type2', title: 'Type 2', meta: { icon: { type: 'test2' } } }; | ||
|
||
service.registerType(mockType1 as any); | ||
service.registerType(mockType2 as any); | ||
|
||
const types = service.getTypes(); | ||
expect(types).toHaveLength(2); | ||
expect(types).toContainEqual(mockType1); | ||
expect(types).toContainEqual(mockType2); | ||
}); | ||
|
||
test('fetchOptions caches and returns data structures', async () => { | ||
const mockType = { | ||
id: 'test-type', | ||
title: 'Test Type', | ||
meta: { icon: { type: 'test' } }, | ||
toDataset: jest.fn(), | ||
fetch: jest.fn().mockResolvedValue({ | ||
id: 'test-structure', | ||
title: 'Test Structure', | ||
type: 'test-type', | ||
children: [{ id: 'child1', title: 'Child 1', type: 'test-type' }], | ||
}), | ||
fetchFields: jest.fn(), | ||
supportedLanguages: jest.fn(), | ||
}; | ||
|
||
service.registerType(mockType); | ||
|
||
const path: DataStructure[] = [{ id: 'root', title: 'Root', type: 'root' }]; | ||
const result = await service.fetchOptions(mockDataPluginServices, path, 'test-type'); | ||
|
||
expect(result).toEqual({ | ||
id: 'test-structure', | ||
title: 'Test Structure', | ||
type: 'test-type', | ||
children: [{ id: 'child1', title: 'Child 1', type: 'test-type' }], | ||
}); | ||
|
||
const cachedResult = await service.fetchOptions(mockDataPluginServices, path, 'test-type'); | ||
expect(cachedResult).toEqual(result); | ||
expect(mockType.fetch).toHaveBeenCalledTimes(2); | ||
}); | ||
}); |
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
92 changes: 92 additions & 0 deletions
92
src/plugins/data/public/query/query_string/dataset_service/lib/index_pattern_type.test.ts
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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
// index_pattern_type.test.ts | ||
|
||
import { indexPatternTypeConfig } from './index_pattern_type'; | ||
import { SavedObjectsClientContract } from 'opensearch-dashboards/public'; | ||
import { DATA_STRUCTURE_META_TYPES, DataStructure, Dataset } from '../../../../../common'; | ||
import * as services from '../../../../services'; | ||
|
||
jest.mock('../../../../services', () => ({ | ||
getIndexPatterns: jest.fn(), | ||
})); | ||
|
||
jest.mock('./utils', () => ({ | ||
injectMetaToDataStructures: jest.fn(), | ||
})); | ||
|
||
describe('indexPatternTypeConfig', () => { | ||
const mockSavedObjectsClient = {} as SavedObjectsClientContract; | ||
const mockServices = { | ||
savedObjects: { client: mockSavedObjectsClient }, | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test('toDataset converts DataStructure to Dataset', () => { | ||
const mockPath: DataStructure[] = [ | ||
{ | ||
id: 'test-pattern', | ||
title: 'Test Pattern', | ||
type: 'INDEX_PATTERN', | ||
meta: { timeFieldName: '@timestamp', type: DATA_STRUCTURE_META_TYPES.CUSTOM }, | ||
}, | ||
]; | ||
|
||
const result = indexPatternTypeConfig.toDataset(mockPath); | ||
|
||
expect(result).toEqual({ | ||
id: 'test-pattern', | ||
title: 'Test Pattern', | ||
type: 'INDEX_PATTERN', | ||
timeFieldName: '@timestamp', | ||
dataSource: undefined, | ||
}); | ||
}); | ||
|
||
test('fetchFields returns fields from index pattern', async () => { | ||
const mockIndexPattern = { | ||
fields: [ | ||
{ name: 'field1', type: 'string' }, | ||
{ name: 'field2', type: 'number' }, | ||
], | ||
}; | ||
const mockGet = jest.fn().mockResolvedValue(mockIndexPattern); | ||
(services.getIndexPatterns as jest.Mock).mockReturnValue({ get: mockGet }); | ||
|
||
const mockDataset: Dataset = { id: 'test-pattern', title: 'Test', type: 'INDEX_PATTERN' }; | ||
const result = await indexPatternTypeConfig.fetchFields(mockDataset); | ||
|
||
expect(result).toHaveLength(2); | ||
expect(result[0]).toEqual({ name: 'field1', type: 'string' }); | ||
expect(result[1]).toEqual({ name: 'field2', type: 'number' }); | ||
}); | ||
|
||
test('supportedLanguages returns correct languages', () => { | ||
const mockDataset: Dataset = { | ||
id: 'test-pattern', | ||
title: 'Test', | ||
type: 'INDEX_PATTERN', | ||
dataSource: { id: 'dataSourceId', title: 'Cluster 1', type: 'OpenSearch' }, | ||
}; | ||
expect(indexPatternTypeConfig.supportedLanguages(mockDataset)).toEqual([ | ||
'DQL', | ||
'Lucene', | ||
'PPL', | ||
'SQL', | ||
]); | ||
|
||
mockDataset.dataSource = { ...mockDataset.dataSource!, type: 'other' }; | ||
expect(indexPatternTypeConfig.supportedLanguages(mockDataset)).toEqual([ | ||
'DQL', | ||
'Lucene', | ||
'PPL', | ||
'SQL', | ||
]); | ||
}); | ||
}); |
Oops, something went wrong.