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

[Plugins] update default url for installing plugins #1316

Merged
merged 1 commit into from
Mar 8, 2022
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
6 changes: 3 additions & 3 deletions packages/osd-opensearch/src/artifact.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ let MOCKS;

const DAILY_SNAPSHOT_BASE_URL = 'https://artifacts.opensearch.org/snapshots/core/opensearch';

const ORIGINAL_PLATFROM = process.platform;
const ORIGINAL_PLATFORM = process.platform;
const ORIGINAL_ARCHITECTURE = process.arch;
const PLATFORM = process.platform === 'win32' ? 'windows' : process.platform;
const ARCHITECTURE = process.arch === 'arm64' ? 'arm64' : 'x64';
Expand Down Expand Up @@ -157,7 +157,7 @@ describe('Artifact', () => {
afterAll(() => {
Object.defineProperties(process, {
platform: {
value: ORIGINAL_PLATFROM,
value: ORIGINAL_PLATFORM,
},
arch: {
value: ORIGINAL_ARCHITECTURE,
Expand All @@ -182,7 +182,7 @@ describe('Artifact', () => {
it('should not throw when on a non-x64 arch', async () => {
Object.defineProperties(process, {
platform: {
value: ORIGINAL_PLATFROM,
value: ORIGINAL_PLATFORM,
},
arch: {
value: 'arm64',
Expand Down
17 changes: 13 additions & 4 deletions src/cli_plugin/install/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,20 @@ import expiry from 'expiry-js';

import { fromRoot } from '../../core/server/utils';

const LATEST_PLUGIN_BASE_URL =
'https://ci.opensearch.org/ci/dbc/distribution-build-opensearch-dashboards';

function generateUrls({ version, plugin }) {
return [
plugin,
`https://artifacts.opensearch.org/downloads/kibana-plugins/${plugin}/${plugin}-${version}.zip`,
];
return [plugin, generatePluginUrl(version, plugin)];
}

function generatePluginUrl(version, plugin) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: This could have just been in generateUrls since that function doesn't do anything anymore 😂

Copy link
Member

Choose a reason for hiding this comment

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

I think there is one called generateUrls (line 42) right?

const platform = process.platform === 'win32' ? 'windows' : process.platform;
const arch = process.arch === 'arm64' ? 'arm64' : 'x64';
if (platform !== 'linux') {
throw new Error('Plugins are only available for Linux');
}
return `${LATEST_PLUGIN_BASE_URL}/${version}/latest/${platform}/${arch}/builds/opensearch-dashboards/plugins/${plugin}-${version}.zip`;
}

export function parseMilliseconds(val) {
Expand Down
60 changes: 58 additions & 2 deletions src/cli_plugin/install/settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ import { parseMilliseconds, parse } from './settings';
const SECOND = 1000;
const MINUTE = SECOND * 60;

const ORIGINAL_PLATFORM = process.platform;
const ORIGINAL_ARCHITECTURE = process.arch;
Comment on lines +41 to +42
Copy link
Contributor

Choose a reason for hiding this comment

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

This causes tests to be inconsistent depending on which platform/architecture you're running them from.

Copy link
Contributor

Choose a reason for hiding this comment

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

My snapshots were updated on my arm64 machine and then they failed in GitHub Actions: https://github.com/opensearch-project/OpenSearch-Dashboards/runs/5548019026?check_suite_focus=true

Copy link
Contributor

Choose a reason for hiding this comment

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

Going to submit a PR to fix this now.

Copy link
Contributor

Choose a reason for hiding this comment

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


expect.addSnapshotSerializer(createAbsolutePathSerializer());

describe('parseMilliseconds function', function () {
Expand All @@ -62,6 +65,17 @@ describe('parse function', function () {
const defaultOptions = { pluginDir: fromRoot('plugins') };
const osdPackage = { version: 1234 };

afterAll(() => {
Object.defineProperties(process, {
platform: {
value: ORIGINAL_PLATFORM,
},
arch: {
value: ORIGINAL_ARCHITECTURE,
},
});
});

it('produces expected defaults', function () {
expect(parse(command, { ...defaultOptions }, osdPackage)).toMatchInlineSnapshot(`
Object {
Expand All @@ -74,7 +88,7 @@ describe('parse function', function () {
"timeout": 0,
"urls": Array [
"plugin name",
"https://artifacts.opensearch.org/downloads/kibana-plugins/plugin name/plugin name-1234.zip",
"https://ci.opensearch.org/ci/dbc/distribution-build-opensearch-dashboards/1234/latest/linux/x64/builds/opensearch-dashboards/plugins/plugin name-1234.zip",
],
"version": 1234,
"workingPath": <absolute path>/plugins/.plugin.installing,
Expand All @@ -101,7 +115,49 @@ describe('parse function', function () {
"timeout": 0,
"urls": Array [
"plugin name",
"https://artifacts.opensearch.org/downloads/kibana-plugins/plugin name/plugin name-1234.zip",
"https://ci.opensearch.org/ci/dbc/distribution-build-opensearch-dashboards/1234/latest/linux/x64/builds/opensearch-dashboards/plugins/plugin name-1234.zip",
],
"version": 1234,
"workingPath": <absolute path>/plugins/.plugin.installing,
}
`);
});

it('should throw when on a non-Linux platform', function () {
Object.defineProperties(process, {
platform: {
value: 'win32',
},
arch: {
value: ORIGINAL_ARCHITECTURE,
},
});
expect(() => parse(command, { ...defaultOptions }, osdPackage)).toThrow(
'Plugins are only available for Linux'
);
});

it('should not throw when on a non-x64 arch', function () {
Object.defineProperties(process, {
platform: {
value: ORIGINAL_PLATFORM,
},
arch: {
value: 'arm64',
},
});
expect(parse(command, { ...defaultOptions }, osdPackage)).toMatchInlineSnapshot(`
Object {
"config": "",
"plugin": "plugin name",
"pluginDir": <absolute path>/plugins,
"quiet": false,
"silent": false,
"tempArchiveFile": <absolute path>/plugins/.plugin.installing/archive.part,
"timeout": 0,
"urls": Array [
"plugin name",
"https://ci.opensearch.org/ci/dbc/distribution-build-opensearch-dashboards/1234/latest/linux/arm64/builds/opensearch-dashboards/plugins/plugin name-1234.zip",
],
"version": 1234,
"workingPath": <absolute path>/plugins/.plugin.installing,
Expand Down