Skip to content

Commit

Permalink
Merge branch 'main' into output-health
Browse files Browse the repository at this point in the history
  • Loading branch information
juliaElastic authored Dec 4, 2023
2 parents 1b258bd + e1b585c commit 07e638a
Show file tree
Hide file tree
Showing 1,319 changed files with 30,159 additions and 5,843 deletions.
107 changes: 101 additions & 6 deletions .buildkite/pipeline-utils/buildkite/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,31 @@
*/

import axios, { AxiosInstance } from 'axios';
import { execSync } from 'child_process';
import { execSync, ExecSyncOptions } from 'child_process';
import { dump } from 'js-yaml';
import { parseLinkHeader } from './parse_link_header';
import { Artifact } from './types/artifact';
import { Build, BuildStatus } from './types/build';
import { Job, JobState } from './types/job';

type ExecType =
| ((command: string, execOpts: ExecSyncOptions) => Buffer | null)
| ((command: string, execOpts: ExecSyncOptions) => string | null);

export interface BuildkiteClientConfig {
baseUrl?: string;
token?: string;
exec?: ExecType;
}

export interface BuildkiteGroup {
group: string;
steps: BuildkiteStep[];
}

export interface BuildkiteStep {
export type BuildkiteStep = BuildkiteCommandStep | BuildkiteInputStep;

export interface BuildkiteCommandStep {
command: string;
label: string;
parallelism?: number;
Expand All @@ -43,6 +50,50 @@ export interface BuildkiteStep {
env?: { [key: string]: string };
}

interface BuildkiteInputTextField {
text: string;
key: string;
hint?: string;
required?: boolean;
default?: string;
}

interface BuildkiteInputSelectField {
select: string;
key: string;
hint?: string;
required?: boolean;
default?: string;
multiple?: boolean;
options: Array<{
label: string;
value: string;
}>;
}

export interface BuildkiteInputStep {
input: string;
prompt?: string;
fields: Array<BuildkiteInputTextField | BuildkiteInputSelectField>;
if?: string;
allow_dependency_failure?: boolean;
branches?: string;
parallelism?: number;
agents?: {
queue: string;
};
timeout_in_minutes?: number;
key?: string;
depends_on?: string | string[];
retry?: {
automatic: Array<{
exit_status: string;
limit: number;
}>;
};
env?: { [key: string]: string };
}

export interface BuildkiteTriggerBuildParams {
commit: string;
branch: string;
Expand All @@ -61,6 +112,7 @@ export interface BuildkiteTriggerBuildParams {

export class BuildkiteClient {
http: AxiosInstance;
exec: ExecType;

constructor(config: BuildkiteClientConfig = {}) {
const BUILDKITE_BASE_URL =
Expand All @@ -78,6 +130,8 @@ export class BuildkiteClient {
},
});

this.exec = config.exec ?? execSync;

// this.agentHttp = axios.create({
// baseURL: BUILDKITE_AGENT_BASE_URL,
// headers: {
Expand All @@ -97,6 +151,32 @@ export class BuildkiteClient {
return resp.data as Build;
};

getBuildsAfterDate = async (
pipelineSlug: string,
date: string,
numberOfBuilds: number
): Promise<Build[]> => {
const response = await this.http.get(
`v2/organizations/elastic/pipelines/${pipelineSlug}/builds?created_from=${date}&per_page=${numberOfBuilds}`
);
return response.data as Build[];
};

getBuildForCommit = async (pipelineSlug: string, commit: string): Promise<Build | null> => {
if (commit.length !== 40) {
throw new Error(`Invalid commit hash: ${commit}, this endpoint works with full SHAs only`);
}

const response = await this.http.get(
`v2/organizations/elastic/pipelines/${pipelineSlug}/builds?commit=${commit}`
);
const builds = response.data as Build[];
if (builds.length === 0) {
return null;
}
return builds[0];
};

getCurrentBuild = (includeRetriedJobs = false) => {
if (!process.env.BUILDKITE_PIPELINE_SLUG || !process.env.BUILDKITE_BUILD_NUMBER) {
throw new Error(
Expand Down Expand Up @@ -235,31 +315,46 @@ export class BuildkiteClient {
};

setMetadata = (key: string, value: string) => {
execSync(`buildkite-agent meta-data set '${key}'`, {
this.exec(`buildkite-agent meta-data set '${key}'`, {
input: value,
stdio: ['pipe', 'inherit', 'inherit'],
});
};

getMetadata(key: string, defaultValue: string | null = null): string | null {
try {
const stdout = this.exec(`buildkite-agent meta-data get '${key}'`, {
stdio: ['pipe'],
});
return stdout?.toString().trim() || defaultValue;
} catch (e) {
if (e.message.includes('404 Not Found')) {
return defaultValue;
} else {
throw e;
}
}
}

setAnnotation = (
context: string,
style: 'info' | 'success' | 'warning' | 'error',
value: string
) => {
execSync(`buildkite-agent annotate --context '${context}' --style '${style}'`, {
this.exec(`buildkite-agent annotate --context '${context}' --style '${style}'`, {
input: value,
stdio: ['pipe', 'inherit', 'inherit'],
});
};

uploadArtifacts = (pattern: string) => {
execSync(`buildkite-agent artifact upload '${pattern}'`, {
this.exec(`buildkite-agent artifact upload '${pattern}'`, {
stdio: ['ignore', 'inherit', 'inherit'],
});
};

uploadSteps = (steps: Array<BuildkiteStep | BuildkiteGroup>) => {
execSync(`buildkite-agent pipeline upload`, {
this.exec(`buildkite-agent pipeline upload`, {
input: dump({ steps }),
stdio: ['pipe', 'inherit', 'inherit'],
});
Expand Down
4 changes: 4 additions & 0 deletions .buildkite/pipeline-utils/github/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,7 @@ export const doAnyChangesMatch = async (

return anyFilesMatchRequired;
};

export function getGithubClient() {
return github;
}
1 change: 1 addition & 0 deletions .buildkite/pipeline-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export * from './buildkite';
export * as CiStats from './ci-stats';
export * from './github';
export * as TestFailures from './test-failures';
export * from './utils';
24 changes: 24 additions & 0 deletions .buildkite/pipeline-utils/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { execSync } from 'child_process';

const getKibanaDir = (() => {
let kibanaDir: string | undefined;
return () => {
if (!kibanaDir) {
kibanaDir = execSync('git rev-parse --show-toplevel', { encoding: 'utf-8' })
.toString()
.trim();
}

return kibanaDir;
};
})();

export { getKibanaDir };
42 changes: 6 additions & 36 deletions .buildkite/pipelines/es_serverless/verify_es_serverless_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,7 @@ steps:
- exit_status: '*'
limit: 1

- command: .buildkite/scripts/steps/functional/security_cypress_exec.sh
env:
TARGET: cypress:run:serverless
ROOT_DIR: x-pack/test/security_solution_cypress
JOB_TITLE: kibana-serverless-security-cypress
MSG: "--- Security Serverless Cypress Tests"
- command: .buildkite/scripts/steps/functional/security_serverless.sh
label: 'Serverless Security Cypress Tests'
if: "build.env('SKIP_CYPRESS') != '1' && build.env('SKIP_CYPRESS') != 'true'"
agents:
Expand All @@ -74,12 +69,7 @@ steps:
- exit_status: '*'
limit: 1

- command: .buildkite/scripts/steps/functional/security_cypress_exec.sh
env:
TARGET: cypress:explore:run:serverless
ROOT_DIR: x-pack/test/security_solution_cypress
JOB_TITLE: kibana-security-solution-chrome
MSG: "--- Explore - Security Solution Cypress Tests"
- command: .buildkite/scripts/steps/functional/security_serverless_explore.sh
label: 'Serverless Explore - Security Solution Cypress Tests'
if: "build.env('SKIP_CYPRESS') != '1' && build.env('SKIP_CYPRESS') != 'true'"
agents:
Expand All @@ -92,12 +82,7 @@ steps:
- exit_status: '*'
limit: 1

- command: .buildkite/scripts/steps/functional/security_cypress_exec.sh
env:
TARGET: cypress:investigations:run:serverless
ROOT_DIR: x-pack/test/security_solution_cypress
JOB_TITLE: kibana-security-solution-chrome
MSG: "--- Investigations Cypress Tests on Serverless"
- command: .buildkite/scripts/steps/functional/security_serverless_investigations.sh
label: 'Serverless Investigations - Security Solution Cypress Tests'
if: "build.env('SKIP_CYPRESS') != '1' && build.env('SKIP_CYPRESS') != 'true'"
agents:
Expand All @@ -110,12 +95,7 @@ steps:
- exit_status: '*'
limit: 1

- command: .buildkite/scripts/steps/functional/security_cypress_exec.sh
env:
TARGET: cypress:rule_management:run:serverless
ROOT_DIR: x-pack/test/security_solution_cypress
JOB_TITLE: kibana-security-solution-chrome
MSG: "--- Rule Management Cypress Tests on Serverless"
- command: .buildkite/scripts/steps/functional/security_serverless_rule_management.sh
label: 'Serverless Rule Management - Security Solution Cypress Tests'
if: "build.env('SKIP_CYPRESS') != '1' && build.env('SKIP_CYPRESS') != 'true'"
agents:
Expand All @@ -128,12 +108,7 @@ steps:
- exit_status: '*'
limit: 1

- command: .buildkite/scripts/steps/functional/security_cypress_exec.sh
env:
TARGET: cypress:rule_management:prebuilt_rules:run:serverless
ROOT_DIR: x-pack/test/security_solution_cypress
JOB_TITLE: kibana-security-solution-chrome
MSG: "--- Rule Management - Prebuilt Rules - Cypress Tests on Serverless"
- command: .buildkite/scripts/steps/functional/security_serverless_rule_management_prebuilt_rules.sh
label: 'Serverless Rule Management - Prebuilt Rules - Security Solution Cypress Tests'
if: "build.env('SKIP_CYPRESS') != '1' && build.env('SKIP_CYPRESS') != 'true'"
agents:
Expand All @@ -146,12 +121,7 @@ steps:
- exit_status: '*'
limit: 1

- command: .buildkite/scripts/steps/functional/security_cypress_exec.sh
env:
TARGET: cypress:dw:serverless:run
ROOT_DIR: x-pack/plugins/security_solution
JOB_TITLE: kibana-defend-workflows-serverless-cypress
MSG: "--- Defend Workflows Cypress tests on Serverless"
- command: .buildkite/scripts/steps/functional/defend_workflows_serverless.sh
label: 'Defend Workflows Cypress Tests on Serverless'
if: "build.env('SKIP_CYPRESS') != '1' && build.env('SKIP_CYPRESS') != 'true'"
agents:
Expand Down
17 changes: 17 additions & 0 deletions .buildkite/pipelines/flaky_tests/groups.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@
{
"key": "cypress/security_serverless_explore",
"name": "[Serverless] Security Solution Explore - Cypress"
},
{
"key": "cypress/security_solution_rule_management",
"name": "Security Solution Rule Management - Cypress"
},
{
"key": "cypress/security_serverless_rule_management",
"name": "[Serverless] Security Solution Rule Management - Cypress"
},

{
"key": "cypress/security_solution_rule_management_prebuilt_rules",
"name": "Security Solution Rule Management - Prebuilt Rules - Cypress"
},
{
"key": "cypress/security_serverless_rule_management_prebuilt_rules",
"name": "[Serverless] Security Solution Rule Management - Prebuilt Rules - Cypress"
},
{
"key": "cypress/defend_workflows",
Expand Down
Loading

0 comments on commit 07e638a

Please sign in to comment.