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

[Build] Dashboards working with legacy engines 7.10.2 #724

Merged
merged 1 commit into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ describe('plugins/opensearch', () => {
it('when majors are equal, but OpenSearch minor is less than OpenSearch Dashboards minor', () => {
expect(opensearchVersionCompatibleWithOpenSearchDashboards('1.0.0', '1.1.0')).toBe(false);
});

it('when majors and minors are not equal, but the engine is on legacy version 6.10.3 and OpenSearch Dashboards is on 1.0.0', () => {
expect(opensearchVersionCompatibleWithOpenSearchDashboards('6.10.3', '1.0.0')).toBe(false);
});

it('when majors and minors are not equal, but the engine is on legacy version 7.10.3 and OpenSearch Dashboards is on 1.0.0', () => {
expect(opensearchVersionCompatibleWithOpenSearchDashboards('7.10.3', '1.0.0')).toBe(false);
});

it('when majors and minors are not equal, but the engine is on legacy version 8.0.0 and OpenSearch Dashboards is on 1.0.0', () => {
expect(opensearchVersionCompatibleWithOpenSearchDashboards('8.0.0', '1.0.0')).toBe(false);
});
});

describe('returns true', () => {
Expand All @@ -64,6 +76,18 @@ describe('plugins/opensearch', () => {
it('when majors and minors are equal, but OpenSearch patch is less than OpenSearch Dashboards patch', () => {
expect(opensearchVersionCompatibleWithOpenSearchDashboards('1.1.0', '1.1.1')).toBe(true);
});

it('when majors and minors are not equal, but the engine is on legacy version 7.10.2 and OpenSearch Dashboards is on 1.0.0', () => {
expect(opensearchVersionCompatibleWithOpenSearchDashboards('7.10.2', '1.0.0')).toBe(true);
});

it('when majors and minors are not equal, but the engine is on legacy version 7.10.2 and OpenSearch Dashboards is on 1.0.1', () => {
expect(opensearchVersionCompatibleWithOpenSearchDashboards('7.10.2', '1.0.1')).toBe(true);
});

it('when majors and minors are not equal, but the engine is on legacy version 7.10.2 and OpenSearch Dashboards is on 1.1.0', () => {
expect(opensearchVersionCompatibleWithOpenSearchDashboards('7.10.2', '1.1.0')).toBe(true);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@

import semver, { coerce } from 'semver';

/** @private */
interface VersionNumbers {
Copy link
Contributor

Choose a reason for hiding this comment

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

May be SemVers ?

major: number;
minor: number;
patch: number;
}

/**
* Checks for the compatibilitiy between OpenSearch and OpenSearchDashboards versions
* 1. Major version differences will never work together.
Expand All @@ -41,18 +48,27 @@ export function opensearchVersionCompatibleWithOpenSearchDashboards(
opensearchVersion: string,
opensearchDashboardsVersion: string
) {
const opensearchVersionNumbers = {
const opensearchVersionNumbers: VersionNumbers = {
major: semver.major(opensearchVersion),
minor: semver.minor(opensearchVersion),
patch: semver.patch(opensearchVersion),
};

const opensearchDashboardsVersionNumbers = {
const opensearchDashboardsVersionNumbers: VersionNumbers = {
major: semver.major(opensearchDashboardsVersion),
minor: semver.minor(opensearchDashboardsVersion),
patch: semver.patch(opensearchDashboardsVersion),
};

if (
legacyVersionCompatibleWithOpenSearchDashboards(
opensearchVersionNumbers,
opensearchDashboardsVersionNumbers
)
) {
return true;
}

// Reject mismatching major version numbers.
if (opensearchVersionNumbers.major !== opensearchDashboardsVersionNumbers.major) {
return false;
Expand All @@ -78,3 +94,24 @@ export function opensearchVersionEqualsOpenSearchDashboards(
nodeSemVer.version === opensearchDashboardsSemver.version
);
}

/**
* Verify legacy version of engines is compatible with current version
* of OpenSearch Dashboards if OpenSearch Dashboards is 1.x.
*
* @private
* @param legacyVersionNumbers semantic version of legacy engine
* @param opensearchDashboardsVersionNumbers semantic version of application
* @returns {boolean}
*/
function legacyVersionCompatibleWithOpenSearchDashboards(
legacyVersionNumbers: VersionNumbers,
opensearchDashboardsVersionNumbers: VersionNumbers
) {
return (
legacyVersionNumbers.major === 7 &&
legacyVersionNumbers.minor === 10 &&
legacyVersionNumbers.patch === 2 &&
opensearchDashboardsVersionNumbers.major === 1
);
}