[8.7] [Fleet] Update URL + add fetch retries for agent versions build task (#154847) (#154868)

This commit is contained in:
Kibana Machine 2023-04-13 10:45:07 -04:00 committed by GitHub
parent 081166bb27
commit a499452f20
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View file

@ -6,6 +6,7 @@
* Side Public License, v 1.
*/
import fetch from 'node-fetch';
import pRetry from 'p-retry';
import { REPO_ROOT } from '@kbn/repo-info';
import { ToolingLog } from '@kbn/tooling-log';
@ -14,6 +15,7 @@ import { FetchAgentVersionsList } from './fetch_agent_versions_list';
import { Build, Config, write } from '../lib';
jest.mock('node-fetch');
jest.mock('p-retry');
jest.mock('../lib');
const config = new Config(
@ -44,9 +46,14 @@ const config = new Config(
);
const mockedFetch = fetch as jest.MockedFunction<typeof fetch>;
const mockedPRetry = pRetry as jest.MockedFunction<typeof pRetry>;
const mockedWrite = write as jest.MockedFunction<typeof write>;
const mockedBuild = new Build(config);
mockedPRetry.mockImplementation((fn: any) => {
return fn();
});
const processEnv = process.env;
describe('FetchAgentVersionsList', () => {

View file

@ -7,10 +7,14 @@
*/
import fetch from 'node-fetch';
import pRetry from 'p-retry';
import { ToolingLog } from '@kbn/tooling-log';
import { write, Task } from '../lib';
// Endpoint maintained by the web-team and hosted on the elastic website
const PRODUCT_VERSIONS_URL = 'https://www.elastic.co/api/product_versions';
const isPr = () =>
!!process.env.BUILDKITE_PULL_REQUEST && process.env.BUILDKITE_PULL_REQUEST !== 'false';
@ -20,13 +24,10 @@ const getAvailableVersions = async (log: ToolingLog) => {
'Content-Type': 'application/json',
},
};
// 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/content/product_versions';
log.info('Fetching Elastic Agent versions list');
try {
const results = await fetch(url, options);
const results = await pRetry(() => fetch(PRODUCT_VERSIONS_URL, options), { retries: 3 });
const rawBody = await results.text();
if (results.status >= 400) {