-
Notifications
You must be signed in to change notification settings - Fork 905
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] Update Version Filter for Data Sources #8785
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
import { SavedObjectsClientContract } from 'opensearch-dashboards/public'; | ||
import { map } from 'rxjs/operators'; | ||
import { i18n } from '@osd/i18n'; | ||
import semver from 'semver'; | ||
import { | ||
DEFAULT_DATA, | ||
DataStructure, | ||
|
@@ -120,11 +121,10 @@ | |
perPage: 10000, | ||
}); | ||
const dataSources: DataStructure[] = response.savedObjects | ||
.filter( | ||
(savedObject) => | ||
typeof savedObject.attributes?.dataSourceEngineType === 'string' && | ||
!savedObject.attributes?.dataSourceEngineType?.includes('OpenSearch Serverless') | ||
) | ||
.filter((savedObject) => { | ||
const coercedVersion = semver.coerce(savedObject.attributes.dataSourceVersion); | ||
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 attribute always exists? 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. yeah @Flyingliuhub @ZilongX confirming this is the correct attribute? We should get cypress tests once i merge the workflow in #8703 @virajsanghvi should do a scan on the usage of this property? I see a number of references to 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. yes |
||
return coercedVersion ? semver.satisfies(coercedVersion, '>=1.0.0') : false; | ||
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. ah i see this what we meant with putting version. if this is the case would we be able to go with the original suggestion of adding an optional property of the dataset type ? |
||
}) | ||
.map((savedObject) => ({ | ||
id: savedObject.id, | ||
title: savedObject.attributes.title, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,36 +142,40 @@ describe('s3TypeConfig', () => { | |
it('should fetch data sources for unknown type', async () => { | ||
mockSavedObjectsClient.find = jest.fn().mockResolvedValue({ | ||
savedObjects: [ | ||
{ id: 'ds1', attributes: { title: 'DataSource 1', dataSourceEngineType: 'OpenSearch' } }, | ||
{ id: 'ds1', attributes: { title: 'DataSource 1', dataSourceVersion: '3.0' } }, | ||
], | ||
}); | ||
|
||
const result = await s3TypeConfig.fetch(mockServices as IDataPluginServices, [ | ||
{ id: 'unknown', title: 'Unknown', type: 'UNKNOWN' }, | ||
]); | ||
|
||
expect(result.children).toHaveLength(1); // Including DEFAULT_DATA.STRUCTURES.LOCAL_DATASOURCE | ||
expect(result.children).toHaveLength(1); | ||
expect(result.children?.[0].title).toBe('DataSource 1'); | ||
expect(result.hasNext).toBe(true); | ||
}); | ||
|
||
it('should filter out OpenSearch Serverless data sources', async () => { | ||
it('should filter out data sources with versions lower than 1.0.0', async () => { | ||
mockSavedObjectsClient.find = jest.fn().mockResolvedValue({ | ||
savedObjects: [ | ||
{ id: 'ds1', attributes: { title: 'DataSource 1', dataSourceEngineType: 'OpenSearch' } }, | ||
{ id: 'ds1', attributes: { title: 'DataSource 1', dataSourceVersion: '1.0' } }, | ||
{ | ||
id: 'ds2', | ||
attributes: { title: 'DataSource 2', dataSourceEngineType: 'OpenSearch Serverless' }, | ||
attributes: { title: 'DataSource 2', dataSourceVersion: '' }, | ||
}, | ||
{ id: 'ds3', attributes: { title: 'DataSource 3', dataSourceVersion: '2.17.0' } }, | ||
{ | ||
id: 'ds4', | ||
attributes: { title: 'DataSource 4', dataSourceVersion: '.0' }, | ||
}, | ||
Comment on lines
+158
to
170
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 we add some test to check invalid semver version like 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. What happens on an invalid version? I assume coerce is just not touching it and it fails satisfies? Data source 2 is an example of an invalid version, but the truthy check on coercedVersion handles that case (I assume). Docs looks like coerce should handle second case so don't think that's a big issue. 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. Confirmed an invalid version returns null locally, so lgtm |
||
{ id: 'ds3', attributes: { title: 'DataSource 3', dataSourceEngineType: 'OpenSearch' } }, | ||
], | ||
}); | ||
|
||
const result = await s3TypeConfig.fetch(mockServices as IDataPluginServices, [ | ||
{ id: 'unknown', title: 'Unknown', type: 'UNKNOWN' }, | ||
]); | ||
|
||
expect(result.children).toHaveLength(2); // Including DEFAULT_DATA.STRUCTURES.LOCAL_DATASOURCE | ||
expect(result.children).toHaveLength(2); | ||
expect(result.children?.[0].title).toBe('DataSource 1'); | ||
expect(result.children?.[1].title).toBe('DataSource 3'); | ||
expect(result.children?.some((child) => child.title === 'DataSource 2')).toBe(false); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
import { i18n } from '@osd/i18n'; | ||
import { trimEnd } from 'lodash'; | ||
import { HttpSetup, SavedObjectsClientContract } from 'opensearch-dashboards/public'; | ||
import semver from 'semver'; | ||
import { | ||
DATA_STRUCTURE_META_TYPES, | ||
DEFAULT_DATA, | ||
|
@@ -197,11 +198,10 @@ const fetchDataSources = async (client: SavedObjectsClientContract): Promise<Dat | |
perPage: 10000, | ||
}); | ||
const dataSources: DataStructure[] = resp.savedObjects | ||
.filter( | ||
(savedObject) => | ||
typeof savedObject.attributes?.dataSourceEngineType === 'string' && | ||
!savedObject.attributes?.dataSourceEngineType?.includes('OpenSearch Serverless') | ||
) | ||
.filter((savedObject) => { | ||
const coercedVersion = semver.coerce(savedObject.attributes.dataSourceVersion); | ||
return coercedVersion ? semver.satisfies(coercedVersion, '>=1.0.0') : false; | ||
}) | ||
Comment on lines
+201
to
+204
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 we use 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. +1, If semver.coerce returns null, this will lead to semver.satisfies(null, '>=x.x.x'), could cause an issue? You may want to add a null check before using semver.satisfies, as semver.satisfies doesn't handle the null 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. Doesn't the truthy check before satisfies handle your concern? 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. Yes. truthy check should handle the concerns about 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. It's my understanding that if the
|
||
.map((savedObject) => ({ | ||
id: savedObject.id, | ||
title: savedObject.attributes.title, | ||
|
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: not sure how valuable this is