From 25ca8a760516d01e7321fe71b4fa14f6a3394b3d Mon Sep 17 00:00:00 2001 From: chrisronline Date: Fri, 5 Jun 2020 11:00:45 -0400 Subject: [PATCH 1/7] Ensure we use existing Elasticsearch config --- .../plugins/monitoring/server/config.test.ts | 157 +++++++++++++++ x-pack/plugins/monitoring/server/config.ts | 179 ++---------------- x-pack/plugins/monitoring/server/plugin.ts | 9 +- 3 files changed, 183 insertions(+), 162 deletions(-) create mode 100644 x-pack/plugins/monitoring/server/config.test.ts diff --git a/x-pack/plugins/monitoring/server/config.test.ts b/x-pack/plugins/monitoring/server/config.test.ts new file mode 100644 index 0000000000000..17140b7ce6fa2 --- /dev/null +++ b/x-pack/plugins/monitoring/server/config.test.ts @@ -0,0 +1,157 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ +import { createConfig, configSchema } from './config'; + +describe('config schema', () => { + it('generates proper defaults', () => { + expect(configSchema.validate({})).toMatchInlineSnapshot(` + Object { + "agent": Object { + "interval": "10s", + }, + "cluster_alerts": Object { + "email_notifications": Object { + "email_address": "", + "enabled": true, + }, + "enabled": true, + }, + "elasticsearch": Object { + "apiVersion": "master", + "customHeaders": Object {}, + "healthCheck": Object { + "delay": "PT2.5S", + }, + "ignoreVersionMismatch": false, + "logFetchCount": 10, + "logQueries": false, + "pingTimeout": "PT30S", + "preserveHost": true, + "requestHeadersWhitelist": Array [ + "authorization", + ], + "requestTimeout": "PT30S", + "shardTimeout": "PT30S", + "sniffInterval": false, + "sniffOnConnectionFault": false, + "sniffOnStart": false, + "ssl": Object { + "alwaysPresentCertificate": false, + "keystore": Object {}, + "truststore": Object {}, + "verificationMode": "full", + }, + "startupTimeout": "PT5S", + }, + "enabled": true, + "kibana": Object { + "collection": Object { + "enabled": true, + "interval": 10000, + }, + }, + "licensing": Object { + "api_polling_frequency": "PT30S", + }, + "tests": Object { + "cloud_detector": Object { + "enabled": true, + }, + }, + "ui": Object { + "ccs": Object { + "enabled": true, + }, + "container": Object { + "elasticsearch": Object { + "enabled": false, + }, + "logstash": Object { + "enabled": false, + }, + }, + "elasticsearch": Object { + "apiVersion": "master", + "customHeaders": Object {}, + "healthCheck": Object { + "delay": "PT2.5S", + }, + "ignoreVersionMismatch": false, + "logFetchCount": 10, + "logQueries": false, + "pingTimeout": "PT30S", + "preserveHost": true, + "requestHeadersWhitelist": Array [ + "authorization", + ], + "requestTimeout": "PT30S", + "shardTimeout": "PT30S", + "sniffInterval": false, + "sniffOnConnectionFault": false, + "sniffOnStart": false, + "ssl": Object { + "alwaysPresentCertificate": false, + "keystore": Object {}, + "truststore": Object {}, + "verificationMode": "full", + }, + "startupTimeout": "PT5S", + }, + "enabled": true, + "logs": Object { + "index": "filebeat-*", + }, + "max_bucket_size": 10000, + "min_interval_seconds": 10, + "show_license_expiration": true, + }, + } + `); + }); +}); + +describe('createConfig()', () => { + it('should wrap in Elasticsearch config', async () => { + const config = createConfig( + configSchema.validate({ + elasticsearch: { + hosts: 'http://localhost:9200', + }, + ui: { + elasticsearch: { + hosts: 'http://localhost:9200', + }, + }, + }) + ); + expect(config.elasticsearch.hosts).toEqual(['http://localhost:9200']); + expect(config.ui.elasticsearch.hosts).toEqual(['http://localhost:9200']); + }); + + it('should attempt to read ssl files', async () => { + let error; + try { + createConfig( + configSchema.validate({ + ui: { + elasticsearch: { + hosts: 'http://localhost:9200', + ssl: { + certificate: 'packages/kbn-dev-utils/certs/elasticsearch.crt', + key: 'packages/kbn-dev-utils/certs/elasticsearch.key', + certificateAuthorities: 'packages/kbn-dev-utils/certs/ca.crt', + verificationMode: 'full', + }, + }, + }, + }) + ); + } catch (err) { + error = err.message; + } + expect(error.includes('no such file or directory')).toBe(true); + }); +}); diff --git a/x-pack/plugins/monitoring/server/config.ts b/x-pack/plugins/monitoring/server/config.ts index a1eddee725e90..01c3761d19de6 100644 --- a/x-pack/plugins/monitoring/server/config.ts +++ b/x-pack/plugins/monitoring/server/config.ts @@ -4,91 +4,23 @@ * you may not use this file except in compliance with the Elastic License. */ import { schema, TypeOf } from '@kbn/config-schema'; +import { + configSchema as elasticsearchConfigSchema, + ElasticsearchConfig, + // eslint-disable-next-line @kbn/eslint/no-restricted-paths +} from '../../../../src/core/server/elasticsearch'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { ElasticsearchConfigType } from '../../../../src/core/server/elasticsearch/elasticsearch_config'; const hostURISchema = schema.uri({ scheme: ['http', 'https'] }); -const DEFAULT_API_VERSION = 'master'; export const configSchema = schema.object({ enabled: schema.boolean({ defaultValue: true }), - elasticsearch: schema.object({ + elasticsearch: elasticsearchConfigSchema.extends({ logFetchCount: schema.number({ defaultValue: 10 }), - sniffOnStart: schema.boolean({ defaultValue: false }), - sniffInterval: schema.oneOf([schema.duration(), schema.literal(false)], { - defaultValue: false, - }), - sniffOnConnectionFault: schema.boolean({ defaultValue: false }), hosts: schema.maybe( schema.oneOf([hostURISchema, schema.arrayOf(hostURISchema, { minSize: 1 })]) ), - preserveHost: schema.boolean({ defaultValue: true }), - username: schema.maybe( - schema.conditional( - schema.contextRef('dist'), - false, - schema.string({ - validate: () => {}, - }), - schema.string() - ) - ), - password: schema.maybe(schema.string()), - requestHeadersWhitelist: schema.oneOf([schema.string(), schema.arrayOf(schema.string())], { - defaultValue: ['authorization'], - }), - customHeaders: schema.recordOf(schema.string(), schema.string(), { defaultValue: {} }), - shardTimeout: schema.duration({ defaultValue: '30s' }), - requestTimeout: schema.duration({ defaultValue: '30s' }), - pingTimeout: schema.duration({ defaultValue: schema.siblingRef('requestTimeout') }), - startupTimeout: schema.duration({ defaultValue: '5s' }), - logQueries: schema.boolean({ defaultValue: false }), - ssl: schema.object( - { - verificationMode: schema.oneOf( - [schema.literal('none'), schema.literal('certificate'), schema.literal('full')], - { defaultValue: 'full' } - ), - certificateAuthorities: schema.maybe( - schema.oneOf([schema.string(), schema.arrayOf(schema.string(), { minSize: 1 })]) - ), - certificate: schema.maybe(schema.string()), - key: schema.maybe(schema.string()), - keyPassphrase: schema.maybe(schema.string()), - keystore: schema.object({ - path: schema.maybe(schema.string()), - password: schema.maybe(schema.string()), - }), - truststore: schema.object({ - path: schema.maybe(schema.string()), - password: schema.maybe(schema.string()), - }), - alwaysPresentCertificate: schema.boolean({ defaultValue: false }), - }, - { - validate: (rawConfig) => { - if (rawConfig.key && rawConfig.keystore.path) { - return 'cannot use [key] when [keystore.path] is specified'; - } - if (rawConfig.certificate && rawConfig.keystore.path) { - return 'cannot use [certificate] when [keystore.path] is specified'; - } - }, - } - ), - apiVersion: schema.string({ defaultValue: DEFAULT_API_VERSION }), - healthCheck: schema.object({ delay: schema.duration({ defaultValue: 2500 }) }), - ignoreVersionMismatch: schema.conditional( - schema.contextRef('dev'), - false, - schema.boolean({ - validate: (rawValue) => { - if (rawValue === true) { - return '"ignoreVersionMismatch" can only be set to true in development mode'; - } - }, - defaultValue: false, - }), - schema.boolean({ defaultValue: false }) - ), }), ui: schema.object({ enabled: schema.boolean({ defaultValue: true }), @@ -99,92 +31,11 @@ export const configSchema = schema.object({ index: schema.string({ defaultValue: 'filebeat-*' }), }), max_bucket_size: schema.number({ defaultValue: 10000 }), - elasticsearch: schema.object({ + elasticsearch: elasticsearchConfigSchema.extends({ logFetchCount: schema.number({ defaultValue: 10 }), - sniffOnStart: schema.boolean({ defaultValue: false }), - sniffInterval: schema.oneOf([schema.duration(), schema.literal(false)], { - defaultValue: false, - }), - sniffOnConnectionFault: schema.boolean({ defaultValue: false }), hosts: schema.maybe( schema.oneOf([hostURISchema, schema.arrayOf(hostURISchema, { minSize: 1 })]) ), - preserveHost: schema.boolean({ defaultValue: true }), - username: schema.maybe( - schema.conditional( - schema.contextRef('dist'), - false, - schema.string({ - validate: (rawConfig) => { - if (rawConfig === 'elastic') { - return ( - 'value of "elastic" is forbidden. This is a superuser account that can obfuscate ' + - 'privilege-related issues. You should use the "kibana_system" user instead.' - ); - } - }, - }), - schema.string() - ) - ), - password: schema.maybe(schema.string()), - requestHeadersWhitelist: schema.oneOf([schema.string(), schema.arrayOf(schema.string())], { - defaultValue: ['authorization'], - }), - customHeaders: schema.recordOf(schema.string(), schema.string(), { defaultValue: {} }), - shardTimeout: schema.duration({ defaultValue: '30s' }), - requestTimeout: schema.duration({ defaultValue: '30s' }), - pingTimeout: schema.duration({ defaultValue: schema.siblingRef('requestTimeout') }), - startupTimeout: schema.duration({ defaultValue: '5s' }), - logQueries: schema.boolean({ defaultValue: false }), - ssl: schema.object( - { - verificationMode: schema.oneOf( - [schema.literal('none'), schema.literal('certificate'), schema.literal('full')], - { defaultValue: 'full' } - ), - certificateAuthorities: schema.maybe( - schema.oneOf([schema.string(), schema.arrayOf(schema.string(), { minSize: 1 })]) - ), - certificate: schema.maybe(schema.string()), - key: schema.maybe(schema.string()), - keyPassphrase: schema.maybe(schema.string()), - keystore: schema.object({ - path: schema.maybe(schema.string()), - password: schema.maybe(schema.string()), - }), - truststore: schema.object({ - path: schema.maybe(schema.string()), - password: schema.maybe(schema.string()), - }), - alwaysPresentCertificate: schema.boolean({ defaultValue: false }), - }, - { - validate: (rawConfig) => { - if (rawConfig.key && rawConfig.keystore.path) { - return 'cannot use [key] when [keystore.path] is specified'; - } - if (rawConfig.certificate && rawConfig.keystore.path) { - return 'cannot use [certificate] when [keystore.path] is specified'; - } - }, - } - ), - apiVersion: schema.string({ defaultValue: DEFAULT_API_VERSION }), - healthCheck: schema.object({ delay: schema.duration({ defaultValue: 2500 }) }), - ignoreVersionMismatch: schema.conditional( - schema.contextRef('dev'), - false, - schema.boolean({ - validate: (rawValue) => { - if (rawValue === true) { - return '"ignoreVersionMismatch" can only be set to true in development mode'; - } - }, - defaultValue: false, - }), - schema.boolean({ defaultValue: false }) - ), }), container: schema.object({ elasticsearch: schema.object({ @@ -227,4 +78,14 @@ export const configSchema = schema.object({ }), }); -export type MonitoringConfig = TypeOf; +export type MonitoringConfig = ReturnType; +export function createConfig(config: TypeOf) { + return { + ...config, + elasticsearch: new ElasticsearchConfig(config.elasticsearch as ElasticsearchConfigType), + ui: { + ...config.ui, + elasticsearch: new ElasticsearchConfig(config.ui.elasticsearch as ElasticsearchConfigType), + }, + }; +} diff --git a/x-pack/plugins/monitoring/server/plugin.ts b/x-pack/plugins/monitoring/server/plugin.ts index f4f38f70b1ccb..881d0080ab789 100644 --- a/x-pack/plugins/monitoring/server/plugin.ts +++ b/x-pack/plugins/monitoring/server/plugin.ts @@ -5,9 +5,10 @@ */ import Boom from 'boom'; import { combineLatest } from 'rxjs'; -import { first } from 'rxjs/operators'; +import { first, map } from 'rxjs/operators'; import { i18n } from '@kbn/i18n'; import { has, get } from 'lodash'; +import { TypeOf } from '@kbn/config-schema'; import { UsageCollectionSetup } from 'src/plugins/usage_collection/server'; import { TelemetryCollectionManagerPluginSetup } from 'src/plugins/telemetry_collection_manager/server'; import { @@ -30,7 +31,7 @@ import { KIBANA_ALERTING_ENABLED, KIBANA_STATS_TYPE_MONITORING, } from '../common/constants'; -import { MonitoringConfig } from './config'; +import { MonitoringConfig, createConfig, configSchema } from './config'; // @ts-ignore import { requireUIRoutes } from './routes'; // @ts-ignore @@ -122,7 +123,9 @@ export class Plugin { async setup(core: CoreSetup, plugins: PluginsSetup) { const [config, legacyConfig] = await combineLatest([ - this.initializerContext.config.create(), + this.initializerContext.config + .create>() + .pipe(map((rawConfig) => createConfig(rawConfig))), this.initializerContext.config.legacy.globalConfig$, ]) .pipe(first()) From 5d920ff104f682ca33a44d7a7267ff2d0f0698d5 Mon Sep 17 00:00:00 2001 From: chrisronline Date: Fri, 5 Jun 2020 14:00:38 -0400 Subject: [PATCH 2/7] Use separate type for this to ensure custom properties work --- x-pack/plugins/monitoring/server/config.ts | 32 ++++++++++++---------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/x-pack/plugins/monitoring/server/config.ts b/x-pack/plugins/monitoring/server/config.ts index 01c3761d19de6..c38884be61789 100644 --- a/x-pack/plugins/monitoring/server/config.ts +++ b/x-pack/plugins/monitoring/server/config.ts @@ -14,14 +14,14 @@ import { ElasticsearchConfigType } from '../../../../src/core/server/elasticsear const hostURISchema = schema.uri({ scheme: ['http', 'https'] }); +const monitoringElasticsearchConfigSchema = elasticsearchConfigSchema.extends({ + logFetchCount: schema.number({ defaultValue: 10 }), + hosts: schema.maybe(schema.oneOf([hostURISchema, schema.arrayOf(hostURISchema, { minSize: 1 })])), +}); + export const configSchema = schema.object({ enabled: schema.boolean({ defaultValue: true }), - elasticsearch: elasticsearchConfigSchema.extends({ - logFetchCount: schema.number({ defaultValue: 10 }), - hosts: schema.maybe( - schema.oneOf([hostURISchema, schema.arrayOf(hostURISchema, { minSize: 1 })]) - ), - }), + elasticsearch: monitoringElasticsearchConfigSchema, ui: schema.object({ enabled: schema.boolean({ defaultValue: true }), ccs: schema.object({ @@ -31,12 +31,7 @@ export const configSchema = schema.object({ index: schema.string({ defaultValue: 'filebeat-*' }), }), max_bucket_size: schema.number({ defaultValue: 10000 }), - elasticsearch: elasticsearchConfigSchema.extends({ - logFetchCount: schema.number({ defaultValue: 10 }), - hosts: schema.maybe( - schema.oneOf([hostURISchema, schema.arrayOf(hostURISchema, { minSize: 1 })]) - ), - }), + elasticsearch: monitoringElasticsearchConfigSchema, container: schema.object({ elasticsearch: schema.object({ enabled: schema.boolean({ defaultValue: false }), @@ -78,14 +73,23 @@ export const configSchema = schema.object({ }), }); +class MonitoringElasticsearchConfig extends ElasticsearchConfig { + public readonly logFetchCount?: number; + + constructor(rawConfig: TypeOf) { + super(rawConfig as ElasticsearchConfigType); + this.logFetchCount = rawConfig.logFetchCount; + } +} + export type MonitoringConfig = ReturnType; export function createConfig(config: TypeOf) { return { ...config, - elasticsearch: new ElasticsearchConfig(config.elasticsearch as ElasticsearchConfigType), + elasticsearch: new MonitoringElasticsearchConfig(config.elasticsearch), ui: { ...config.ui, - elasticsearch: new ElasticsearchConfig(config.ui.elasticsearch as ElasticsearchConfigType), + elasticsearch: new MonitoringElasticsearchConfig(config.ui.elasticsearch), }, }; } From 94046b97f459b41d3578a40d564bdf8c54386c08 Mon Sep 17 00:00:00 2001 From: chrisronline Date: Mon, 8 Jun 2020 10:07:26 -0400 Subject: [PATCH 3/7] PR suggestions --- .../plugins/monitoring/server/config.test.ts | 49 +++++++++++-------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/x-pack/plugins/monitoring/server/config.test.ts b/x-pack/plugins/monitoring/server/config.test.ts index 17140b7ce6fa2..6a57f667312c6 100644 --- a/x-pack/plugins/monitoring/server/config.test.ts +++ b/x-pack/plugins/monitoring/server/config.test.ts @@ -4,6 +4,10 @@ * you may not use this file except in compliance with the Elastic License. */ import { createConfig, configSchema } from './config'; +jest.mock('fs', () => ({ + ...jest.requireActual('fs'), + readFileSync: jest.fn().mockImplementation((path: string) => `contents-of-${path}`), +})); describe('config schema', () => { it('generates proper defaults', () => { @@ -131,27 +135,30 @@ describe('createConfig()', () => { expect(config.ui.elasticsearch.hosts).toEqual(['http://localhost:9200']); }); - it('should attempt to read ssl files', async () => { - let error; - try { - createConfig( - configSchema.validate({ - ui: { - elasticsearch: { - hosts: 'http://localhost:9200', - ssl: { - certificate: 'packages/kbn-dev-utils/certs/elasticsearch.crt', - key: 'packages/kbn-dev-utils/certs/elasticsearch.key', - certificateAuthorities: 'packages/kbn-dev-utils/certs/ca.crt', - verificationMode: 'full', - }, - }, + it('should attempt to read PEM files', async () => { + const ssl = { + certificate: 'packages/kbn-dev-utils/certs/elasticsearch.crt', + key: 'packages/kbn-dev-utils/certs/elasticsearch.key', + certificateAuthorities: 'packages/kbn-dev-utils/certs/ca.crt', + }; + const config = createConfig( + configSchema.validate({ + elasticsearch: { + ssl, + }, + ui: { + elasticsearch: { + ssl, }, - }) - ); - } catch (err) { - error = err.message; - } - expect(error.includes('no such file or directory')).toBe(true); + }, + }) + ); + const expected = expect.objectContaining({ + certificate: 'contents-of-packages/kbn-dev-utils/certs/elasticsearch.crt', + key: 'contents-of-packages/kbn-dev-utils/certs/elasticsearch.key', + certificateAuthorities: ['contents-of-packages/kbn-dev-utils/certs/ca.crt'], + }); + expect(config.elasticsearch.ssl).toEqual(expected); + expect(config.ui.elasticsearch.ssl).toEqual(expected); }); }); From 2fccd1fe24b299235e22f2b65a7795db0ae2340c Mon Sep 17 00:00:00 2001 From: chrisronline Date: Tue, 9 Jun 2020 09:37:26 -0400 Subject: [PATCH 4/7] PR feedback --- x-pack/plugins/monitoring/server/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/monitoring/server/config.ts b/x-pack/plugins/monitoring/server/config.ts index c38884be61789..14fe60b82ef97 100644 --- a/x-pack/plugins/monitoring/server/config.ts +++ b/x-pack/plugins/monitoring/server/config.ts @@ -86,7 +86,7 @@ export type MonitoringConfig = ReturnType; export function createConfig(config: TypeOf) { return { ...config, - elasticsearch: new MonitoringElasticsearchConfig(config.elasticsearch), + elasticsearch: new ElasticsearchConfig(config.elasticsearch as ElasticsearchConfigType), ui: { ...config.ui, elasticsearch: new MonitoringElasticsearchConfig(config.ui.elasticsearch), From 3a0737833fb01188b7e847e80c5aae8ba4c621f3 Mon Sep 17 00:00:00 2001 From: chrisronline Date: Fri, 12 Jun 2020 10:01:04 -0400 Subject: [PATCH 5/7] PR feedback --- x-pack/plugins/monitoring/server/config.ts | 2 +- .../server/es_client/instantiate_client.ts | 18 +++++++++--------- x-pack/plugins/monitoring/server/types.ts | 4 ---- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/x-pack/plugins/monitoring/server/config.ts b/x-pack/plugins/monitoring/server/config.ts index 14fe60b82ef97..963ef8b2e63d0 100644 --- a/x-pack/plugins/monitoring/server/config.ts +++ b/x-pack/plugins/monitoring/server/config.ts @@ -14,7 +14,7 @@ import { ElasticsearchConfigType } from '../../../../src/core/server/elasticsear const hostURISchema = schema.uri({ scheme: ['http', 'https'] }); -const monitoringElasticsearchConfigSchema = elasticsearchConfigSchema.extends({ +export const monitoringElasticsearchConfigSchema = elasticsearchConfigSchema.extends({ logFetchCount: schema.number({ defaultValue: 10 }), hosts: schema.maybe(schema.oneOf([hostURISchema, schema.arrayOf(hostURISchema, { minSize: 1 })])), }); diff --git a/x-pack/plugins/monitoring/server/es_client/instantiate_client.ts b/x-pack/plugins/monitoring/server/es_client/instantiate_client.ts index 280d8aab70300..1fbc295a97cb1 100644 --- a/x-pack/plugins/monitoring/server/es_client/instantiate_client.ts +++ b/x-pack/plugins/monitoring/server/es_client/instantiate_client.ts @@ -3,11 +3,12 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ - -import { Logger, ElasticsearchClientConfig, ICustomClusterClient } from 'kibana/server'; +import { ConfigOptions } from 'elasticsearch'; +import { TypeOf } from '@kbn/config-schema'; +import { Logger, ICustomClusterClient } from 'kibana/server'; // @ts-ignore import { monitoringBulk } from '../kibana_monitoring/lib/monitoring_bulk'; -import { MonitoringElasticsearchConfig } from '../types'; +import { monitoringElasticsearchConfigSchema } from '../config'; /* Provide a dedicated Elasticsearch client for Monitoring * The connection options can be customized for the Monitoring application @@ -15,13 +16,12 @@ import { MonitoringElasticsearchConfig } from '../types'; * Kibana itself is connected to a production cluster. */ +type ESConfig = TypeOf & Pick; + export function instantiateClient( - elasticsearchConfig: any, + elasticsearchConfig: ESConfig, log: Logger, - createClient: ( - type: string, - clientConfig?: Partial - ) => ICustomClusterClient + createClient: (type: string, clientConfig?: Partial) => ICustomClusterClient ) { const isMonitoringCluster = hasMonitoringCluster(elasticsearchConfig); const cluster = createClient('monitoring', { @@ -35,6 +35,6 @@ export function instantiateClient( return cluster; } -export function hasMonitoringCluster(config: MonitoringElasticsearchConfig) { +export function hasMonitoringCluster(config: ESConfig) { return Boolean(config.hosts && config.hosts[0]); } diff --git a/x-pack/plugins/monitoring/server/types.ts b/x-pack/plugins/monitoring/server/types.ts index 9f30ed1ba5035..9b3725d007fd9 100644 --- a/x-pack/plugins/monitoring/server/types.ts +++ b/x-pack/plugins/monitoring/server/types.ts @@ -15,7 +15,3 @@ export interface MonitoringLicenseService { getSecurityFeature: () => LicenseFeature; stop: () => void; } - -export interface MonitoringElasticsearchConfig { - hosts: string[]; -} From 1dc4baf291da65d5d94b1555f04fcf2812bbe05c Mon Sep 17 00:00:00 2001 From: chrisronline Date: Fri, 12 Jun 2020 13:22:59 -0400 Subject: [PATCH 6/7] Fix type issues --- x-pack/plugins/monitoring/server/config.ts | 2 +- .../server/es_client/instantiate_client.ts | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/monitoring/server/config.ts b/x-pack/plugins/monitoring/server/config.ts index 963ef8b2e63d0..143161805c187 100644 --- a/x-pack/plugins/monitoring/server/config.ts +++ b/x-pack/plugins/monitoring/server/config.ts @@ -73,7 +73,7 @@ export const configSchema = schema.object({ }), }); -class MonitoringElasticsearchConfig extends ElasticsearchConfig { +export class MonitoringElasticsearchConfig extends ElasticsearchConfig { public readonly logFetchCount?: number; constructor(rawConfig: TypeOf) { diff --git a/x-pack/plugins/monitoring/server/es_client/instantiate_client.ts b/x-pack/plugins/monitoring/server/es_client/instantiate_client.ts index 1fbc295a97cb1..5b097220352cf 100644 --- a/x-pack/plugins/monitoring/server/es_client/instantiate_client.ts +++ b/x-pack/plugins/monitoring/server/es_client/instantiate_client.ts @@ -4,11 +4,10 @@ * you may not use this file except in compliance with the Elastic License. */ import { ConfigOptions } from 'elasticsearch'; -import { TypeOf } from '@kbn/config-schema'; import { Logger, ICustomClusterClient } from 'kibana/server'; // @ts-ignore import { monitoringBulk } from '../kibana_monitoring/lib/monitoring_bulk'; -import { monitoringElasticsearchConfigSchema } from '../config'; +import { MonitoringElasticsearchConfig } from '../config'; /* Provide a dedicated Elasticsearch client for Monitoring * The connection options can be customized for the Monitoring application @@ -16,25 +15,25 @@ import { monitoringElasticsearchConfigSchema } from '../config'; * Kibana itself is connected to a production cluster. */ -type ESConfig = TypeOf & Pick; +type ESClusterConfig = MonitoringElasticsearchConfig & Pick; export function instantiateClient( - elasticsearchConfig: ESConfig, + elasticsearchConfig: MonitoringElasticsearchConfig, log: Logger, - createClient: (type: string, clientConfig?: Partial) => ICustomClusterClient + createClient: (type: string, clientConfig?: Partial) => ICustomClusterClient ) { const isMonitoringCluster = hasMonitoringCluster(elasticsearchConfig); const cluster = createClient('monitoring', { ...(isMonitoringCluster ? elasticsearchConfig : {}), plugins: [monitoringBulk], logQueries: Boolean(elasticsearchConfig.logQueries), - }); + } as ESClusterConfig); const configSource = isMonitoringCluster ? 'monitoring' : 'production'; log.info(`config sourced from: ${configSource} cluster`); return cluster; } -export function hasMonitoringCluster(config: ESConfig) { +export function hasMonitoringCluster(config: MonitoringElasticsearchConfig) { return Boolean(config.hosts && config.hosts[0]); } From 413125a2b6a78106f5a4a2196af6b8a98c1cb143 Mon Sep 17 00:00:00 2001 From: chrisronline Date: Mon, 15 Jun 2020 10:24:32 -0400 Subject: [PATCH 7/7] PR feedback --- x-pack/plugins/monitoring/server/config.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/monitoring/server/config.ts b/x-pack/plugins/monitoring/server/config.ts index 143161805c187..a430be8da6a5f 100644 --- a/x-pack/plugins/monitoring/server/config.ts +++ b/x-pack/plugins/monitoring/server/config.ts @@ -5,15 +5,15 @@ */ import { schema, TypeOf } from '@kbn/config-schema'; import { - configSchema as elasticsearchConfigSchema, + config as ElasticsearchBaseConfig, ElasticsearchConfig, - // eslint-disable-next-line @kbn/eslint/no-restricted-paths -} from '../../../../src/core/server/elasticsearch'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { ElasticsearchConfigType } from '../../../../src/core/server/elasticsearch/elasticsearch_config'; +} from '../../../../src/core/server/'; const hostURISchema = schema.uri({ scheme: ['http', 'https'] }); +const elasticsearchConfigSchema = ElasticsearchBaseConfig.elasticsearch.schema; +type ElasticsearchConfigType = TypeOf; + export const monitoringElasticsearchConfigSchema = elasticsearchConfigSchema.extends({ logFetchCount: schema.number({ defaultValue: 10 }), hosts: schema.maybe(schema.oneOf([hostURISchema, schema.arrayOf(hostURISchema, { minSize: 1 })])),