[Synthtrace] Improve error message when APM package version is invalid (#138616)

This commit is contained in:
Søren Louv-Jansen 2022-08-12 15:47:20 +02:00 committed by GitHub
parent f2da8548a9
commit 554e83be14
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -53,22 +53,20 @@ export class ApmSynthtraceKibanaClient {
return kibanaUrl;
});
}
async fetchLatestApmPackageVersion(version: string) {
async fetchLatestApmPackageVersion(currentKibanaVersion: string) {
const url =
'https://epr-snapshot.elastic.co/search?package=apm&prerelease=true&all=true&kibana.version=';
const response = await fetch(url + version, { method: 'GET' });
const json = await response.json();
if (!Array.isArray(json)) {
throw new Error('Could not locate apm package compatible with the current kibana version');
const response = await fetch(url + currentKibanaVersion, { method: 'GET' });
const json = (await response.json()) as Array<{ version: string }>;
const packageVersions = (json ?? []).map((item) => item.version).sort(Semver.rcompare);
const validPackageVersions = packageVersions.filter((v) => Semver.valid(v));
const bestMatch = validPackageVersions[0];
if (!bestMatch) {
throw new Error(
`None of the available APM package versions matches the current Kibana version (${currentKibanaVersion}). The latest available version is ${packageVersions[0]}. This can happen if the Kibana version was recently bumped, and no matching APM package was released. Reach out to the fleet team if this persists.`
);
}
const versions = json
.map<string>((item) => item.version)
.filter((v) => Semver.valid(v))
.sort(Semver.rcompare);
if (versions.length === 0) {
throw new Error('Could not locate apm package compatible with the current kibana version');
}
return versions[0];
return bestMatch;
}
async installApmPackage(kibanaUrl: string, version: string, username: string, password: string) {