-
Notifications
You must be signed in to change notification settings - Fork 907
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
Conversation
Signed-off-by: Sean Li <[email protected]>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #8785 +/- ##
==========================================
+ Coverage 60.75% 60.76% +0.01%
==========================================
Files 3798 3798
Lines 90690 90692 +2
Branches 14277 14277
==========================================
+ Hits 55101 55112 +11
+ Misses 32090 32081 -9
Partials 3499 3499
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
.filter((savedObject) => { | ||
const coercedVersion = semver.coerce(savedObject.attributes.dataSourceVersion); | ||
return coercedVersion ? semver.satisfies(coercedVersion, '>=1.0.0') : false; | ||
}) |
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.
should we use semver.vaild(savedObject.attributes.dataSourceVersion)
to check datsource version is valid first and then do satisfies check?
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.
+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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. truthy check should handle the concerns about null
and undefined
, should we validate the datasource version is valid? Thanks
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.
It's my understanding that if the dataSourceVersion
is not valid in our situation, then semver.coerce()
should return null.
Only text which lacks digits will fail coercion
dataSourceVersion
is "invalid" when it is an empty string and gets caught by the truthy check.
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' }, | ||
}, |
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.
can we add some test to check invalid semver version like a.b.c
and semver version with snapshot/alpha (3.0.0-snapshot) etc?
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed an invalid version returns null locally, so lgtm
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.
just blocking approval on the question on invalid version
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' }, | ||
}, |
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.
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.
!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 comment
The 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 comment
The 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 dataSourceEngineType
in main
right now
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.
yes dataSourceVersion
would always exist, it may carry empty value for invalid datasource but the filed itself would be there
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); |
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
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' }, | ||
}, |
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.
Confirmed an invalid version returns null locally, so lgtm
) | ||
.filter((savedObject) => { | ||
const coercedVersion = semver.coerce(savedObject.attributes.dataSourceVersion); | ||
return coercedVersion ? semver.satisfies(coercedVersion, '>=1.0.0') : false; |
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.
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 ?
Merging as validated it is working but we should revisit this |
The backport to
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-8785-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 9f7f8aa4c39b0710374438daf7066a11327e4452
# Push it to GitHub
git push --set-upstream origin backport/backport-8785-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 |
The backport to
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.18 2.18
# Navigate to the new working tree
pushd ../.worktrees/OpenSearch-Dashboards/backport-2.18
# Create a new branch
git switch --create backport/backport-8785-to-2.18
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 9f7f8aa4c39b0710374438daf7066a11327e4452
# Push it to GitHub
git push --set-upstream origin backport/backport-8785-to-2.18
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/OpenSearch-Dashboards/backport-2.18 Then, create a pull request where the |
Description Uses semver to filter out data sources with invalid versions or versions that are lower than 1.0.0. Adding tests for index_type.ts Signed-off-by: Sean Li <[email protected]> (cherry picked from commit 9f7f8aa) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Description Uses semver to filter out data sources with invalid versions or versions that are lower than 1.0.0. Adding tests for index_type.ts (cherry picked from commit 9f7f8aa) Signed-off-by: Sean Li <[email protected]> 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>
Description
semver
to filter out data sources with invalid versions or versions that are lower than1.0.0
.index_type.ts
Issues Resolved
Screenshot
Testing the changes
Changelog
Check List
yarn test:jest
yarn test:jest_integration