mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
expose docLinks from ConfigDeprecationContext (#132424)
* expose docLinks from ConfigDeprecationContext * fix mock * [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix' Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
f75b6fa156
commit
569e10a6b8
7 changed files with 42 additions and 9 deletions
|
@ -38,6 +38,7 @@ RUNTIME_DEPS = [
|
|||
"//packages/kbn-utility-types",
|
||||
"//packages/kbn-i18n",
|
||||
"//packages/kbn-plugin-discovery",
|
||||
"//packages/kbn-doc-links",
|
||||
"@npm//js-yaml",
|
||||
"@npm//load-json-file",
|
||||
"@npm//lodash",
|
||||
|
@ -54,6 +55,7 @@ TYPES_DEPS = [
|
|||
"//packages/kbn-utility-types:npm_module_types",
|
||||
"//packages/kbn-i18n:npm_module_types",
|
||||
"//packages/kbn-plugin-discovery:npm_module_types",
|
||||
"//packages/kbn-doc-links:npm_module_types",
|
||||
"@npm//load-json-file",
|
||||
"@npm//rxjs",
|
||||
"@npm//@types/jest",
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import type { DocLinks } from '@kbn/doc-links';
|
||||
|
||||
export const mockPackage = new Proxy({ raw: {} as any }, { get: (obj, prop) => obj.raw[prop] });
|
||||
import type { applyDeprecations } from './deprecation/apply_deprecations';
|
||||
|
||||
|
@ -26,3 +28,12 @@ export const mockApplyDeprecations = jest.fn<
|
|||
jest.mock('./deprecation/apply_deprecations', () => ({
|
||||
applyDeprecations: mockApplyDeprecations,
|
||||
}));
|
||||
|
||||
export const docLinksMock = {
|
||||
settings: 'settings',
|
||||
} as DocLinks;
|
||||
export const getDocLinksMock = jest.fn().mockReturnValue(docLinksMock);
|
||||
|
||||
jest.doMock('@kbn/doc-links', () => ({
|
||||
getDocLinks: getDocLinksMock,
|
||||
}));
|
||||
|
|
|
@ -9,7 +9,12 @@
|
|||
import { BehaviorSubject, Observable } from 'rxjs';
|
||||
import { first, take } from 'rxjs/operators';
|
||||
|
||||
import { mockApplyDeprecations, mockedChangedPaths } from './config_service.test.mocks';
|
||||
import {
|
||||
mockApplyDeprecations,
|
||||
mockedChangedPaths,
|
||||
docLinksMock,
|
||||
getDocLinksMock,
|
||||
} from './config_service.test.mocks';
|
||||
import { rawConfigServiceMock } from './raw/raw_config_service.mock';
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
|
@ -39,6 +44,7 @@ const getRawConfigProvider = (rawConfig: Record<string, any>) =>
|
|||
beforeEach(() => {
|
||||
logger = loggerMock.create();
|
||||
mockApplyDeprecations.mockClear();
|
||||
getDocLinksMock.mockClear();
|
||||
});
|
||||
|
||||
test('returns config at path as observable', async () => {
|
||||
|
@ -469,6 +475,7 @@ test('calls `applyDeprecations` with the correct parameters', async () => {
|
|||
const context: ConfigDeprecationContext = {
|
||||
branch: defaultEnv.packageInfo.branch,
|
||||
version: defaultEnv.packageInfo.version,
|
||||
docLinks: docLinksMock,
|
||||
};
|
||||
|
||||
const deprecationA = jest.fn();
|
||||
|
@ -479,6 +486,8 @@ test('calls `applyDeprecations` with the correct parameters', async () => {
|
|||
|
||||
await configService.validate();
|
||||
|
||||
expect(getDocLinksMock).toHaveBeenCalledTimes(1);
|
||||
|
||||
expect(mockApplyDeprecations).toHaveBeenCalledTimes(1);
|
||||
expect(mockApplyDeprecations).toHaveBeenCalledWith(
|
||||
cfg,
|
||||
|
|
|
@ -12,6 +12,7 @@ import { isEqual } from 'lodash';
|
|||
import { BehaviorSubject, combineLatest, firstValueFrom, Observable } from 'rxjs';
|
||||
import { distinctUntilChanged, first, map, shareReplay, tap } from 'rxjs/operators';
|
||||
import { Logger, LoggerFactory } from '@kbn/logging';
|
||||
import { getDocLinks, DocLinks } from '@kbn/doc-links';
|
||||
|
||||
import { Config, ConfigPath, Env } from '.';
|
||||
import { hasConfigPathIntersection } from './config';
|
||||
|
@ -42,6 +43,7 @@ export interface ConfigValidateParameters {
|
|||
export class ConfigService {
|
||||
private readonly log: Logger;
|
||||
private readonly deprecationLog: Logger;
|
||||
private readonly docLinks: DocLinks;
|
||||
|
||||
private validated = false;
|
||||
private readonly config$: Observable<Config>;
|
||||
|
@ -67,6 +69,7 @@ export class ConfigService {
|
|||
) {
|
||||
this.log = logger.get('config');
|
||||
this.deprecationLog = logger.get('config', 'deprecation');
|
||||
this.docLinks = getDocLinks({ kibanaBranch: env.packageInfo.branch });
|
||||
|
||||
this.config$ = combineLatest([this.rawConfigProvider.getConfig$(), this.deprecations]).pipe(
|
||||
map(([rawConfig, deprecations]) => {
|
||||
|
@ -104,7 +107,7 @@ export class ConfigService {
|
|||
...provider(configDeprecationFactory).map((deprecation) => ({
|
||||
deprecation,
|
||||
path: flatPath,
|
||||
context: createDeprecationContext(this.env),
|
||||
context: this.createDeprecationContext(),
|
||||
})),
|
||||
]);
|
||||
}
|
||||
|
@ -262,6 +265,14 @@ export class ConfigService {
|
|||
handledDeprecatedConfig.push(config);
|
||||
this.handledDeprecatedConfigs.set(domainId, handledDeprecatedConfig);
|
||||
}
|
||||
|
||||
private createDeprecationContext(): ConfigDeprecationContext {
|
||||
return {
|
||||
branch: this.env.packageInfo.branch,
|
||||
version: this.env.packageInfo.version,
|
||||
docLinks: this.docLinks,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const pathToString = (path: ConfigPath) => (Array.isArray(path) ? path.join('.') : path);
|
||||
|
@ -272,10 +283,3 @@ const pathToString = (path: ConfigPath) => (Array.isArray(path) ? path.join('.')
|
|||
*/
|
||||
const isPathHandled = (path: string, handledPaths: string[]) =>
|
||||
handledPaths.some((handledPath) => hasConfigPathIntersection(path, handledPath));
|
||||
|
||||
const createDeprecationContext = (env: Env): ConfigDeprecationContext => {
|
||||
return {
|
||||
branch: env.packageInfo.branch,
|
||||
version: env.packageInfo.version,
|
||||
};
|
||||
};
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import type { DocLinks } from '@kbn/doc-links';
|
||||
import { applyDeprecations } from './apply_deprecations';
|
||||
import { ConfigDeprecation, ConfigDeprecationContext, ConfigDeprecationWithContext } from './types';
|
||||
import { configDeprecationFactory as deprecations } from './deprecation_factory';
|
||||
|
@ -14,6 +15,7 @@ describe('applyDeprecations', () => {
|
|||
const context: ConfigDeprecationContext = {
|
||||
version: '7.16.2',
|
||||
branch: '7.16',
|
||||
docLinks: {} as DocLinks,
|
||||
};
|
||||
|
||||
const wrapHandler = (
|
||||
|
|
|
@ -6,12 +6,14 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import type { DocLinks } from '@kbn/doc-links';
|
||||
import type { ConfigDeprecationContext } from './types';
|
||||
|
||||
const createMockedContext = (): ConfigDeprecationContext => {
|
||||
return {
|
||||
branch: 'master',
|
||||
version: '8.0.0',
|
||||
docLinks: {} as DocLinks,
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
import type { RecursiveReadonly } from '@kbn/utility-types';
|
||||
import type { DocLinks } from '@kbn/doc-links';
|
||||
|
||||
/**
|
||||
* Config deprecation hook used when invoking a {@link ConfigDeprecation}
|
||||
|
@ -77,6 +78,8 @@ export interface ConfigDeprecationContext {
|
|||
version: string;
|
||||
/** The current Kibana branch, e.g `7.x`, `7.16`, `master` */
|
||||
branch: string;
|
||||
/** Allow direct access to the doc links from the deprecation handler */
|
||||
docLinks: DocLinks;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue