Skip to content

Commit ce10318

Browse files
szwarckonradpatrykkopycinskimistic
authored
[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 <[email protected]> Co-authored-by: Tiago Costa <[email protected]>
1 parent 1d430d4 commit ce10318

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

x-pack/test/osquery_cypress/agent.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ export class AgentManager extends Manager {
4141
this.log.info(chalk.bold('Setting up Agent'));
4242

4343
const artifact = `docker.elastic.co/elastic-agent/elastic-agent:${await getLatestAvailableAgentVersion(
44-
this.kbnClient
44+
this.kbnClient,
45+
this.log
4546
)}`;
4647
this.log.indent(4, () => this.log.info(`Image: ${artifact}`));
4748
const containerName = generateRandomString(12);

x-pack/test/osquery_cypress/fleet_server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class FleetManager extends Manager {
2626
}
2727

2828
public async setup(): Promise<void> {
29-
const version = await getLatestAvailableAgentVersion(this.kbnClient);
29+
const version = await getLatestAvailableAgentVersion(this.kbnClient, this.log);
3030
this.fleetServer = await startFleetServer({
3131
kbnClient: this.kbnClient,
3232
logger: this.log,

x-pack/test/osquery_cypress/utils.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import axios from 'axios';
99
import semver from 'semver';
1010
import { map } from 'lodash';
1111
import { PackagePolicy, CreatePackagePolicyResponse, API_VERSIONS } from '@kbn/fleet-plugin/common';
12+
// @ts-expect-error we have to check types with "allowJs: false" for now, causing this import to fail
13+
import { kibanaPackageJson } from '@kbn/repo-info';
1214
import { KbnClient } from '@kbn/test';
1315
import {
1416
GetEnrollmentAPIKeysResponse,
@@ -140,10 +142,23 @@ const isValidArtifactVersion = (version: string) => !!version.match(/^\d+\.\d+\.
140142
* Returns the Agent version that is available for install (will check `artifacts-api.elastic.co/v1/versions`)
141143
* that is equal to or less than `maxVersion`.
142144
* @param kbnClient
145+
* @param log
143146
*/
144147

145-
export const getLatestAvailableAgentVersion = async (kbnClient: KbnClient): Promise<string> => {
146-
const kbnStatus = await kbnClient.status.get();
148+
export const getLatestAvailableAgentVersion = async (
149+
kbnClient: KbnClient,
150+
log: ToolingLog
151+
): Promise<string> => {
152+
let currentVersion: string;
153+
154+
try {
155+
const kbnStatus = await kbnClient.status.get();
156+
currentVersion = kbnStatus.version.number;
157+
} catch {
158+
log.warning(chalk.bold('Failed to get Kibana version, using package.json version'));
159+
currentVersion = kibanaPackageJson.version;
160+
}
161+
147162
const agentVersions = await pRetry(
148163
async () => {
149164
const response = await axios.get('https://artifacts-api.elastic.co/v1/versions');
@@ -157,9 +172,15 @@ export const getLatestAvailableAgentVersion = async (kbnClient: KbnClient): Prom
157172
}
158173
).catch(() => null);
159174

175+
if (!agentVersions) {
176+
log.warning(
177+
chalk.bold('Failed to get agent versions from artifacts-api, using package.json version')
178+
);
179+
}
180+
160181
const version = agentVersions
161-
? semver.maxSatisfying(agentVersions, `<=${kbnStatus.version.number}`)
162-
: kbnStatus.version.number;
182+
? semver.maxSatisfying(agentVersions, `<=${currentVersion}`)
183+
: currentVersion;
163184

164185
return `${version}-SNAPSHOT`;
165186
};

0 commit comments

Comments
 (0)