Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Saved Objects] Compatible mappings PR check #148656

Merged
merged 72 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
336b401
added an initial version of the mappings PR check CLI
jloleysens Jan 10, 2023
879854f
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Jan 10, 2023
ccdb0d6
[CI] Auto-commit changed files from 'node scripts/ts_project_linter -…
kibanamachine Jan 10, 2023
1661e7d
some refactorings and added a levelled logger
jloleysens Jan 11, 2023
92244b5
updated logs
jloleysens Jan 11, 2023
e02376a
some minor refactoring of helper functions out of CLI declaration and…
jloleysens Jan 11, 2023
e396f3e
added util file
jloleysens Jan 11, 2023
570a114
[CI] Auto-commit changed files from 'node scripts/ts_project_linter -…
kibanamachine Jan 11, 2023
5ed9b6f
use tooling-log for logging
jloleysens Jan 11, 2023
2f042e6
another minor refactor, still need to figure additive-only changes...
jloleysens Jan 11, 2023
6b225d5
[CI] Auto-commit changed files from 'node scripts/ts_project_linter -…
kibanamachine Jan 11, 2023
38059d2
update comment
jloleysens Jan 11, 2023
68b87e8
fix comment
jloleysens Jan 11, 2023
7df09ad
move startES helper to utils
jloleysens Jan 11, 2023
d2ef288
Merge branch 'main' into compatible-schema-change-check
jloleysens Jan 12, 2023
728117f
refactor: move incompat check to own file
jloleysens Jan 12, 2023
9663e63
small refactor of where esClient is instantiated and also added algo …
jloleysens Jan 12, 2023
4d6ecba
updated CLI log to be slightly clearer
jloleysens Jan 12, 2023
7956cf0
set up CLI to run as PR check step
jloleysens Jan 12, 2023
7d5aac4
move saved objects compat check to base PR steps
jloleysens Jan 12, 2023
176c18d
add depends on
jloleysens Jan 12, 2023
590a611
do bootstrap before running CLI
jloleysens Jan 12, 2023
732b800
finish README
jloleysens Jan 12, 2023
ac08d24
update types and docs for PluginSystemOverrides class
jloleysens Jan 12, 2023
f5743a4
added class-level comment too
jloleysens Jan 12, 2023
3f2b245
[CI] Auto-commit changed files from 'node src/cli_compatible_mappings…
kibanamachine Jan 12, 2023
ecc0773
Merge branch 'main' of github.com:elastic/kibana into pr/148656
Jan 13, 2023
f1e6965
[checkMappingsUpdate] convert to a dev cli
Jan 13, 2023
b3fbae1
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Jan 13, 2023
d954a83
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine Jan 13, 2023
fdd800c
Merge branch 'main' into compatible-schema-change-check
jloleysens Jan 16, 2023
49b6cc0
minor refactor of logic
jloleysens Jan 16, 2023
8b01ace
stricter typing and avoid using deprecated Rx API
jloleysens Jan 16, 2023
f48b9f8
remove static-package pattern
jloleysens Jan 17, 2023
a55a23d
implemented config-driven override instead
jloleysens Jan 17, 2023
99508ba
omit from public interfaces
jloleysens Jan 17, 2023
c398e04
refactor private function name
jloleysens Jan 17, 2023
5e4d167
use PluginConfig instead
jloleysens Jan 17, 2023
c0acfdf
added plugin service-level test
jloleysens Jan 17, 2023
a20896e
added additive only check tests
jloleysens Jan 17, 2023
d15fbc9
test behaviour when adding a new field
jloleysens Jan 17, 2023
346d938
added test for empty current object
jloleysens Jan 17, 2023
e1e3a64
added incompat mappings test
jloleysens Jan 17, 2023
ca095ad
added test for expected inputs
jloleysens Jan 17, 2023
5e1cb46
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Jan 17, 2023
fff5557
Merge branch 'main' into compatible-schema-change-check
jloleysens Jan 18, 2023
d838753
minor refactor to remove const string from PluginConfig class
jloleysens Jan 18, 2023
669f0dc
[CI] Auto-commit changed files from 'node scripts/check_mappings_upda…
kibanamachine Jan 18, 2023
e30b972
Merge branch 'main' into compatible-schema-change-check
jloleysens Jan 19, 2023
930bf71
Merge branch 'main' into compatible-schema-change-check
jloleysens Jan 20, 2023
45c9cf2
run compat check with other checks, not in own job
jloleysens Jan 20, 2023
d2f23d1
remove "__internal__" from config path
jloleysens Jan 20, 2023
719f5ab
fix jest test
jloleysens Jan 23, 2023
0a81e23
Merge branch 'main' into compatible-schema-change-check
jloleysens Jan 23, 2023
da85a0d
Merge branch 'main' into compatible-schema-change-check
jloleysens Jan 26, 2023
f67af65
Merge branch 'main' into compatible-schema-change-check
jloleysens Feb 2, 2023
0a185eb
Merge branch 'main' into compatible-schema-change-check
jloleysens Feb 8, 2023
7bef5b4
CLI usability fix: make it so that running with --fix implies we skip…
jloleysens Feb 8, 2023
8ac9bfc
updated mappings snapshot
jloleysens Feb 8, 2023
8ffebf1
Revert "CLI usability fix: make it so that running with --fix implies…
jloleysens Feb 8, 2023
a9b2e06
Merge branch 'main' into compatible-schema-change-check
jloleysens Feb 10, 2023
1aeaa94
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine Feb 10, 2023
6e9640c
Merge branch 'main' into compatible-schema-change-check
jloleysens Feb 13, 2023
0aa561c
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine Feb 13, 2023
12b922b
Merge branch 'main' into compatible-schema-change-check
jloleysens Feb 14, 2023
6639be6
Merge branch 'main' into compatible-schema-change-check
jloleysens Feb 22, 2023
a7ae61b
update current mappings with incompatible changes
jloleysens Feb 22, 2023
481ac10
Merge branch 'main' into compatible-schema-change-check
jloleysens Mar 7, 2023
ab5ff42
Merge branch 'main' into compatible-schema-change-check
jloleysens Apr 26, 2023
f0dc206
fix snapshot and update code
jloleysens Apr 26, 2023
b34f0aa
remove eslint-disable?
jloleysens Apr 26, 2023
6432cb5
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Apr 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .buildkite/pipelines/pull_request/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,15 @@ steps:
automatic:
- exit_status: '-1'
limit: 3

