Skip to content

Commit

Permalink
Merge branch 'master' into migrate/ftr-service-class/testsubjects
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlemeshko committed May 26, 2021
2 parents bff524e + 1f02c48 commit 98c5e36
Show file tree
Hide file tree
Showing 164 changed files with 2,931 additions and 2,799 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"dependencies": {
"@elastic/apm-rum": "^5.6.1",
"@elastic/apm-rum-react": "^1.2.5",
"@elastic/charts": "29.1.0",
"@elastic/charts": "29.2.0",
"@elastic/datemath": "link:bazel-bin/packages/elastic-datemath/npm_module",
"@elastic/elasticsearch": "npm:@elastic/elasticsearch-canary@^8.0.0-canary.4",
"@elastic/ems-client": "7.13.0",
Expand Down
30 changes: 4 additions & 26 deletions packages/kbn-analytics/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ ts_project(
srcs = SRCS,
deps = DEPS,
declaration = True,
declaration_dir = "types",
declaration_dir = "target_types",
declaration_map = True,
incremental = True,
out_dir = "node",
out_dir = "target_node",
source_map = True,
root_dir = "src",
tsconfig = ":tsconfig",
Expand All @@ -72,38 +72,16 @@ ts_project(
deps = DEPS,
declaration = False,
incremental = True,
out_dir = "web",
out_dir = "target_web",
source_map = True,
root_dir = "src",
tsconfig = ":tsconfig_browser",
)

filegroup(
name = "tsc_types",
srcs = [":tsc"],
output_group = "types",
)

filegroup(
name = "target_files",
srcs = [
":tsc",
":tsc_browser",
":tsc_types",
],
)

pkg_npm(
name = "target",
deps = [
":target_files",
],
)

js_library(
name = PKG_BASE_NAME,
srcs = NPM_MODULE_EXTRA_FILES,
deps = DEPS + [":target"],
deps = DEPS + [":tsc", ":tsc_browser"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)
Expand Down
6 changes: 3 additions & 3 deletions packages/kbn-analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"private": true,
"version": "1.0.0",
"description": "Kibana Analytics tool",
"main": "target/node/index.js",
"types": "target/types/index.d.ts",
"browser": "target/web/index.js",
"main": "target_node/index.js",
"types": "target_types/index.d.ts",
"browser": "target_web/index.js",
"author": "Ahmad Bamieh <ahmadbamieh@gmail.com>",
"license": "SSPL-1.0 OR Elastic License 2.0"
}
2 changes: 1 addition & 1 deletion packages/kbn-analytics/tsconfig.browser.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"extends": "../../tsconfig.browser.json",
"compilerOptions": {
"incremental": true,
"outDir": "./target/web",
"outDir": "./target_web",
"stripInternal": true,
"declaration": false,
"isolatedModules": true,
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-analytics/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"incremental": true,
"declarationDir": "./target/types",
"outDir": "./target/node",
"declarationDir": "./target_types",
"outDir": "./target_node",
"stripInternal": true,
"declaration": true,
"declarationMap": true,
Expand Down
2 changes: 2 additions & 0 deletions packages/kbn-config/src/config_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ const createConfigServiceMock = ({
addDeprecationProvider: jest.fn(),
validate: jest.fn(),
getHandledDeprecatedConfigs: jest.fn(),
getDeprecatedConfigPath$: jest.fn(),
};

mocked.atPath.mockReturnValue(new BehaviorSubject(atPath));
mocked.atPathSync.mockReturnValue(atPath);
mocked.getConfig$.mockReturnValue(new BehaviorSubject(new ObjectToConfigAdapter(getConfig$)));
mocked.getDeprecatedConfigPath$.mockReturnValue(new BehaviorSubject({ set: [], unset: [] }));
mocked.getUsedPaths.mockResolvedValue([]);
mocked.getUnusedPaths.mockResolvedValue([]);
mocked.isEnabledAtPath.mockResolvedValue(true);
Expand Down
11 changes: 9 additions & 2 deletions packages/kbn-config/src/config_service.test.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@ import type { applyDeprecations } from './deprecation/apply_deprecations';

jest.mock('../../../package.json', () => mockPackage);

const changedPaths = {
set: ['foo'],
unset: ['bar.baz'],
};

export { changedPaths as mockedChangedPaths };

export const mockApplyDeprecations = jest.fn<
Record<string, any>,
ReturnType<typeof applyDeprecations>,
Parameters<typeof applyDeprecations>
>((config, deprecations, createAddDeprecation) => config);
>((config, deprecations, createAddDeprecation) => ({ config, changedPaths }));

jest.mock('./deprecation/apply_deprecations', () => ({
applyDeprecations: mockApplyDeprecations,
Expand Down
25 changes: 20 additions & 5 deletions packages/kbn-config/src/config_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { BehaviorSubject, Observable } from 'rxjs';
import { first, take } from 'rxjs/operators';

import { mockApplyDeprecations } from './config_service.test.mocks';
import { mockApplyDeprecations, mockedChangedPaths } from './config_service.test.mocks';
import { rawConfigServiceMock } from './raw/raw_config_service.mock';

import { schema } from '@kbn/config-schema';
Expand Down Expand Up @@ -420,7 +420,7 @@ test('logs deprecation warning during validation', async () => {
const addDeprecation = createAddDeprecation!('');
addDeprecation({ message: 'some deprecation message' });
addDeprecation({ message: 'another deprecation message' });
return config;
return { config, changedPaths: mockedChangedPaths };
});

loggerMock.clear(logger);
Expand All @@ -446,12 +446,12 @@ test('does not log warnings for silent deprecations during validation', async ()
const addDeprecation = createAddDeprecation!('');
addDeprecation({ message: 'some deprecation message', silent: true });
addDeprecation({ message: 'another deprecation message' });
return config;
return { config, changedPaths: mockedChangedPaths };
})
.mockImplementationOnce((config, deprecations, createAddDeprecation) => {
const addDeprecation = createAddDeprecation!('');
addDeprecation({ message: 'I am silent', silent: true });
return config;
return { config, changedPaths: mockedChangedPaths };
});

loggerMock.clear(logger);
Expand Down Expand Up @@ -521,7 +521,7 @@ describe('getHandledDeprecatedConfigs', () => {
const addDeprecation = createAddDeprecation!(deprecation.path);
addDeprecation({ message: `some deprecation message`, documentationUrl: 'some-url' });
});
return config;
return { config, changedPaths: mockedChangedPaths };
});

await configService.validate();
Expand All @@ -541,3 +541,18 @@ describe('getHandledDeprecatedConfigs', () => {
`);
});
});

describe('getDeprecatedConfigPath$', () => {
it('returns all config paths changes during deprecation', async () => {
const rawConfig$ = new BehaviorSubject<Record<string, any>>({ key: 'value' });
const rawConfigProvider = rawConfigServiceMock.create({ rawConfig$ });

const configService = new ConfigService(rawConfigProvider, defaultEnv, logger);
await configService.setSchema('key', schema.string());
await configService.validate();

const deprecatedConfigPath$ = configService.getDeprecatedConfigPath$();
const deprecatedConfigPath = await deprecatedConfigPath$.pipe(first()).toPromise();
expect(deprecatedConfigPath).toEqual(mockedChangedPaths);
});
});
12 changes: 11 additions & 1 deletion packages/kbn-config/src/config_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
ConfigDeprecationProvider,
configDeprecationFactory,
DeprecatedConfigDetails,
ChangedDeprecatedPaths,
} from './deprecation';
import { LegacyObjectToConfigAdapter } from './legacy';

Expand All @@ -36,6 +37,10 @@ export class ConfigService {
private validated = false;
private readonly config$: Observable<Config>;
private lastConfig?: Config;
private readonly deprecatedConfigPaths = new BehaviorSubject<ChangedDeprecatedPaths>({
set: [],
unset: [],
});

/**
* Whenever a config if read at a path, we mark that path as 'handled'. We can
Expand All @@ -57,7 +62,8 @@ export class ConfigService {
this.config$ = combineLatest([this.rawConfigProvider.getConfig$(), this.deprecations]).pipe(
map(([rawConfig, deprecations]) => {
const migrated = applyDeprecations(rawConfig, deprecations);
return new LegacyObjectToConfigAdapter(migrated);
this.deprecatedConfigPaths.next(migrated.changedPaths);
return new LegacyObjectToConfigAdapter(migrated.config);
}),
tap((config) => {
this.lastConfig = config;
Expand Down Expand Up @@ -191,6 +197,10 @@ export class ConfigService {
return config.getFlattenedPaths().filter((path) => isPathHandled(path, handledPaths));
}

public getDeprecatedConfigPath$() {
return this.deprecatedConfigPaths.asObservable();
}

private async logDeprecation() {
const rawConfig = await this.rawConfigProvider.getConfig$().pipe(take(1)).toPromise();
const deprecations = await this.deprecations.pipe(take(1)).toPromise();
Expand Down
29 changes: 25 additions & 4 deletions packages/kbn-config/src/deprecation/apply_deprecations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('applyDeprecations', () => {
it('returns the migrated config', () => {
const initialConfig = { foo: 'bar', deprecated: 'deprecated', renamed: 'renamed' };

const migrated = applyDeprecations(initialConfig, [
const { config: migrated } = applyDeprecations(initialConfig, [
wrapHandler(deprecations.unused('deprecated')),
wrapHandler(deprecations.rename('renamed', 'newname')),
]);
Expand All @@ -93,7 +93,7 @@ describe('applyDeprecations', () => {
it('does not alter the initial config', () => {
const initialConfig = { foo: 'bar', deprecated: 'deprecated' };

const migrated = applyDeprecations(initialConfig, [
const { config: migrated } = applyDeprecations(initialConfig, [
wrapHandler(deprecations.unused('deprecated')),
]);

Expand All @@ -110,7 +110,7 @@ describe('applyDeprecations', () => {
return { unset: [{ path: 'unknown' }] };
});

const migrated = applyDeprecations(
const { config: migrated } = applyDeprecations(
initialConfig,
[wrapHandler(handler, 'pathA')],
createAddDeprecation
Expand All @@ -128,12 +128,33 @@ describe('applyDeprecations', () => {
return { rewrite: [{ path: 'foo' }] };
});

const migrated = applyDeprecations(
const { config: migrated } = applyDeprecations(
initialConfig,
[wrapHandler(handler, 'pathA')],
createAddDeprecation
);

expect(migrated).toEqual(initialConfig);
});

it('returns a list of changes config paths', () => {
const addDeprecation = jest.fn();
const createAddDeprecation = jest.fn().mockReturnValue(addDeprecation);
const initialConfig = { foo: 'bar', deprecated: 'deprecated' };

const handler = jest.fn().mockImplementation((config) => {
return { set: [{ path: 'foo', value: 'bar' }], unset: [{ path: 'baz' }] };
});

const { changedPaths } = applyDeprecations(
initialConfig,
[wrapHandler(handler, 'pathA')],
createAddDeprecation
);

expect(changedPaths).toEqual({
set: ['foo'],
unset: ['baz'],
});
});
});
19 changes: 16 additions & 3 deletions packages/kbn-config/src/deprecation/apply_deprecations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

import { cloneDeep, unset } from 'lodash';
import { set } from '@elastic/safer-lodash-set';
import { ConfigDeprecationWithContext, AddConfigDeprecation } from './types';
import type {
AddConfigDeprecation,
ChangedDeprecatedPaths,
ConfigDeprecationWithContext,
} from './types';

const noopAddDeprecationFactory: () => AddConfigDeprecation = () => () => undefined;
/**
Expand All @@ -22,22 +26,31 @@ export const applyDeprecations = (
config: Record<string, any>,
deprecations: ConfigDeprecationWithContext[],
createAddDeprecation: (pluginId: string) => AddConfigDeprecation = noopAddDeprecationFactory
) => {
): { config: Record<string, any>; changedPaths: ChangedDeprecatedPaths } => {
const result = cloneDeep(config);
const changedPaths: ChangedDeprecatedPaths = {
set: [],
unset: [],
};
deprecations.forEach(({ deprecation, path }) => {
const commands = deprecation(result, path, createAddDeprecation(path));
if (commands) {
if (commands.set) {
changedPaths.set.push(...commands.set.map((c) => c.path));
commands.set.forEach(function ({ path: commandPath, value }) {
set(result, commandPath, value);
});
}
if (commands.unset) {
changedPaths.unset.push(...commands.unset.map((c) => c.path));
commands.unset.forEach(function ({ path: commandPath }) {
unset(result, commandPath);
});
}
}
});
return result;
return {
config: result,
changedPaths,
};
};
1 change: 1 addition & 0 deletions packages/kbn-config/src/deprecation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type {
AddConfigDeprecation,
ConfigDeprecationProvider,
DeprecatedConfigDetails,
ChangedDeprecatedPaths,
} from './types';
export { configDeprecationFactory } from './deprecation_factory';
export { applyDeprecations } from './apply_deprecations';
10 changes: 10 additions & 0 deletions packages/kbn-config/src/deprecation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ export type ConfigDeprecation = (
addDeprecation: AddConfigDeprecation
) => void | ConfigDeprecationCommand;

/**
* List of config paths changed during deprecation.
*
* @public
*/
export interface ChangedDeprecatedPaths {
set: string[];
unset: string[];
}

/**
* Outcome of deprecation operation. Allows mutating config values in a declarative way.
*
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type {
ConfigDeprecationWithContext,
ConfigDeprecation,
ConfigDeprecationCommand,
ChangedDeprecatedPaths,
} from './deprecation';

export { applyDeprecations, configDeprecationFactory } from './deprecation';
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pageLoadAssetSize:
tileMap: 65337
timelion: 29920
transform: 41007
triggersActionsUi: 186732
triggersActionsUi: 100000
uiActions: 97717
uiActionsEnhanced: 313011
upgradeAssistant: 81241
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/config/test_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function collectDeprecations(
) {
const deprecations = provider(configDeprecationFactory);
const deprecationMessages: string[] = [];
const migrated = applyDeprecations(
const { config: migrated } = applyDeprecations(
settings,
deprecations.map((deprecation) => ({
deprecation,
Expand Down
Loading

0 comments on commit 98c5e36

Please sign in to comment.