From c8edd11ad769594e26c4cb33d1ecf713eb25daa3 Mon Sep 17 00:00:00 2001 From: Julia Bardi Date: Thu, 5 Sep 2024 14:21:24 +0200 Subject: [PATCH 1/2] allow +build agent upgrade versions --- .../fleet/server/services/agents/versions.test.ts | 15 +++++++++++++-- .../fleet/server/services/agents/versions.ts | 4 +--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/fleet/server/services/agents/versions.test.ts b/x-pack/plugins/fleet/server/services/agents/versions.test.ts index 58e6dadd7f9e0..0acbcfec18696 100644 --- a/x-pack/plugins/fleet/server/services/agents/versions.test.ts +++ b/x-pack/plugins/fleet/server/services/agents/versions.test.ts @@ -221,7 +221,7 @@ describe('getAvailableVersions', () => { expect(res).toEqual(['8.10.0', '8.9.2', '8.1.0', '8.0.0', '7.17.0']); }); - it('should not include duplicate', async () => { + it('should include build version', async () => { mockKibanaVersion = '300.0.0'; mockedReadFile.mockResolvedValue(`["8.1.0", "8.0.0", "7.17.0", "7.16.0"]`); mockedFetch.mockResolvedValueOnce({ @@ -245,6 +245,10 @@ describe('getAvailableVersions', () => { title: 'Elastic Agent 8.9.2', version_number: '8.9.2', }, + { + title: 'Elastic Agent 8.9.2', + version_number: '8.9.2', + }, , ], ]) @@ -254,7 +258,14 @@ describe('getAvailableVersions', () => { const res = await getAvailableVersions({ ignoreCache: true }); // Should sort, uniquify and filter out versions < 7.17 - expect(res).toEqual(['8.10.0', '8.9.2', '8.1.0', '8.0.0', '7.17.0']); + expect(res).toEqual([ + '8.10.0', + '8.10.0+build202407291657', + '8.9.2', + '8.1.0', + '8.0.0', + '7.17.0', + ]); }); it('should cache results', async () => { diff --git a/x-pack/plugins/fleet/server/services/agents/versions.ts b/x-pack/plugins/fleet/server/services/agents/versions.ts index f374275bf941b..fd59ba7c0e0cc 100644 --- a/x-pack/plugins/fleet/server/services/agents/versions.ts +++ b/x-pack/plugins/fleet/server/services/agents/versions.ts @@ -15,7 +15,6 @@ import semverGte from 'semver/functions/gte'; import semverGt from 'semver/functions/gt'; import semverRcompare from 'semver/functions/rcompare'; import semverLt from 'semver/functions/lt'; -import semverCoerce from 'semver/functions/coerce'; import { REPO_ROOT } from '@kbn/repo-info'; @@ -109,11 +108,10 @@ export const getAvailableVersions = async ({ // fetch from the live API more than `TIME_BETWEEN_FETCHES` milliseconds. const apiVersions = await fetchAgentVersionsFromApi(); - // Coerce each version to a semver object and compare to our `MINIMUM_SUPPORTED_VERSION` - we + // Take each version and compare to our `MINIMUM_SUPPORTED_VERSION` - we // only want support versions in the final result. We'll also sort by newest version first. availableVersions = uniq( [...availableVersions, ...apiVersions] - .map((item: any) => semverCoerce(item)?.version || '') .filter((v: any) => semverGte(v, MINIMUM_SUPPORTED_VERSION)) .sort((a: any, b: any) => (semverGt(a, b) ? -1 : 1)) ); From 4115143d42d35fbf69948a1b287a573ff68b4fce Mon Sep 17 00:00:00 2001 From: Julia Bardi Date: Thu, 5 Sep 2024 15:40:56 +0200 Subject: [PATCH 2/2] added back map to ignore rc and beta versions --- .../server/services/agents/versions.test.ts | 27 +++++++++++++++++++ .../fleet/server/services/agents/versions.ts | 2 ++ 2 files changed, 29 insertions(+) diff --git a/x-pack/plugins/fleet/server/services/agents/versions.test.ts b/x-pack/plugins/fleet/server/services/agents/versions.test.ts index 0acbcfec18696..b3dc82008f812 100644 --- a/x-pack/plugins/fleet/server/services/agents/versions.test.ts +++ b/x-pack/plugins/fleet/server/services/agents/versions.test.ts @@ -221,6 +221,33 @@ describe('getAvailableVersions', () => { expect(res).toEqual(['8.10.0', '8.9.2', '8.1.0', '8.0.0', '7.17.0']); }); + it('should filter out rc and beta versions', async () => { + mockKibanaVersion = '300.0.0'; + mockedReadFile.mockResolvedValue(`["8.1.0", "8.0.0", "7.17.0", "7.16.0"]`); + mockedFetch.mockResolvedValueOnce({ + status: 200, + text: jest.fn().mockResolvedValue( + JSON.stringify([ + [ + { + title: 'Elastic Agent 8.0.0', + version_number: '8.0.0-rc1', + }, + { + title: 'Elastic Agent 8.0.0', + version_number: '8.0.0-beta1', + }, + ], + ]) + ), + } as any); + + const res = await getAvailableVersions({ ignoreCache: true }); + + // Should sort, uniquify and filter out versions < 7.17 + expect(res).toEqual(['8.1.0', '8.0.0', '7.17.0']); + }); + it('should include build version', async () => { mockKibanaVersion = '300.0.0'; mockedReadFile.mockResolvedValue(`["8.1.0", "8.0.0", "7.17.0", "7.16.0"]`); diff --git a/x-pack/plugins/fleet/server/services/agents/versions.ts b/x-pack/plugins/fleet/server/services/agents/versions.ts index fd59ba7c0e0cc..fb42c3af2a50d 100644 --- a/x-pack/plugins/fleet/server/services/agents/versions.ts +++ b/x-pack/plugins/fleet/server/services/agents/versions.ts @@ -15,6 +15,7 @@ import semverGte from 'semver/functions/gte'; import semverGt from 'semver/functions/gt'; import semverRcompare from 'semver/functions/rcompare'; import semverLt from 'semver/functions/lt'; +import semverCoerce from 'semver/functions/coerce'; import { REPO_ROOT } from '@kbn/repo-info'; @@ -112,6 +113,7 @@ export const getAvailableVersions = async ({ // only want support versions in the final result. We'll also sort by newest version first. availableVersions = uniq( [...availableVersions, ...apiVersions] + .map((item: any) => (item.includes('+build') ? item : semverCoerce(item)?.version || '')) .filter((v: any) => semverGte(v, MINIMUM_SUPPORTED_VERSION)) .sort((a: any, b: any) => (semverGt(a, b) ? -1 : 1)) );