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

[Fleet] allow +build agent upgrade versions #192171

Merged
merged 2 commits into from
Sep 5, 2024
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
42 changes: 40 additions & 2 deletions x-pack/plugins/fleet/server/services/agents/versions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,34 @@ 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 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"]`);
mockedFetch.mockResolvedValueOnce({
Expand All @@ -245,6 +272,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',
},
,
],
])
Expand All @@ -254,7 +285,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 () => {
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/fleet/server/services/agents/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ 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]
Copy link
Member

Choose a reason for hiding this comment

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

In the version from the API it seems there are also some RC and beta versions I do not know if we want them included too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably best to keep the behaviour unchanged for that now that 9.0 is approaching. Added back the coerce logic and allowing only +build versions.

.map((item: any) => semverCoerce(item)?.version || '')
.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))
);
Expand Down
Loading