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] Add retry when retrieving agent version #186459

Merged
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 @@ -25,8 +25,7 @@ export default function (providerContext: FtrProviderContext) {
const config = getService('config');
const log = getService('log');

// FLAKY: https://github.com/elastic/kibana/issues/184681
describe.skip('inputs_with_standalone_docker_agent', () => {
describe('inputs_with_standalone_docker_agent', () => {
skipIfNoDockerRegistry(providerContext);
let apiKey: string;
let agent: AgentProcess;
Expand Down
10 changes: 8 additions & 2 deletions x-pack/test/fleet_cypress/artifact_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@

import axios from 'axios';
import { last } from 'lodash';
import pRetry from 'p-retry';

const DEFAULT_VERSION = '8.15.0-SNAPSHOT';

export async function getLatestVersion(): Promise<string> {
const response: any = await axios('https://artifacts-api.elastic.co/v1/versions');
return last(response.data.versions as string[]) || '8.1.0-SNAPSHOT';
return pRetry(() => axios('https://artifacts-api.elastic.co/v1/versions'), {
Copy link
Member

@cmacknz cmacknz Jun 19, 2024

Choose a reason for hiding this comment

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

The artifacts-api is not stable, don't use it. We had to move away from it in the agent team.

The latest snapshot for each version is available from https://snapshots.elastic.co which does not use the artifacts API.

Examples:

The version to use will be the current version of Kibana in a branch for the next release.

Those will give you a build ID you can use to build the artifact download URL For example 8.15.0-SNAPSHOT gives you "build_id" : "8.15.0-72200925" as the latest build ID which gets used as shown below to get the linux x64_64 .tar.gz artifact directly.

https://snapshots.elastic.co/8.15.0-72200925/downloads/beats/elastic-agent/elastic-agent-8.15.0-SNAPSHOT-linux-x86_64.tar.gz

Copy link
Member Author

Choose a reason for hiding this comment

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

@cmacknz Looks like a bunch of Kibana tests use the artifacts API, do you think even with retry? (and a fallback value) it's not good enough?
I am worried when using https://snapshots.elastic.co/ we will have issues when creating new branch for new version and when the elastic-agent SNAPSHOT is not yet available

Copy link
Contributor

Choose a reason for hiding this comment

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

I am worried when using https://snapshots.elastic.co/ we will have issues when creating new branch for new version and when the elastic-agent SNAPSHOT is not yet available

Then we might have to pin the exact version indeed. Retrying might help but stability is not guaranteed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Then we might have to pin the exact version indeed. Retrying might help but stability is not guaranteed.

The way I implemented this is with retry and a fallback value to 8.15.0-SNAPSHOT if retries failed

Copy link
Member

Choose a reason for hiding this comment

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

You can certainly start with a retry and see how it works, if it continues to be flaky the solution is as described above - don't use the artifacts-api.

maxRetryTime: 60 * 1000, // 1 minute
})
.then((response) => last(response.data.versions as string[]) || DEFAULT_VERSION)
.catch(() => DEFAULT_VERSION);
}
Loading