- command: .buildkite/scripts/steps/checks/saved_objects_compat_changes.sh
label: 'Saved Objects compatible mappings check'
agents:
queue: n2-16-spot
timeout_in_minutes: 60
depends_on:
- build
retry:
automatic:
- exit_status: '-1'
limit: 3
17 changes: 17 additions & 0 deletions .buildkite/scripts/steps/checks/saved_objects_compat_changes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

set -euo pipefail

source .buildkite/scripts/common/util.sh

export DISABLE_BOOTSTRAP_VALIDATION=false
.buildkite/scripts/bootstrap.sh

echo --- Check Mappings Update
cmd="node scripts/check_mappings_update"
if is_pr && ! is_auto_commit_disabled; then
cmd="$cmd --fix"
fi
spalger marked this conversation as resolved.
Show resolved Hide resolved

eval "$cmd"
check_for_changed_files "$cmd" true
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,7 @@ packages/kbn-babel-transform @elastic/kibana-operations
packages/kbn-bazel-runner @elastic/kibana-operations
packages/kbn-cases-components @elastic/response-ops
packages/kbn-chart-icons @elastic/kibana-visualizations
packages/kbn-check-mappings-update-cli @elastic/kibana-core
packages/kbn-ci-stats-core @elastic/kibana-operations
packages/kbn-ci-stats-performance-metrics @elastic/kibana-operations
packages/kbn-ci-stats-reporter @elastic/kibana-operations
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,7 @@
"@kbn/babel-register": "link:packages/kbn-babel-register",
"@kbn/babel-transform": "link:packages/kbn-babel-transform",
"@kbn/bazel-runner": "link:packages/kbn-bazel-runner",
"@kbn/check-mappings-update-cli": "link:packages/kbn-check-mappings-update-cli",
"@kbn/ci-stats-core": "link:packages/kbn-ci-stats-core",
"@kbn/ci-stats-performance-metrics": "link:packages/kbn-ci-stats-performance-metrics",
"@kbn/ci-stats-reporter": "link:packages/kbn-ci-stats-reporter",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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.
*/

