Skip to content

Commit

Permalink
Merge branch 'main' of github.com:elastic/kibana into 163590-dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
kpatticha committed Oct 2, 2023
2 parents 8e7be83 + 267328b commit 6093ebf
Show file tree
Hide file tree
Showing 481 changed files with 111,323 additions and 4,057 deletions.
104 changes: 76 additions & 28 deletions .buildkite/scripts/steps/check_types_commits.sh
Expand Up @@ -2,40 +2,92 @@

set -euo pipefail

# This script will collect typescript projects and run typecheck on projects between the given 2 parameters
# Could be used for selective typechecking on projects that might be affected for a given PR.
# This script detects the files changed in a given set of commits, finds the related tsconfig.json files, and scope the TypeScript type check to those.
# In CI, this script can be used for selective type-checking on projects that might be affected for a given PR.
# (The accuracy for finding related projects is not a 100%)

if [[ "${CI-}" == "true" ]]; then
.buildkite/scripts/bootstrap.sh
argv=( "$@" )
diffArgs=("--name-only")
uniq_dirs=()
uniq_tsconfigs=()

sha1=$(git merge-base $GITHUB_PR_TARGET_BRANCH $GITHUB_PR_TRIGGERED_SHA)
sha2="${GITHUB_PR_TRIGGERED_SHA-}"
else
if [[ "${1-}" == "--cached" ]]; then
# Only check staged files
sha1=$1
sha2=""
is_flag_set () {
flag=$1
if [ ${#argv[@]} -gt 0 ] && [[ ${argv[@]} =~ $flag ]]; then
true
else
# Script take between 0 and 2 arguments representing two commit SHA's:
# If 0, it will diff HEAD and HEAD^
# If 1 (SHA1), it will diff SHA1 and SHA1^
# If 2 (SHA1, SHA2), it will diff SHA1 and SHA2
sha1="${1-HEAD}"
sha2="${2-$sha1^}"
false
fi
}

get_args_for_flag_result=()
get_args_for_flag () {
flag=$1
found=false
get_args_for_flag_result=()
if [ ${#argv[@]} -gt 0 ]; then
for i in "${!argv[@]}"; do
arg="${argv[$i]}"
if [ "$found" == false ] && [[ "$arg" == "$flag" ]]; then
found=true
elif [ "$found" == true ]; then
if [[ "$arg" == -* ]]; then
return
else
get_args_for_flag_result+=("$arg")
fi
fi
done
fi
}

if is_flag_set "--help" || is_flag_set "-h"; then
echo "Detects the files changed in a given set of commits, finds the related"
echo "tsconfig.json files, and scope the TypeScript type check to those."
echo
echo "Usage:"
echo " $0 [options]"
echo " $0 [<ref1> [<ref2>]]"
echo
echo "Options:"
echo " --help, -h Show this help"
echo " --cached Check staged changes"
echo " --merge-base [<ref1> [<ref2>]]"
echo " Check changes between nearest common ansestor (merge-base) of"
echo " ref1 and ref2. Defaults: 'main' and 'HEAD'"
echo
echo "If no options are provided, the script takes between 0 and 2 arguments"
echo "representing two git refs:"
echo " If 0, it will diff HEAD and HEAD^"
echo " If 1 (REF1), it will diff REF1 and REF1^"
echo " If 2 (REF1, REF2), it will diff REF1 and REF2"
exit
fi

uniq_dirs=()
uniq_tsconfigs=()
if [[ "${CI-}" == "true" ]]; then
# Buildkite only
.buildkite/scripts/bootstrap.sh

if [[ "$sha1" == "--cached" ]]; then
echo "Detecting files changed in staging area..."
targetBranch="${GITHUB_PR_TARGET_BRANCH-}"
git fetch origin $targetBranch
sha=$(git merge-base "origin/$targetBranch" "${GITHUB_PR_TRIGGERED_SHA-}")
diffArgs+=("$sha" "${GITHUB_PR_TRIGGERED_SHA-}")
elif is_flag_set "--merge-base"; then
# Similar to when CI=true, but locally
get_args_for_flag "--merge-base"
diffArgs+=("--merge-base" "${get_args_for_flag_result[0]-main}" "${get_args_for_flag_result[1]-HEAD}")
elif is_flag_set "--cached"; then
# Only check staged files
diffArgs+=("--cached")
else
echo "Detecting files changed between $sha1 and $sha2..."
# Full manual mode!
ref1="${1-HEAD}"
diffArgs+=("$ref1" "${2-$ref1^}")
fi

files=($(git diff --name-only $sha1 $sha2))
echo "Detecting files changed..."
echo "DEBUG: git diff args: ${diffArgs[@]}"
files=($(git diff "${diffArgs[@]}"))

add_dir () {
new_dir=$1
Expand Down Expand Up @@ -117,11 +169,7 @@ if [ ${#uniq_dirs[@]} -gt 0 ]; then
fi

if [ ${#uniq_tsconfigs[@]} -eq 0 ]; then
if [[ "$sha1" == "--cached" ]]; then
echo "No tsconfig.json files found for staged changes"
else
echo "No tsconfig.json files found for changes between $sha1 and $sha2"
fi
echo "No tsconfig.json files found"
exit
fi

Expand Down
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Expand Up @@ -274,6 +274,7 @@ packages/core/status/core-status-server-mocks @elastic/kibana-core
packages/core/test-helpers/core-test-helpers-deprecations-getters @elastic/kibana-core
packages/core/test-helpers/core-test-helpers-http-setup-browser @elastic/kibana-core
packages/core/test-helpers/core-test-helpers-kbn-server @elastic/kibana-core
packages/core/test-helpers/core-test-helpers-model-versions @elastic/kibana-core
packages/core/test-helpers/core-test-helpers-so-type-serializer @elastic/kibana-core
packages/core/test-helpers/core-test-helpers-test-utils @elastic/kibana-core
packages/core/theme/core-theme-browser @elastic/kibana-core
Expand Down Expand Up @@ -1239,6 +1240,7 @@ x-pack/plugins/cloud_integrations/cloud_full_story/server/config.ts @elastic/kib
/x-pack/plugins/security_solution/public/common/components/ml_popover @elastic/security-detection-rule-management
/x-pack/plugins/security_solution/public/common/components/popover_items @elastic/security-detection-rule-management
/x-pack/plugins/security_solution/public/detection_engine/fleet_integrations @elastic/security-detection-rule-management
/x-pack/plugins/security_solution/public/detection_engine/endpoint_exceptions @elastic/security-defend-workflows
/x-pack/plugins/security_solution/public/detection_engine/rule_details_ui @elastic/security-detection-rule-management
/x-pack/plugins/security_solution/public/detection_engine/rule_management @elastic/security-detection-rule-management
/x-pack/plugins/security_solution/public/detection_engine/rule_management_ui @elastic/security-detection-rule-management
Expand Down Expand Up @@ -1336,6 +1338,7 @@ x-pack/plugins/cloud_integrations/cloud_full_story/server/config.ts @elastic/kib
/x-pack/test/security_solution_endpoint_api_int/ @elastic/security-defend-workflows
/x-pack/test_serverless/shared/lib/security/kibana_roles/ @elastic/security-defend-workflows
/x-pack/plugins/security_solution_serverless/public/upselling/sections/endpoint_management @elastic/security-defend-workflows
/x-pack/plugins/security_solution_serverless/public/upselling/pages/endpoint_management @elastic/security-defend-workflows
/x-pack/plugins/security_solution_serverless/server/endpoint @elastic/security-defend-workflows

## Security Solution sub teams - security-telemetry (Data Engineering)
Expand Down
7 changes: 4 additions & 3 deletions package.json
Expand Up @@ -98,7 +98,7 @@
"@dnd-kit/utilities": "^2.0.0",
"@elastic/apm-rum": "^5.14.0",
"@elastic/apm-rum-react": "^2.0.0",
"@elastic/charts": "59.1.0",
"@elastic/charts": "60.0.0",
"@elastic/datemath": "5.0.3",
"@elastic/elasticsearch": "npm:@elastic/elasticsearch-canary@8.9.1-canary.1",
"@elastic/ems-client": "8.4.0",
Expand Down Expand Up @@ -936,8 +936,8 @@
"jsts": "^1.6.2",
"kea": "^2.4.2",
"langchain": "^0.0.151",
"launchdarkly-js-client-sdk": "^2.22.1",
"launchdarkly-node-server-sdk": "^6.4.2",
"launchdarkly-js-client-sdk": "^3.1.4",
"launchdarkly-node-server-sdk": "^7.0.3",
"load-json-file": "^6.2.0",
"lodash": "^4.17.21",
"lru-cache": "^4.1.5",
Expand Down Expand Up @@ -1180,6 +1180,7 @@
"@kbn/core-saved-objects-server-mocks": "link:packages/core/saved-objects/core-saved-objects-server-mocks",
"@kbn/core-status-server-mocks": "link:packages/core/status/core-status-server-mocks",
"@kbn/core-test-helpers-kbn-server": "link:packages/core/test-helpers/core-test-helpers-kbn-server",
"@kbn/core-test-helpers-model-versions": "link:packages/core/test-helpers/core-test-helpers-model-versions",
"@kbn/core-theme-browser-mocks": "link:packages/core/theme/core-theme-browser-mocks",
"@kbn/core-ui-settings-browser-mocks": "link:packages/core/ui-settings/core-ui-settings-browser-mocks",
"@kbn/core-ui-settings-server-mocks": "link:packages/core/ui-settings/core-ui-settings-server-mocks",
Expand Down
@@ -0,0 +1,19 @@
# @kbn/core-test-helpers-model-versions

Package exposing utilities for model version integration testing.

This package exposes a `createModelVersionTestBed` utility which allow simulating
a testbed environment where we're in the cohabitation period between two versions, to test the interactions
between two model versions of a set of SO types.

### Limitations:

Because the test bed is only creating the parts of Core required to create the two SO
repositories, and because we're not loading all plugins (for proper isolation), the integration
test bed has some limitations:

- no extensions are enabled
- no security
- no encryption
- no spaces
- all SO types will be using the same SO index
@@ -0,0 +1,16 @@
/*
* 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.
*/

export { createModelVersionTestBed } from './src/test_bed';

export type {
ModelVersionTestBed,
ModelVersionTestKit,
ModelVersionTestkitOptions,
SavedObjectTestkitDefinition,
} from './src/types';
@@ -0,0 +1,13 @@
/*
* 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.
*/

module.exports = {
preset: '@kbn/test/jest_node',
rootDir: '../../../..',
roots: ['<rootDir>/packages/core/test-helpers/core-test-helpers-model-versions'],
};
@@ -0,0 +1,6 @@
{
"type": "shared-common",
"id": "@kbn/core-test-helpers-model-versions",
"owner": "@elastic/kibana-core",
"devOnly": true
}
@@ -0,0 +1,6 @@
{
"name": "@kbn/core-test-helpers-model-versions",
"private": true,
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0"
}
@@ -0,0 +1,34 @@
/*
* 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 { createTestServers, type TestElasticsearchUtils } from '@kbn/core-test-helpers-kbn-server';

/**
* Start the traditional ES cluster and return the instance.
*/
export const startElasticsearch = async ({
basePath,
dataArchive,
timeout,
}: {
basePath?: string;
dataArchive?: string;
timeout?: number;
} = {}): Promise<TestElasticsearchUtils> => {
const { startES } = createTestServers({
adjustTimeout: (t: number) => jest.setTimeout(t + (timeout ?? 0)),
settings: {
es: {
license: 'basic',
basePath,
dataArchive,
},
},
});
return await startES();
};
@@ -0,0 +1,89 @@
/*
* 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 { TestElasticsearchUtils } from '@kbn/core-test-helpers-kbn-server';
import { startElasticsearch } from './elasticsearch';
import { prepareModelVersionTestKit } from './test_kit';
import type { ModelVersionTestBed } from './types';

/**
* Create a {@link ModelVersionTestBed} that can be used for model version integration testing.
*
* @example
* ```ts
* describe('myIntegrationTest', () => {
* const testbed = createModelVersionTestBed();
* let testkit: ModelVersionTestKit;
*
* beforeAll(async () => {
* await testbed.startES();
* });
*
* afterAll(async () => {
* await testbed.stopES();
* });
*
* beforeEach(async () => {
* testkit = await testbed.prepareTestKit({
* savedObjectDefinitions: [{
* definition: mySoTypeDefinition,
* modelVersionBefore: 1,
* modelVersionAfter: 2,
* }]
* })
* });
*
* afterEach(async () => {
* if(testkit) {
* await testkit.tearsDown();
* }
* });
*
* it('can be used to test model version cohabitation', async () => {
* // last registered version is `1`
* const repositoryV1 = testkit.repositoryBefore;
* // last registered version is `2`
* const repositoryV2 = testkit.repositoryAfter;
*
* // do something with the two repositories, e.g
* await repositoryV1.create(someAttrs, { id });
* const v2docReadFromV1 = await repositoryV2.get('my-type', id);
* expect(v2docReadFromV1.attributes).toEqual(something);
* })
* })
* ```
*
* @public
*/
export const createModelVersionTestBed = (): ModelVersionTestBed => {
let elasticsearch: TestElasticsearchUtils | undefined;

const startES = async () => {
if (elasticsearch) {
throw new Error('Elasticsearch already started');
}
elasticsearch = await startElasticsearch();
};

const stopES = async () => {
if (!elasticsearch) {
throw new Error('Elasticsearch not started');
}
await elasticsearch.stop();
await delay(10);
elasticsearch = undefined;
};

return {
startES,
stopES,
prepareTestKit: prepareModelVersionTestKit,
};
};

const delay = (seconds: number) => new Promise((resolve) => setTimeout(resolve, seconds * 1000));

0 comments on commit 6093ebf

Please sign in to comment.