forked from opensearch-project/dashboards-observability
-
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.
[Backport 2.x] Add Index-based adaptor for integrations (opensearch-p…
…roject#1399) * Update comment for json adaptor construction * Stub index data adaptor class * Add initial impl for findIntegrationVersions * Fill in simple getDirectoryType implementation * Implement index adaptor as wrapper for json adaptor * Add integration template type for index * Fix lints for server/routes * Fix integrations_manager lints * Refactor template manager to support multiple readers at once * Rename FileSystemCatalogDataAdaptor -> FileSystemDataAdaptor * Add IndexReader to existing Manager logic * Fix plugin label type * Add tests for index adaptor * Add object management to integration objects * Fix bug with version parsing for numeric integration names * Prioritize dynamic integrations over defaults --------- (cherry picked from commit ee3ca58) Signed-off-by: Simeon Widdis <sawiddis@amazon.com> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
5543b73
commit 045306e
Showing
15 changed files
with
368 additions
and
96 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
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
105 changes: 105 additions & 0 deletions
105
server/adaptors/integrations/repository/__test__/index_data_adaptor.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,105 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { IntegrationReader } from '../integration_reader'; | ||
import { JsonCatalogDataAdaptor } from '../json_data_adaptor'; | ||
import { TEST_INTEGRATION_CONFIG } from '../../../../../test/constants'; | ||
import { savedObjectsClientMock } from '../../../../../../../src/core/server/mocks'; | ||
import { IndexDataAdaptor } from '../index_data_adaptor'; | ||
import { SavedObjectsClientContract } from '../../../../../../../src/core/server'; | ||
|
||
// Simplified catalog for integration searching -- Do not use for full deserialization tests. | ||
const TEST_CATALOG_NO_SERIALIZATION: SerializedIntegration[] = [ | ||
{ | ||
...(TEST_INTEGRATION_CONFIG as SerializedIntegration), | ||
name: 'sample1', | ||
}, | ||
{ | ||
...(TEST_INTEGRATION_CONFIG as SerializedIntegration), | ||
name: 'sample2', | ||
}, | ||
{ | ||
...(TEST_INTEGRATION_CONFIG as SerializedIntegration), | ||
name: 'sample2', | ||
version: '2.1.0', | ||
}, | ||
]; | ||
|
||
// Copy of json_data_adaptor.test.ts with new reader type | ||
// Since implementation at time of writing is to defer to json adaptor | ||
describe('Index Data Adaptor', () => { | ||
let mockClient: SavedObjectsClientContract; | ||
|
||
beforeEach(() => { | ||
mockClient = savedObjectsClientMock.create(); | ||
mockClient.find = jest.fn().mockResolvedValue({ | ||
saved_objects: TEST_CATALOG_NO_SERIALIZATION.map((item) => ({ | ||
attributes: item, | ||
})), | ||
}); | ||
}); | ||
|
||
it('Should correctly identify repository type', async () => { | ||
const adaptor = new IndexDataAdaptor(mockClient); | ||
await expect(adaptor.getDirectoryType()).resolves.toBe('repository'); | ||
}); | ||
|
||
it('Should correctly identify integration type after filtering', async () => { | ||
const adaptor = new JsonCatalogDataAdaptor(TEST_CATALOG_NO_SERIALIZATION); | ||
const joined = await adaptor.join('sample1'); | ||
await expect(joined.getDirectoryType()).resolves.toBe('integration'); | ||
}); | ||
|
||
it('Should correctly retrieve integration versions', async () => { | ||
const adaptor = new IndexDataAdaptor(mockClient); | ||
const versions = await adaptor.findIntegrationVersions('sample2'); | ||
expect((versions as { value: string[] }).value).toHaveLength(2); | ||
}); | ||
|
||
it('Should correctly supply latest integration version for IntegrationReader', async () => { | ||
const adaptor = new IndexDataAdaptor(mockClient); | ||
const reader = new IntegrationReader('sample2', adaptor.join('sample2')); | ||
const version = await reader.getLatestVersion(); | ||
expect(version).toBe('2.1.0'); | ||
}); | ||
|
||
it('Should find integration names', async () => { | ||
const adaptor = new IndexDataAdaptor(mockClient); | ||
const integResult = await adaptor.findIntegrations(); | ||
const integs = (integResult as { value: string[] }).value; | ||
integs.sort(); | ||
|
||
expect(integs).toEqual(['sample1', 'sample2']); | ||
}); | ||
|
||
it('Should reject any attempts to read a file with a type', async () => { | ||
const adaptor = new IndexDataAdaptor(mockClient); | ||
const result = await adaptor.readFile('logs-1.0.0.json', 'schemas'); | ||
await expect(result.error?.message).toBe( | ||
'JSON adaptor does not support subtypes (isConfigLocalized: true)' | ||
); | ||
}); | ||
|
||
it('Should reject any attempts to read a raw file', async () => { | ||
const adaptor = new JsonCatalogDataAdaptor(TEST_CATALOG_NO_SERIALIZATION); | ||
const result = await adaptor.readFileRaw('logo.svg', 'static'); | ||
await expect(result.error?.message).toBe( | ||
'JSON adaptor does not support raw files (isConfigLocalized: true)' | ||
); | ||
}); | ||
|
||
it('Should reject nested directory searching', async () => { | ||
const adaptor = new JsonCatalogDataAdaptor(TEST_CATALOG_NO_SERIALIZATION); | ||
const result = await adaptor.findIntegrations('sample1'); | ||
await expect(result.error?.message).toBe( | ||
'Finding integrations for custom dirs not supported for JSONreader' | ||
); | ||
}); | ||
|
||
it('Should report unknown directory type if integration list is empty', async () => { | ||
const adaptor = new JsonCatalogDataAdaptor([]); | ||
await expect(adaptor.getDirectoryType()).resolves.toBe('unknown'); | ||
}); | ||
}); |
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
Oops, something went wrong.