/**
* @internal
*/
export const ENABLE_ALL_PLUGINS_CONFIG_PATH = '__internal__.enableAllPlugins' as const;

/**
* Set this to true in the raw configuration passed to {@link Root} to force
* enable all plugins.
* @internal
*/
export const PLUGIN_SYSTEM_ENABLE_ALL_PLUGINS_CONFIG_PATH =
`plugins.${ENABLE_ALL_PLUGINS_CONFIG_PATH}` as const;
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,17 @@ describe('PluginsConfig', () => {
const config = new PluginsConfig(rawConfig, env);
expect(config.additionalPluginPaths).toEqual(['some-path', 'another-path']);
});

it('retrieves shouldEnableAllPlugins', () => {
const env = Env.createDefault(REPO_ROOT, getEnvOptions({ cliArgs: { dev: true } }));
const rawConfig: any = {
initialize: true,
paths: ['some-path', 'another-path'],
__internal__: {
enableAllPlugins: true,
},
jloleysens marked this conversation as resolved.
Show resolved Hide resolved
};
const config = new PluginsConfig(rawConfig, env);
expect(config.shouldEnableAllPlugins).toBe(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,31 @@
*/

import { schema, TypeOf } from '@kbn/config-schema';
import { get } from 'lodash';
import { Env } from '@kbn/config';
import type { ServiceConfigDescriptor } from '@kbn/core-base-server-internal';

import { ENABLE_ALL_PLUGINS_CONFIG_PATH } from './constants';

const configSchema = schema.object({
initialize: schema.boolean({ defaultValue: true }),

/**
* Defines an array of directories where another plugin should be loaded from.
*/
paths: schema.arrayOf(schema.string(), { defaultValue: [] }),
/**
* Internal config, not intended to be used by end users. Only for specific
* internal purposes.
*/
__internal__: schema.maybe(
schema.object({ enableAllPlugins: schema.boolean({ defaultValue: false }) })
),
});

export type PluginsConfigType = TypeOf<typeof configSchema>;
type InternalPluginsConfigType = TypeOf<typeof configSchema>;

export type PluginsConfigType = Omit<InternalPluginsConfigType, '__internal__'>;

export const config: ServiceConfigDescriptor<PluginsConfigType> = {
path: 'plugins',
Expand All @@ -43,9 +55,17 @@ export class PluginsConfig {
*/
public readonly additionalPluginPaths: readonly string[];

/**
* Whether to enable all plugins.
*
* @note this is intended to be an undocumented setting.
*/
public readonly shouldEnableAllPlugins: boolean;

constructor(rawConfig: PluginsConfigType, env: Env) {
this.initialize = rawConfig.initialize;
this.pluginSearchPaths = env.pluginSearchPaths;
this.additionalPluginPaths = rawConfig.paths;
this.shouldEnableAllPlugins = get(rawConfig, ENABLE_ALL_PLUGINS_CONFIG_PATH, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ import { PluginDiscoveryError } from './discovery';
import { PluginWrapper } from './plugin';
import { PluginsService } from './plugins_service';
import { PluginsSystem } from './plugins_system';
import { config } from './plugins_config';
import { config, PluginsConfigType } from './plugins_config';
import { take } from 'rxjs/operators';
import type { PluginConfigDescriptor } from '@kbn/core-plugins-server';
import { DiscoveredPlugin, PluginType } from '@kbn/core-base-common';

const MockPluginsSystem: jest.Mock<PluginsSystem<PluginType>> = PluginsSystem as any;

let pluginsService: PluginsService;
let pluginsConfig: PluginsConfigType;
let config$: BehaviorSubject<Record<string, any>>;
let configService: ConfigService;
let coreId: symbol;
Expand Down Expand Up @@ -130,7 +131,8 @@ async function testSetup() {
coreId = Symbol('core');
env = Env.createDefault(REPO_ROOT, getEnvOptions());

config$ = new BehaviorSubject<Record<string, any>>({ plugins: { initialize: true } });
pluginsConfig = { initialize: true, paths: [] };
config$ = new BehaviorSubject<Record<string, any>>({ plugins: pluginsConfig });
const rawConfigService = rawConfigServiceMock.create({ rawConfig$: config$ });
configService = new ConfigService(rawConfigService, env, logger);
await configService.setSchema(config.path, config.schema);
Expand Down Expand Up @@ -496,6 +498,52 @@ describe('PluginsService', () => {
`);
});

describe('"enableAllPlugins" __internal__ configuration', () => {
it('enables all plugins regardless of their configuration', async () => {
(pluginsConfig as any).__internal__ = { enableAllPlugins: true };
jest
.spyOn(configService, 'isEnabledAtPath')
.mockImplementation((path) => Promise.resolve(!path.includes('disabled')));
prebootMockPluginSystem.setupPlugins.mockResolvedValue(new Map());
standardMockPluginSystem.setupPlugins.mockResolvedValue(new Map());
await pluginsService.setup(setupDeps);

mockDiscover.mockReturnValue({
error$: from([]),
plugin$: from([
createPlugin('explicitly-disabled-plugin-preboot', {
type: PluginType.preboot,
disabled: true,
path: 'path-1-preboot',
configPath: 'path-1-preboot',
}),
createPlugin('explicitly-disabled-plugin-standard', {
disabled: true,
path: 'path-1-standard',
configPath: 'path-1-standard',
}),
createPlugin('plugin-with-missing-required-deps-preboot', {
type: PluginType.preboot,
path: 'path-2-preboot',
configPath: 'path-2-preboot',
requiredPlugins: ['missing-plugin-preboot'],
}),
]),
});

await pluginsService.discover({ environment: environmentPreboot, node: nodePreboot });
await pluginsService.preboot(prebootDeps);

expect(loggingSystemMock.collect(logger).info).toMatchInlineSnapshot(`
Array [
Array [
"Plugin \\"plugin-with-missing-required-deps-preboot\\" has been disabled since the following direct or transitive dependencies are missing, disabled, or have incompatible types: [missing-plugin-preboot]",
],
]
`);
});
});

it('does not throw in case of mutual plugin dependencies', async () => {
const prebootPlugins = [
createPlugin('first-plugin-preboot', {
Expand Down Expand Up @@ -727,6 +775,7 @@ describe('PluginsService', () => {
resolve(process.cwd(), 'plugins'),
resolve(process.cwd(), '..', 'kibana-extra'),
],
shouldEnableAllPlugins: false,
},
coreContext: { coreId, env, logger, configService },
instanceInfo: { uuid: 'uuid' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,19 @@ export class PluginsService implements CoreService<PluginsServiceSetup, PluginsS
}
}

const config = await firstValueFrom(this.config$);
const enableAllPlugins = config.shouldEnableAllPlugins;
if (enableAllPlugins) {
this.log.warn('Detected override configuration; will enable all plugins');
}

// Validate config and handle enabled statuses.
// NOTE: We can't do both in the same previous loop because some plugins' deprecations may affect others.
// Hence, we need all the deprecations to be registered before accessing any config parameter.
for (const plugin of plugins) {
const isEnabled = await this.coreContext.configService.isEnabledAtPath(plugin.configPath);
const isEnabled =
enableAllPlugins ||
(await this.coreContext.configService.isEnabledAtPath(plugin.configPath));

if (pluginEnableStatuses.has(plugin.name)) {
throw new Error(`Plugin with id "${plugin.name}" is already registered!`);
Expand Down
7 changes: 7 additions & 0 deletions packages/kbn-check-mappings-update-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# @kbn/check-mappings-update-cli

Saved Objects CLI tool that can be used to check whether a snapshot of current
mappings (i.e., mappings on main) is compatible with mappings we can extract
from the current code.

See `node scripts/check_mappings_update --help` for more info.
Loading