mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 02:09:32 -04:00
[EDR Workflows][Osquery][Cypress] Fallback for KibanaStatus error response when fetching kibana version (#218240)
This PR fixes an issue that can cause test execution to fail when `await kbnClient.status.get()` doesn't return the Kibana version. The fallback now uses the version from `package.json` in that case. Example failure: https://buildkite.com/elastic/kibana-on-merge/builds/66520#0196344e-f27e-4ab8-9bf7-f041b94c665d/268-3998 --------- Co-authored-by: Patryk Kopyciński <contact@patrykkopycinski.com> Co-authored-by: Tiago Costa <tiago.costa@elastic.co>
This commit is contained in:
parent
1d430d4d35
commit
ce10318ef3
3 changed files with 28 additions and 6 deletions
|
@ -41,7 +41,8 @@ export class AgentManager extends Manager {
|
||||||
this.log.info(chalk.bold('Setting up Agent'));
|
this.log.info(chalk.bold('Setting up Agent'));
|
||||||
|
|
||||||
const artifact = `docker.elastic.co/elastic-agent/elastic-agent:${await getLatestAvailableAgentVersion(
|
const artifact = `docker.elastic.co/elastic-agent/elastic-agent:${await getLatestAvailableAgentVersion(
|
||||||
this.kbnClient
|
this.kbnClient,
|
||||||
|
this.log
|
||||||
)}`;
|
)}`;
|
||||||
this.log.indent(4, () => this.log.info(`Image: ${artifact}`));
|
this.log.indent(4, () => this.log.info(`Image: ${artifact}`));
|
||||||
const containerName = generateRandomString(12);
|
const containerName = generateRandomString(12);
|
||||||
|
|
|
@ -26,7 +26,7 @@ export class FleetManager extends Manager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async setup(): Promise<void> {
|
public async setup(): Promise<void> {
|
||||||
const version = await getLatestAvailableAgentVersion(this.kbnClient);
|
const version = await getLatestAvailableAgentVersion(this.kbnClient, this.log);
|
||||||
this.fleetServer = await startFleetServer({
|
this.fleetServer = await startFleetServer({
|
||||||
kbnClient: this.kbnClient,
|
kbnClient: this.kbnClient,
|
||||||
logger: this.log,
|
logger: this.log,
|
||||||
|
|
|
@ -9,6 +9,8 @@ import axios from 'axios';
|
||||||
import semver from 'semver';
|
import semver from 'semver';
|
||||||
import { map } from 'lodash';
|
import { map } from 'lodash';
|
||||||
import { PackagePolicy, CreatePackagePolicyResponse, API_VERSIONS } from '@kbn/fleet-plugin/common';
|
import { PackagePolicy, CreatePackagePolicyResponse, API_VERSIONS } from '@kbn/fleet-plugin/common';
|
||||||
|
// @ts-expect-error we have to check types with "allowJs: false" for now, causing this import to fail
|
||||||
|
import { kibanaPackageJson } from '@kbn/repo-info';
|
||||||
import { KbnClient } from '@kbn/test';
|
import { KbnClient } from '@kbn/test';
|
||||||
import {
|
import {
|
||||||
GetEnrollmentAPIKeysResponse,
|
GetEnrollmentAPIKeysResponse,
|
||||||
|
@ -140,10 +142,23 @@ const isValidArtifactVersion = (version: string) => !!version.match(/^\d+\.\d+\.
|
||||||
* Returns the Agent version that is available for install (will check `artifacts-api.elastic.co/v1/versions`)
|
* Returns the Agent version that is available for install (will check `artifacts-api.elastic.co/v1/versions`)
|
||||||
* that is equal to or less than `maxVersion`.
|
* that is equal to or less than `maxVersion`.
|
||||||
* @param kbnClient
|
* @param kbnClient
|
||||||
|
* @param log
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const getLatestAvailableAgentVersion = async (kbnClient: KbnClient): Promise<string> => {
|
export const getLatestAvailableAgentVersion = async (
|
||||||
const kbnStatus = await kbnClient.status.get();
|
kbnClient: KbnClient,
|
||||||
|
log: ToolingLog
|
||||||
|
): Promise<string> => {
|
||||||
|
let currentVersion: string;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const kbnStatus = await kbnClient.status.get();
|
||||||
|
currentVersion = kbnStatus.version.number;
|
||||||
|
} catch {
|
||||||
|
log.warning(chalk.bold('Failed to get Kibana version, using package.json version'));
|
||||||
|
currentVersion = kibanaPackageJson.version;
|
||||||
|
}
|
||||||
|
|
||||||
const agentVersions = await pRetry(
|
const agentVersions = await pRetry(
|
||||||
async () => {
|
async () => {
|
||||||
const response = await axios.get('https://artifacts-api.elastic.co/v1/versions');
|
const response = await axios.get('https://artifacts-api.elastic.co/v1/versions');
|
||||||
|
@ -157,9 +172,15 @@ export const getLatestAvailableAgentVersion = async (kbnClient: KbnClient): Prom
|
||||||
}
|
}
|
||||||
).catch(() => null);
|
).catch(() => null);
|
||||||
|
|
||||||
|
if (!agentVersions) {
|
||||||
|
log.warning(
|
||||||
|
chalk.bold('Failed to get agent versions from artifacts-api, using package.json version')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const version = agentVersions
|
const version = agentVersions
|
||||||
? semver.maxSatisfying(agentVersions, `<=${kbnStatus.version.number}`)
|
? semver.maxSatisfying(agentVersions, `<=${currentVersion}`)
|
||||||
: kbnStatus.version.number;
|
: currentVersion;
|
||||||
|
|
||||||
return `${version}-SNAPSHOT`;
|
return `${version}-SNAPSHOT`;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue