Skip to content

Commit

Permalink
[Fleet] Fail build on unable to retrieve agent versions list (#154110)
Browse files Browse the repository at this point in the history
## Summary

Resolves #153923

This PR:

1. [Fails **non-PR**
builds](https://buildkite.com/elastic/kibana-pull-request/builds/116952#01873497-c5a2-4031-9f5b-84df00e8368b)
if we are unable to retrieve the list of Elastic Agent versions from the
website API. If a build ships without this list being retrieved, users
will not have the correct version choices to upgrade their agents to
(see above issue)
2. Updates the API endpoint used from
`https://www.elastic.co/api/product_versions` to
`https://www.elastic.co/content/product_versions`, which appears to be a
more stable version. The `/api` one is currently down:
elastic/website-development#10820
  • Loading branch information
jen-huang authored Apr 6, 2023
1 parent 4c8c13d commit 99f366a
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/dev/build/tasks/fetch_agent_versions_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,29 @@ const getAvailableVersions = async (log: ToolingLog) => {
};
// Endpoint maintained by the web-team and hosted on the elastic website
// See https://github.com/elastic/website-development/issues/9331
const url = 'https://www.elastic.co/api/product_versions';
try {
log.info('Fetching Elastic Agent versions list');
const results = await fetch(url, options);
const url = 'https://www.elastic.co/content/product_versions';
log.info('Fetching Elastic Agent versions list');
const results = await fetch(url, options);
const rawBody = await results.text();

const jsonBody = await results.json();
try {
const jsonBody = JSON.parse(rawBody);

const versions: string[] = (jsonBody.length ? jsonBody[0] : [])
.filter((item: any) => item?.title?.includes('Elastic Agent'))
.map((item: any) => item?.version_number);

log.info(`Retrieved available versions`);
log.info(`Retrieved available Elastic Agent versions`);
return versions;
} catch (error) {
log.warning(`Failed to fetch versions list`);
log.warning(error);
log.warning(`Failed to fetch Elastic Agent versions list`);
log.info(`Status: ${results.status}`);
log.info(rawBody);
if (process.env.BUILDKITE_PULL_REQUEST === 'true') {
log.warning(error);
} else {
throw new Error(error);
}
}
return [];
};
Expand All @@ -47,8 +54,8 @@ export const FetchAgentVersionsList: Task = {
const versionsList = await getAvailableVersions(log);
const AGENT_VERSION_BUILD_FILE = 'x-pack/plugins/fleet/target/agent_versions_list.json';

if (versionsList !== []) {
log.info(`Writing versions list to ${AGENT_VERSION_BUILD_FILE}`);
if (versionsList.length !== 0) {
log.info(`Writing Elastic Agent versions list to ${AGENT_VERSION_BUILD_FILE}`);
await write(
build.resolvePath(AGENT_VERSION_BUILD_FILE),
JSON.stringify(versionsList, null, ' ')
Expand Down

0 comments on commit 99f366a

Please sign in to comment.