diff --git a/packages/kbn-config/BUILD.bazel b/packages/kbn-config/BUILD.bazel index 3567c549a77c4..e735e2cb346eb 100644 --- a/packages/kbn-config/BUILD.bazel +++ b/packages/kbn-config/BUILD.bazel @@ -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", diff --git a/packages/kbn-config/src/config_service.test.mocks.ts b/packages/kbn-config/src/config_service.test.mocks.ts index 39aa551ae85f9..40379e69a3cb2 100644 --- a/packages/kbn-config/src/config_service.test.mocks.ts +++ b/packages/kbn-config/src/config_service.test.mocks.ts @@ -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, +})); diff --git a/packages/kbn-config/src/config_service.test.ts b/packages/kbn-config/src/config_service.test.ts index 51e67956637ee..b427af4e50229 100644 --- a/packages/kbn-config/src/config_service.test.ts +++ b/packages/kbn-config/src/config_service.test.ts @@ -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) => 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, diff --git a/packages/kbn-config/src/config_service.ts b/packages/kbn-config/src/config_service.ts index bb7bb54e75ce5..0da30aad0e232 100644 --- a/packages/kbn-config/src/config_service.ts +++ b/packages/kbn-config/src/config_service.ts @@ -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; @@ -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, - }; -}; diff --git a/packages/kbn-config/src/deprecation/apply_deprecations.test.ts b/packages/kbn-config/src/deprecation/apply_deprecations.test.ts index 5acf725ba93a6..73e7b2b422017 100644 --- a/packages/kbn-config/src/deprecation/apply_deprecations.test.ts +++ b/packages/kbn-config/src/deprecation/apply_deprecations.test.ts @@ -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 = ( diff --git a/packages/kbn-config/src/deprecation/deprecations.mock.ts b/packages/kbn-config/src/deprecation/deprecations.mock.ts index 80b65c84b4879..06b467290b47e 100644 --- a/packages/kbn-config/src/deprecation/deprecations.mock.ts +++ b/packages/kbn-config/src/deprecation/deprecations.mock.ts @@ -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, }; }; diff --git a/packages/kbn-config/src/deprecation/types.ts b/packages/kbn-config/src/deprecation/types.ts index 052741c0b4be3..6d656ab97921f 100644 --- a/packages/kbn-config/src/deprecation/types.ts +++ b/packages/kbn-config/src/deprecation/types.ts @@ -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; } /**