From 057b83f968cc4a6a52cde111b6ee865819bed570 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Thu, 1 Oct 2020 13:25:49 +0200 Subject: [PATCH 01/18] Core Telemetry service --- src/core/server/internal_types.ts | 2 + src/core/server/server.ts | 7 + .../server/telemetry/is_configured.test.ts | 131 +++++++++++ src/core/server/telemetry/is_configured.ts | 65 ++++++ src/core/server/telemetry/is_defined.test.ts | 59 +++++ .../telemetry/telemetry_service.test.ts | 212 +++++++++++++++++ .../server/telemetry/telemetry_service.ts | 216 ++++++++++++++++++ src/core/server/telemetry/types.ts | 137 +++++++++++ 8 files changed, 829 insertions(+) create mode 100644 src/core/server/telemetry/is_configured.test.ts create mode 100644 src/core/server/telemetry/is_configured.ts create mode 100644 src/core/server/telemetry/is_defined.test.ts create mode 100644 src/core/server/telemetry/telemetry_service.test.ts create mode 100644 src/core/server/telemetry/telemetry_service.ts create mode 100644 src/core/server/telemetry/types.ts diff --git a/src/core/server/internal_types.ts b/src/core/server/internal_types.ts index f5a5edffb0a74..912f7fa075076 100644 --- a/src/core/server/internal_types.ts +++ b/src/core/server/internal_types.ts @@ -39,6 +39,7 @@ import { InternalHttpResourcesSetup } from './http_resources'; import { InternalStatusServiceSetup } from './status'; import { AuditTrailSetup, AuditTrailStart } from './audit_trail'; import { InternalLoggingServiceSetup } from './logging'; +import { CoreTelemetryStart } from './telemetry/types'; /** @internal */ export interface InternalCoreSetup { @@ -68,6 +69,7 @@ export interface InternalCoreStart { savedObjects: InternalSavedObjectsServiceStart; uiSettings: InternalUiSettingsServiceStart; auditTrail: AuditTrailStart; + coreTelemetry: CoreTelemetryStart; } /** diff --git a/src/core/server/server.ts b/src/core/server/server.ts index 5935636d54f9d..b7424b964b72a 100644 --- a/src/core/server/server.ts +++ b/src/core/server/server.ts @@ -48,6 +48,7 @@ import { config as statusConfig } from './status'; import { ContextService } from './context'; import { RequestHandlerContext } from '.'; import { InternalCoreSetup, InternalCoreStart, ServiceConfigDescriptor } from './internal_types'; +import { CoreTelemetryService } from './telemetry/telemetry_service'; const coreId = Symbol('core'); const rootConfigPath = ''; @@ -71,6 +72,7 @@ export class Server { private readonly logging: LoggingService; private readonly coreApp: CoreApp; private readonly auditTrail: AuditTrailService; + private readonly coreTelemetry: CoreTelemetryService; #pluginsInitialized?: boolean; private coreStart?: InternalCoreStart; @@ -102,6 +104,7 @@ export class Server { this.httpResources = new HttpResourcesService(core); this.auditTrail = new AuditTrailService(core); this.logging = new LoggingService(core); + this.coreTelemetry = new CoreTelemetryService(core); } public async setup() { @@ -179,6 +182,8 @@ export class Server { loggingSystem: this.loggingSystem, }); + this.coreTelemetry.setup({ metrics: metricsSetup }); + const coreSetup: InternalCoreSetup = { capabilities: capabilitiesSetup, context: contextServiceSetup, @@ -225,6 +230,7 @@ export class Server { const uiSettingsStart = await this.uiSettings.start(); const metricsStart = await this.metrics.start(); const httpStart = this.http.getStartContract(); + const coreTelemetryStart = this.coreTelemetry.start(); this.coreStart = { capabilities: capabilitiesStart, @@ -234,6 +240,7 @@ export class Server { savedObjects: savedObjectsStart, uiSettings: uiSettingsStart, auditTrail: auditTrailStart, + coreTelemetry: coreTelemetryStart, }; const pluginsStart = await this.plugins.start(this.coreStart); diff --git a/src/core/server/telemetry/is_configured.test.ts b/src/core/server/telemetry/is_configured.test.ts new file mode 100644 index 0000000000000..cfb436e38d737 --- /dev/null +++ b/src/core/server/telemetry/is_configured.test.ts @@ -0,0 +1,131 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { isConfigured } from './is_configured'; + +describe('isConfigured', () => { + describe('#string', () => { + it('returns true for a non-empty string', () => { + expect(isConfigured.string('I am configured')).toEqual(true); + }); + + it('returns false for an empty string', () => { + expect(isConfigured.string(' ')).toEqual(false); + expect(isConfigured.string(' ')).toEqual(false); + }); + + it('returns false for undefined', () => { + expect(isConfigured.string(undefined)).toEqual(false); + }); + + it('returns false for null', () => { + expect(isConfigured.string(null as any)).toEqual(false); + }); + + it('returns false for a record', () => { + expect(isConfigured.string({} as any)).toEqual(false); + expect(isConfigured.string({ key: 'hello' } as any)).toEqual(false); + }); + + it('returns false for an array', () => { + expect(isConfigured.string([] as any)).toEqual(false); + expect(isConfigured.string(['hello'] as any)).toEqual(false); + }); + }); + + describe('array', () => { + it('returns true for a non-empty array', () => { + expect(isConfigured.array(['a'])).toEqual(true); + expect(isConfigured.array([{}])).toEqual(true); + expect(isConfigured.array([{ key: 'hello' }])).toEqual(true); + }); + + it('returns false for an empty array', () => { + expect(isConfigured.array([])).toEqual(false); + }); + + it('returns false for undefined', () => { + expect(isConfigured.array(undefined)).toEqual(false); + }); + + it('returns false for null', () => { + expect(isConfigured.array(null as any)).toEqual(false); + }); + + it('returns false for a string', () => { + expect(isConfigured.array('string')).toEqual(false); + }); + + it('returns false for a record', () => { + expect(isConfigured.array({} as any)).toEqual(false); + }); + }); + + describe('stringOrArray', () => { + const arraySpy = jest.spyOn(isConfigured, 'array'); + const stringSpy = jest.spyOn(isConfigured, 'string'); + + it('calls #array for an array', () => { + isConfigured.stringOrArray([]); + expect(arraySpy).toHaveBeenCalledWith([]); + }); + + it('calls #string for non-array values', () => { + isConfigured.stringOrArray('string'); + expect(stringSpy).toHaveBeenCalledWith('string'); + }); + }); + + describe('record', () => { + it('returns true for a non-empty record', () => { + expect(isConfigured.record({ key: 'hello' })).toEqual(true); + expect(isConfigured.record({ key: undefined })).toEqual(true); + }); + + it('returns false for an empty record', () => { + expect(isConfigured.record({})).toEqual(false); + }); + }); + + describe('number', () => { + it('returns true for a valid number', () => { + expect(isConfigured.number(0)).toEqual(true); + expect(isConfigured.number(-0)).toEqual(true); + expect(isConfigured.number(1)).toEqual(true); + expect(isConfigured.number(-0)).toEqual(true); + }); + + it('returns false for NaN', () => { + expect(isConfigured.number(Number.NaN)).toEqual(false); + }); + + it('returns false for a string', () => { + expect(isConfigured.number('1' as any)).toEqual(false); + expect(isConfigured.number('' as any)).toEqual(false); + }); + + it('returns false for undefined', () => { + expect(isConfigured.number(undefined)).toEqual(false); + }); + + it('returns false for null', () => { + expect(isConfigured.number(null as any)).toEqual(false); + }); + }); +}); diff --git a/src/core/server/telemetry/is_configured.ts b/src/core/server/telemetry/is_configured.ts new file mode 100644 index 0000000000000..07e63854ef57d --- /dev/null +++ b/src/core/server/telemetry/is_configured.ts @@ -0,0 +1,65 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { isEqual } from 'lodash'; + +/** + * Test whether a given config value is configured based on it's schema type. + * Our configuration schema and code often accept and ignore empty values like + * `elasticsearch.customHeaders: {}`. However, for telemetry purposes, we're + * only interested when these values have been set to something that will + * change the behaivour of Kibana. + */ +export const isConfigured = { + /** + * config is a string with non-zero length + */ + string: (config?: string): boolean => { + return (config?.trim?.()?.length ?? 0) > 0; + }, + /** + * config is an array with non-zero length + */ + array: (config?: unknown[] | string, defaultValue?: any): boolean => { + return Array.isArray(config) + ? (config?.length ?? 0) > 0 && !isEqual(config, defaultValue) + : false; + }, + /** + * config is a string or array of strings where each element has non-zero length + */ + stringOrArray: (config?: string[] | string, defaultValue?: any): boolean => { + return Array.isArray(config) + ? isConfigured.array(config, defaultValue) + : isConfigured.string(config); + }, + /** + * config is a record with at least one key + */ + record: (config?: Record): boolean => { + return typeof config === 'object' && Object.keys(config).length > 0; + }, + /** + * config is a number + */ + number: (config?: number): boolean => { + // kbn-config-schema already does NaN validation, but doesn't hurt to be sure + return typeof config === 'number' && !isNaN(config); + }, +}; diff --git a/src/core/server/telemetry/is_defined.test.ts b/src/core/server/telemetry/is_defined.test.ts new file mode 100644 index 0000000000000..5b9aa8f23e75c --- /dev/null +++ b/src/core/server/telemetry/is_defined.test.ts @@ -0,0 +1,59 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +// describe.skip('isConfigured', () => { +// it('returns true for a string', () => { +// expect(isConfigured('hello')).toEqual(true); +// expect(isConfigured('')).toEqual(true); +// expect(isConfigured(' ')).toEqual(true); +// }); + +// it('returns true for a number', () => { +// expect(isConfigured(1)).toEqual(true); +// expect(isConfigured(-1)).toEqual(true); +// expect(isConfigured(0)).toEqual(true); +// expect(isConfigured(-0)).toEqual(true); +// expect(isConfigured(Number.NaN)).toEqual(true); +// }); + +// it('returns true for an array', () => { +// expect(isConfigured(['hello'])).toEqual(true); +// expect(isConfigured([])).toEqual(true); +// expect(isConfigured([{ key: 'hello' }])).toEqual(true); +// expect(isConfigured([{}])).toEqual(true); +// }); + +// it('returns true for a record', () => { +// expect(isConfigured({})).toEqual(true); +// expect(isConfigured({ key: 'hello' })).toEqual(true); +// }); + +// it('returns true for a boolean', () => { +// expect(isConfigured(true)).toEqual(true); +// expect(isConfigured(false)).toEqual(true); +// }); + +// it('returns false for undefined', () => { +// expect(isConfigured(undefined)).toEqual(false); +// }); + +// it('returns false for null', () => { +// expect(isConfigured(null)).toEqual(false); +// }); +// }); diff --git a/src/core/server/telemetry/telemetry_service.test.ts b/src/core/server/telemetry/telemetry_service.test.ts new file mode 100644 index 0000000000000..e1f8de2670a7d --- /dev/null +++ b/src/core/server/telemetry/telemetry_service.test.ts @@ -0,0 +1,212 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { BehaviorSubject, Observable } from 'rxjs'; +import { HotObservable } from 'rxjs/internal/testing/HotObservable'; +import { TestScheduler } from 'rxjs/testing'; + +import { configServiceMock } from '../config/mocks'; + +import { mockCoreContext } from '../core_context.mock'; +import { config as RawElasticsearchConfig } from '../elasticsearch/elasticsearch_config'; +import { config as RawHttpConfig } from '../http/http_config'; +import { config as RawLoggingConfig } from '../logging/logging_config'; +import { savedObjectsConfig as RawSavedObjectsConfig } from '../saved_objects/saved_objects_config'; +import { metricsServiceMock } from '../metrics/metrics_service.mock'; + +import { CoreTelemetryService } from './telemetry_service'; + +describe('CoreTelemetryService', () => { + const getTestScheduler = () => + new TestScheduler((actual, expected) => { + expect(actual).toEqual(expected); + }); + + let service: CoreTelemetryService; + const configService = configServiceMock.create(); + configService.atPath.mockImplementation((path) => { + if (path === 'elasticsearch') { + return new BehaviorSubject(RawElasticsearchConfig.schema.validate({})); + } else if (path === 'http') { + return new BehaviorSubject(RawHttpConfig.schema.validate({})); + } else if (path === 'logging') { + return new BehaviorSubject(RawLoggingConfig.schema.validate({})); + } else if (path === 'savedObjects') { + return new BehaviorSubject(RawSavedObjectsConfig.schema.validate({})); + } + return new BehaviorSubject({}); + }); + const coreContext = mockCoreContext.create({ configService }); + + beforeEach(() => { + service = new CoreTelemetryService(coreContext); + }); + + describe('start', () => { + describe('getCoreTelemetry', () => { + it('returns null if an exception occurs', () => { + const metrics = metricsServiceMock.createInternalSetupContract(); + metrics.getOpsMetrics$.mockReturnValueOnce(new BehaviorSubject({} as any)); + service.setup({ metrics }); + const { getCoreTelemetry } = service.start(); + expect(getCoreTelemetry()).toEqual(null); + }); + + it('returns core metrics for default config', () => { + const metrics = metricsServiceMock.createInternalSetupContract(); + service.setup({ metrics }); + const { getCoreTelemetry } = service.start(); + expect(getCoreTelemetry()).toMatchInlineSnapshot(` + Object { + "config": Object { + "elasticsearch": Object { + "apiVersion": "master", + "customHeadersConfigured": false, + "healthCheckDelayMs": 2500, + "logQueries": false, + "numberOfHostsConfigured": 1, + "pingTimeoutMs": 30000, + "requestHeadersWhitelistConfigured": false, + "requestTimeoutMs": 30000, + "shardTimeoutMs": 30000, + "sniffIntervalMs": -1, + "sniffOnConnectionFault": false, + "sniffOnStart": false, + "ssl": Object { + "alwaysPresentCertificate": false, + "certificateAuthoritiesConfigured": false, + "certificateConfigured": false, + "keyConfigured": false, + "verificationMode": "full", + }, + }, + "http": Object { + "basePathConfigured": false, + "compression": Object { + "enabled": true, + "referrerWhitelistConfigured": false, + }, + "keepaliveTimeout": 120000, + "maxPayloadInBytes": 1048576, + "requestId": Object { + "allowFromAnyIp": false, + "ipAllowlistConfigured": false, + }, + "rewriteBasePath": false, + "socketTimeout": 120000, + "ssl": Object { + "certificateAuthoritiesConfigured": false, + "certificateConfigured": false, + "cipherSuites": Array [ + "ECDHE-RSA-AES128-GCM-SHA256", + "ECDHE-ECDSA-AES128-GCM-SHA256", + "ECDHE-RSA-AES256-GCM-SHA384", + "ECDHE-ECDSA-AES256-GCM-SHA384", + "DHE-RSA-AES128-GCM-SHA256", + "ECDHE-RSA-AES128-SHA256", + "DHE-RSA-AES128-SHA256", + "ECDHE-RSA-AES256-SHA384", + "DHE-RSA-AES256-SHA384", + "ECDHE-RSA-AES256-SHA256", + "DHE-RSA-AES256-SHA256", + "HIGH", + "!aNULL", + "!eNULL", + "!EXPORT", + "!DES", + "!RC4", + "!MD5", + "!PSK", + "!SRP", + "!CAMELLIA", + ], + "clientAuthentication": "none", + "keyConfigured": false, + "keystoreConfigured": false, + "redirectHttpFromPortConfigured": false, + "supportedProtocols": Array [ + "TLSv1.1", + "TLSv1.2", + ], + "truststoreConfigured": false, + }, + "xsrf": Object { + "disableProtection": false, + "whitelistConfigured": false, + }, + }, + "logging": Object { + "appendersTypesUsed": Array [], + "loggersConfiguredCount": 0, + }, + "savedObjects": Object { + "maxImportExportSizeBytes": 10000, + "maxImportPayloadBytes": 10485760, + }, + }, + "environment": Object { + "memory": Object { + "heapSizeLimit": 1, + "heapTotalBytes": 1, + "heapUsedBytes": 1, + }, + "os": Object { + "platform": "darwin", + "platformRelease": "test", + }, + }, + } + `); + }); + }); + }); + + describe('setup and stop', () => { + it('subscribes and unsubscribes from all config paths and metrics', () => { + getTestScheduler().run(({ cold, hot, expectSubscriptions }) => { + const observables: Array> = []; + configService.atPath.mockImplementation(() => { + const newObservable = hot('-a-------'); + observables.push(newObservable); + return newObservable; + }); + const metrics = metricsServiceMock.createInternalSetupContract(); + metrics.getOpsMetrics$.mockImplementation(() => { + const newObservable = hot('-a-------'); + observables.push(newObservable); + return newObservable as Observable; + }); + + service.setup({ metrics }); + + // Use the stopTimer$ to delay calling stop() until the third frame + const stopTimer$ = cold('---a|'); + stopTimer$.subscribe(() => { + service.stop(); + }); + + const subs = '^--!'; + + observables.forEach((o) => { + expectSubscriptions(o.subscriptions).toBe(subs); + }); + }); + }); + }); +}); diff --git a/src/core/server/telemetry/telemetry_service.ts b/src/core/server/telemetry/telemetry_service.ts new file mode 100644 index 0000000000000..270df81050a69 --- /dev/null +++ b/src/core/server/telemetry/telemetry_service.ts @@ -0,0 +1,216 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { Subject } from 'rxjs'; +import { takeUntil } from 'rxjs/operators'; + +import { CoreService } from 'src/core/types'; +import { CoreContext } from '../core_context'; +import { ElasticsearchConfigType } from '../elasticsearch/elasticsearch_config'; +import { HttpConfigType } from '../http'; +import { Logger, LoggingConfigType } from '../logging'; +import { SavedObjectsConfigType } from '../saved_objects/saved_objects_config'; +import { CoreTelemetry, CoreTelemetryStart } from './types'; +import { SavedObjectsService } from '../saved_objects'; +import { isConfigured } from './is_configured'; +import { MetricsServiceSetup, OpsMetrics } from '..'; + +export interface SetupDeps { + metrics: MetricsServiceSetup; +} + +export interface StartDeps { + savedObjectsService: SavedObjectsService; +} + +export class CoreTelemetryService implements CoreService { + private readonly log: Logger; + private elasticsearchConfig?: ElasticsearchConfigType; + private configService: CoreContext['configService']; + private httpConfig?: HttpConfigType; + private loggingConfig?: LoggingConfigType; + private soConfig?: SavedObjectsConfigType; + private stop$: Subject; + private opsMetrics?: OpsMetrics; + + constructor(core: CoreContext) { + this.log = core.logger.get('core_telemetry'); + this.configService = core.configService; + this.stop$ = new Subject(); + } + + private getCoreTelemetry(): CoreTelemetry { + if ( + this.elasticsearchConfig == null || + this.httpConfig == null || + this.soConfig == null || + this.opsMetrics == null + ) { + throw new Error('Unable to read config values. Ensure that setup() has completed.'); + } + + const es = this.elasticsearchConfig; + + const http = this.httpConfig; + return { + config: { + elasticsearch: { + apiVersion: es.apiVersion, + sniffOnStart: es.sniffOnStart, + sniffIntervalMs: es.sniffInterval !== false ? es.sniffInterval.asMilliseconds() : -1, + sniffOnConnectionFault: es.sniffOnConnectionFault, + numberOfHostsConfigured: Array.isArray(es.hosts) + ? es.hosts.length + : isConfigured.string(es.hosts) + ? 1 + : 0, + customHeadersConfigured: isConfigured.record(es.customHeaders), + healthCheckDelayMs: es.healthCheck.delay.asMilliseconds(), + logQueries: es.logQueries, + pingTimeoutMs: es.pingTimeout.asMilliseconds(), + requestHeadersWhitelistConfigured: isConfigured.stringOrArray( + es.requestHeadersWhitelist, + ['authorization'] + ), + requestTimeoutMs: es.requestTimeout.asMilliseconds(), + shardTimeoutMs: es.shardTimeout.asMilliseconds(), + ssl: { + alwaysPresentCertificate: es.ssl.alwaysPresentCertificate, + certificateAuthoritiesConfigured: isConfigured.stringOrArray( + es.ssl.certificateAuthorities + ), + certificateConfigured: isConfigured.string(es.ssl.certificate), + keyConfigured: isConfigured.string(es.ssl.key), + verificationMode: es.ssl.verificationMode, + }, + }, + http: { + basePathConfigured: isConfigured.string(http.basePath), + maxPayloadInBytes: http.maxPayload.getValueInBytes(), + rewriteBasePath: http.rewriteBasePath, + keepaliveTimeout: http.keepaliveTimeout, + socketTimeout: http.socketTimeout, + compression: { + enabled: http.compression.enabled, + referrerWhitelistConfigured: isConfigured.array(http.compression.referrerWhitelist), + }, + xsrf: { + disableProtection: http.xsrf.disableProtection, + whitelistConfigured: isConfigured.array(http.xsrf.whitelist), + }, + requestId: { + allowFromAnyIp: http.requestId.allowFromAnyIp, + ipAllowlistConfigured: isConfigured.array(http.requestId.ipAllowlist), + }, + ssl: { + certificateAuthoritiesConfigured: isConfigured.stringOrArray( + http.ssl.certificateAuthorities + ), + certificateConfigured: isConfigured.string(http.ssl.certificate), + cipherSuites: http.ssl.cipherSuites, + keyConfigured: isConfigured.string(http.ssl.key), + redirectHttpFromPortConfigured: isConfigured.number(http.ssl.redirectHttpFromPort), + supportedProtocols: http.ssl.supportedProtocols, + clientAuthentication: http.ssl.clientAuthentication, + keystoreConfigured: isConfigured.record(http.ssl.keystore), + truststoreConfigured: isConfigured.record(http.ssl.truststore), + }, + }, + + logging: { + appendersTypesUsed: Array.from( + Array.from(this.loggingConfig?.appenders.values() ?? []) + .reduce((acc, a) => acc.add(a.kind), new Set()) + .values() + ), + loggersConfiguredCount: this.loggingConfig?.loggers.length ?? 0, + }, + + savedObjects: { + maxImportPayloadBytes: this.soConfig.maxImportPayloadBytes.getValueInBytes(), + maxImportExportSizeBytes: this.soConfig.maxImportExportSize.getValueInBytes(), + }, + }, + environment: { + memory: { + heapSizeLimit: this.opsMetrics.process.memory.heap.size_limit, + heapTotalBytes: this.opsMetrics.process.memory.heap.total_in_bytes, + heapUsedBytes: this.opsMetrics.process.memory.heap.used_in_bytes, + }, + os: { + platform: this.opsMetrics.os.platform, + platformRelease: this.opsMetrics.os.platformRelease, + }, + }, + }; + } + + setup({ metrics }: SetupDeps) { + metrics + .getOpsMetrics$() + .pipe(takeUntil(this.stop$)) + .subscribe((opsMetrics) => (this.opsMetrics = opsMetrics)); + + this.configService + .atPath('elasticsearch') + .pipe(takeUntil(this.stop$)) + .subscribe((config) => { + this.elasticsearchConfig = config; + }); + + this.configService + .atPath('http') + .pipe(takeUntil(this.stop$)) + .subscribe((config) => { + this.httpConfig = config; + }); + + this.configService + .atPath('logging') + .pipe(takeUntil(this.stop$)) + .subscribe((config) => { + this.loggingConfig = config; + }); + + this.configService + .atPath('savedObjects') + .pipe(takeUntil(this.stop$)) + .subscribe((config) => { + this.soConfig = config; + }); + } + + start() { + return { + getCoreTelemetry: () => { + try { + return this.getCoreTelemetry(); + } catch (e) { + this.log.error('Error collecting core telemetry', e); + return null; + } + }, + }; + } + + stop() { + this.stop$.next(); + this.stop$.complete(); + } +} diff --git a/src/core/server/telemetry/types.ts b/src/core/server/telemetry/types.ts new file mode 100644 index 0000000000000..1adeaa9f8c6e9 --- /dev/null +++ b/src/core/server/telemetry/types.ts @@ -0,0 +1,137 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export interface CoreTelemetry { + config: CoreConfigTelemetry; + // usage: CoreUsageTelemetry; + environment: CoreEnvironmentTelemetry; +} + +/** + * Telemetry data on this cluster's usage of Core features + */ +export interface CoreUsageTelemetry { + savedObjects: { + totalCount: number; + typesCount: number; + }; +} + +/** + * Telemetry data on this Kibana node's runtime environment. + */ +export interface CoreEnvironmentTelemetry { + memory: { + heapTotalBytes: number; + heapUsedBytes: number; + /** V8 heap size limit */ + heapSizeLimit: number; + }; + os: { + platform: string; + platformRelease: string; + distro?: string; + distroRelease?: string; + }; +} + +/** + * Telemetry data on this cluster's configuration of Core features + */ +export interface CoreConfigTelemetry { + elasticsearch: { + sniffOnStart: boolean; + sniffIntervalMs?: number; + sniffOnConnectionFault: boolean; + numberOfHostsConfigured: number; + requestHeadersWhitelistConfigured: boolean; + customHeadersConfigured: boolean; + shardTimeoutMs: number; + requestTimeoutMs: number; + pingTimeoutMs: number; + logQueries: boolean; + ssl: { + verificationMode: 'none' | 'certificate' | 'full'; + certificateAuthoritiesConfigured: boolean; + certificateConfigured: boolean; + keyConfigured: boolean; + // keystoreConfigured: boolean; + // truststoreConfigured: boolean; requires access to rawConfig + alwaysPresentCertificate: boolean; + }; + apiVersion: string; + healthCheckDelayMs: number; + }; + + http: { + basePathConfigured: boolean; + maxPayloadInBytes: number; + rewriteBasePath: boolean; + keepaliveTimeout: number; + socketTimeout: number; + compression: { + enabled: boolean; + referrerWhitelistConfigured: boolean; + }; + xsrf: { + disableProtection: boolean; + whitelistConfigured: boolean; + }; + requestId: { + allowFromAnyIp: boolean; + ipAllowlistConfigured: boolean; + }; + ssl: { + certificateAuthoritiesConfigured: boolean; + certificateConfigured: boolean; + cipherSuites: string[]; + keyConfigured: boolean; + keystoreConfigured: boolean; + truststoreConfigured: boolean; + redirectHttpFromPortConfigured: boolean; + supportedProtocols: string[]; + clientAuthentication: 'none' | 'optional' | 'required'; + }; + }; + + logging: { + appendersTypesUsed: string[]; + loggersConfiguredCount: number; + }; + + // plugins: { + // /** list of built-in plugins that are disabled */ + // firstPartyDisabled: string[]; + // /** list of third-party plugins that are installed and enabled */ + // thirdParty: string[]; + // }; + + savedObjects: { + maxImportPayloadBytes: number; + maxImportExportSizeBytes: number; + }; + + // uiSettings: { + // overridesCount: number; + // }; +} + +export interface CoreTelemetryStart { + getCoreTelemetry(): CoreTelemetry | null; +} From 72274123e65ab9d71776ed062c3d6c7e06a8141f Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Thu, 1 Oct 2020 14:23:48 +0200 Subject: [PATCH 02/18] CoreTelemetryService mock --- src/core/server/mocks.ts | 2 + .../telemetry/telemetry_service.mock.ts | 142 ++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 src/core/server/telemetry/telemetry_service.mock.ts diff --git a/src/core/server/mocks.ts b/src/core/server/mocks.ts index 3030cd9f4e0cb..8e139b48c2235 100644 --- a/src/core/server/mocks.ts +++ b/src/core/server/mocks.ts @@ -37,6 +37,7 @@ import { metricsServiceMock } from './metrics/metrics_service.mock'; import { environmentServiceMock } from './environment/environment_service.mock'; import { statusServiceMock } from './status/status_service.mock'; import { auditTrailServiceMock } from './audit_trail/audit_trail_service.mock'; +import { coreTelemetryServiceMock } from './telemetry/telemetry_service.mock'; export { configServiceMock } from './config/mocks'; export { httpServerMock } from './http/http_server.mocks'; @@ -190,6 +191,7 @@ function createInternalCoreStartMock() { savedObjects: savedObjectsServiceMock.createInternalStartContract(), uiSettings: uiSettingsServiceMock.createStartContract(), auditTrail: auditTrailServiceMock.createStartContract(), + coreTelemetry: coreTelemetryServiceMock.createStartContract(), }; return startDeps; } diff --git a/src/core/server/telemetry/telemetry_service.mock.ts b/src/core/server/telemetry/telemetry_service.mock.ts new file mode 100644 index 0000000000000..71269df37e184 --- /dev/null +++ b/src/core/server/telemetry/telemetry_service.mock.ts @@ -0,0 +1,142 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { PublicMethodsOf } from '@kbn/utility-types'; +import { BehaviorSubject } from 'rxjs'; +import { CoreTelemetryService } from './telemetry_service'; +import { CoreTelemetry, CoreTelemetryStart } from './types'; + +const createStartContractMock = () => { + const startContract: jest.Mocked = { + getCoreTelemetry: jest.fn().mockReturnValue( + new BehaviorSubject({ + config: { + elasticsearch: { + apiVersion: 'master', + customHeadersConfigured: false, + healthCheckDelayMs: 2500, + logQueries: false, + numberOfHostsConfigured: 1, + pingTimeoutMs: 30000, + requestHeadersWhitelistConfigured: false, + requestTimeoutMs: 30000, + shardTimeoutMs: 30000, + sniffIntervalMs: -1, + sniffOnConnectionFault: false, + sniffOnStart: false, + ssl: { + alwaysPresentCertificate: false, + certificateAuthoritiesConfigured: false, + certificateConfigured: false, + keyConfigured: false, + verificationMode: 'full', + }, + }, + http: { + basePathConfigured: false, + compression: { + enabled: true, + referrerWhitelistConfigured: false, + }, + keepaliveTimeout: 120000, + maxPayloadInBytes: 1048576, + requestId: { + allowFromAnyIp: false, + ipAllowlistConfigured: false, + }, + rewriteBasePath: false, + socketTimeout: 120000, + ssl: { + certificateAuthoritiesConfigured: false, + certificateConfigured: false, + cipherSuites: [ + 'ECDHE-RSA-AES128-GCM-SHA256', + 'ECDHE-ECDSA-AES128-GCM-SHA256', + 'ECDHE-RSA-AES256-GCM-SHA384', + 'ECDHE-ECDSA-AES256-GCM-SHA384', + 'DHE-RSA-AES128-GCM-SHA256', + 'ECDHE-RSA-AES128-SHA256', + 'DHE-RSA-AES128-SHA256', + 'ECDHE-RSA-AES256-SHA384', + 'DHE-RSA-AES256-SHA384', + 'ECDHE-RSA-AES256-SHA256', + 'DHE-RSA-AES256-SHA256', + 'HIGH', + '!aNULL', + '!eNULL', + '!EXPORT', + '!DES', + '!RC4', + '!MD5', + '!PSK', + '!SRP', + '!CAMELLIA', + ], + clientAuthentication: 'none', + keyConfigured: false, + keystoreConfigured: false, + redirectHttpFromPortConfigured: false, + supportedProtocols: ['TLSv1.1', 'TLSv1.2'], + truststoreConfigured: false, + }, + xsrf: { + disableProtection: false, + whitelistConfigured: false, + }, + }, + logging: { + appendersTypesUsed: [], + loggersConfiguredCount: 0, + }, + savedObjects: { + maxImportExportSizeBytes: 10000, + maxImportPayloadBytes: 10485760, + }, + }, + environment: { + memory: { + heapSizeLimit: 1, + heapTotalBytes: 1, + heapUsedBytes: 1, + }, + os: { + platform: 'darwin', + platformRelease: 'test', + }, + }, + }) + ), + }; + + return startContract; +}; + +const createMock = () => { + const mocked: jest.Mocked> = { + setup: jest.fn(), + start: jest.fn().mockReturnValue(createStartContractMock()), + stop: jest.fn(), + }; + return mocked; +}; + +export const coreTelemetryServiceMock = { + create: createMock, + createStartContract: createStartContractMock, +}; From f69a00dba1bd23484ab86d47d2607098521c3406 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Thu, 1 Oct 2020 14:57:14 +0200 Subject: [PATCH 03/18] Add missing config values back, cleanup --- ...gin-core-server.corestart.coretelemetry.md | 13 ++++ .../kibana-plugin-core-server.corestart.md | 1 + ...plugin-core-server.coretelemetry.config.md | 11 ++++ ...n-core-server.coretelemetry.environment.md | 11 ++++ ...kibana-plugin-core-server.coretelemetry.md | 19 ++++++ ...a-plugin-core-server.coretelemetrystart.md | 11 ++++ .../core/server/kibana-plugin-core-server.md | 2 + src/core/server/index.ts | 5 ++ src/core/server/internal_types.ts | 2 +- src/core/server/legacy/legacy_service.ts | 5 ++ src/core/server/mocks.ts | 2 + src/core/server/plugins/plugin_context.ts | 1 + src/core/server/server.api.md | 24 ++++++++ src/core/server/server.ts | 2 +- src/core/server/telemetry/index.ts | 20 +++++++ src/core/server/telemetry/is_defined.test.ts | 59 ------------------- .../telemetry/telemetry_service.mock.ts | 2 + .../telemetry/telemetry_service.test.ts | 2 + .../server/telemetry/telemetry_service.ts | 2 + src/core/server/telemetry/types.ts | 8 ++- 20 files changed, 139 insertions(+), 63 deletions(-) create mode 100644 docs/development/core/server/kibana-plugin-core-server.corestart.coretelemetry.md create mode 100644 docs/development/core/server/kibana-plugin-core-server.coretelemetry.config.md create mode 100644 docs/development/core/server/kibana-plugin-core-server.coretelemetry.environment.md create mode 100644 docs/development/core/server/kibana-plugin-core-server.coretelemetry.md create mode 100644 docs/development/core/server/kibana-plugin-core-server.coretelemetrystart.md create mode 100644 src/core/server/telemetry/index.ts delete mode 100644 src/core/server/telemetry/is_defined.test.ts diff --git a/docs/development/core/server/kibana-plugin-core-server.corestart.coretelemetry.md b/docs/development/core/server/kibana-plugin-core-server.corestart.coretelemetry.md new file mode 100644 index 0000000000000..51d170565e0ee --- /dev/null +++ b/docs/development/core/server/kibana-plugin-core-server.corestart.coretelemetry.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreStart](./kibana-plugin-core-server.corestart.md) > [coreTelemetry](./kibana-plugin-core-server.corestart.coretelemetry.md) + +## CoreStart.coreTelemetry property + +[CoreTelemetryStart](./kibana-plugin-core-server.coretelemetrystart.md) + +Signature: + +```typescript +coreTelemetry: CoreTelemetryStart; +``` diff --git a/docs/development/core/server/kibana-plugin-core-server.corestart.md b/docs/development/core/server/kibana-plugin-core-server.corestart.md index 0d5474fae5e16..42054e458c501 100644 --- a/docs/development/core/server/kibana-plugin-core-server.corestart.md +++ b/docs/development/core/server/kibana-plugin-core-server.corestart.md @@ -18,6 +18,7 @@ export interface CoreStart | --- | --- | --- | | [auditTrail](./kibana-plugin-core-server.corestart.audittrail.md) | AuditTrailStart | [AuditTrailSetup](./kibana-plugin-core-server.audittrailsetup.md) | | [capabilities](./kibana-plugin-core-server.corestart.capabilities.md) | CapabilitiesStart | [CapabilitiesStart](./kibana-plugin-core-server.capabilitiesstart.md) | +| [coreTelemetry](./kibana-plugin-core-server.corestart.coretelemetry.md) | CoreTelemetryStart | [CoreTelemetryStart](./kibana-plugin-core-server.coretelemetrystart.md) | | [elasticsearch](./kibana-plugin-core-server.corestart.elasticsearch.md) | ElasticsearchServiceStart | [ElasticsearchServiceStart](./kibana-plugin-core-server.elasticsearchservicestart.md) | | [http](./kibana-plugin-core-server.corestart.http.md) | HttpServiceStart | [HttpServiceStart](./kibana-plugin-core-server.httpservicestart.md) | | [metrics](./kibana-plugin-core-server.corestart.metrics.md) | MetricsServiceStart | [MetricsServiceStart](./kibana-plugin-core-server.metricsservicestart.md) | diff --git a/docs/development/core/server/kibana-plugin-core-server.coretelemetry.config.md b/docs/development/core/server/kibana-plugin-core-server.coretelemetry.config.md new file mode 100644 index 0000000000000..d0aaaf736e1a5 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-core-server.coretelemetry.config.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreTelemetry](./kibana-plugin-core-server.coretelemetry.md) > [config](./kibana-plugin-core-server.coretelemetry.config.md) + +## CoreTelemetry.config property + +Signature: + +```typescript +config: CoreConfigTelemetry; +``` diff --git a/docs/development/core/server/kibana-plugin-core-server.coretelemetry.environment.md b/docs/development/core/server/kibana-plugin-core-server.coretelemetry.environment.md new file mode 100644 index 0000000000000..cb0da8267b6cb --- /dev/null +++ b/docs/development/core/server/kibana-plugin-core-server.coretelemetry.environment.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreTelemetry](./kibana-plugin-core-server.coretelemetry.md) > [environment](./kibana-plugin-core-server.coretelemetry.environment.md) + +## CoreTelemetry.environment property + +Signature: + +```typescript +environment: CoreEnvironmentTelemetry; +``` diff --git a/docs/development/core/server/kibana-plugin-core-server.coretelemetry.md b/docs/development/core/server/kibana-plugin-core-server.coretelemetry.md new file mode 100644 index 0000000000000..a8cf3fb976c5f --- /dev/null +++ b/docs/development/core/server/kibana-plugin-core-server.coretelemetry.md @@ -0,0 +1,19 @@ + + +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreTelemetry](./kibana-plugin-core-server.coretelemetry.md) + +## CoreTelemetry interface + +Signature: + +```typescript +export interface CoreTelemetry +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [config](./kibana-plugin-core-server.coretelemetry.config.md) | CoreConfigTelemetry | | +| [environment](./kibana-plugin-core-server.coretelemetry.environment.md) | CoreEnvironmentTelemetry | | + diff --git a/docs/development/core/server/kibana-plugin-core-server.coretelemetrystart.md b/docs/development/core/server/kibana-plugin-core-server.coretelemetrystart.md new file mode 100644 index 0000000000000..5892587ca6a56 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-core-server.coretelemetrystart.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreTelemetryStart](./kibana-plugin-core-server.coretelemetrystart.md) + +## CoreTelemetryStart interface + +Signature: + +```typescript +export interface CoreTelemetryStart +``` diff --git a/docs/development/core/server/kibana-plugin-core-server.md b/docs/development/core/server/kibana-plugin-core-server.md index be8b7c27495ad..d7b4221cf4072 100644 --- a/docs/development/core/server/kibana-plugin-core-server.md +++ b/docs/development/core/server/kibana-plugin-core-server.md @@ -70,6 +70,8 @@ The plugin integrates with the core system via lifecycle events: `setup` | [CoreSetup](./kibana-plugin-core-server.coresetup.md) | Context passed to the plugins setup method. | | [CoreStart](./kibana-plugin-core-server.corestart.md) | Context passed to the plugins start method. | | [CoreStatus](./kibana-plugin-core-server.corestatus.md) | Status of core services. | +| [CoreTelemetry](./kibana-plugin-core-server.coretelemetry.md) | | +| [CoreTelemetryStart](./kibana-plugin-core-server.coretelemetrystart.md) | | | [CountResponse](./kibana-plugin-core-server.countresponse.md) | | | [CustomHttpResponseOptions](./kibana-plugin-core-server.customhttpresponseoptions.md) | HTTP response parameters for a response with adjustable status code. | | [DeleteDocumentResponse](./kibana-plugin-core-server.deletedocumentresponse.md) | | diff --git a/src/core/server/index.ts b/src/core/server/index.ts index 70ef93963c69f..5f711720c85f9 100644 --- a/src/core/server/index.ts +++ b/src/core/server/index.ts @@ -64,6 +64,7 @@ import { MetricsServiceSetup, MetricsServiceStart } from './metrics'; import { StatusServiceSetup } from './status'; import { Auditor, AuditTrailSetup, AuditTrailStart } from './audit_trail'; import { AppenderConfigType, appendersSchema, LoggingServiceSetup } from './logging'; +import { CoreTelemetryStart } from './telemetry'; export { AuditableEvent, Auditor, AuditorFactory, AuditTrailSetup } from './audit_trail'; export { bootstrap } from './bootstrap'; @@ -349,6 +350,8 @@ export { StatusServiceSetup, } from './status'; +export { CoreTelemetryStart, CoreTelemetry } from './telemetry'; + /** * Plugin specific context passed to a route handler. * @@ -456,6 +459,8 @@ export interface CoreStart { uiSettings: UiSettingsServiceStart; /** {@link AuditTrailSetup} */ auditTrail: AuditTrailStart; + /** {@link CoreTelemetryStart} */ + coreTelemetry: CoreTelemetryStart; } export { diff --git a/src/core/server/internal_types.ts b/src/core/server/internal_types.ts index 912f7fa075076..0d5d72508c280 100644 --- a/src/core/server/internal_types.ts +++ b/src/core/server/internal_types.ts @@ -39,7 +39,7 @@ import { InternalHttpResourcesSetup } from './http_resources'; import { InternalStatusServiceSetup } from './status'; import { AuditTrailSetup, AuditTrailStart } from './audit_trail'; import { InternalLoggingServiceSetup } from './logging'; -import { CoreTelemetryStart } from './telemetry/types'; +import { CoreTelemetryStart } from './telemetry'; /** @internal */ export interface InternalCoreSetup { diff --git a/src/core/server/legacy/legacy_service.ts b/src/core/server/legacy/legacy_service.ts index 086e20c98c1a3..ba6f237737e5a 100644 --- a/src/core/server/legacy/legacy_service.ts +++ b/src/core/server/legacy/legacy_service.ts @@ -217,6 +217,11 @@ export class LegacyService implements CoreService { }, uiSettings: { asScopedToClient: startDeps.core.uiSettings.asScopedToClient }, auditTrail: startDeps.core.auditTrail, + coreTelemetry: { + getCoreTelemetry: () => { + throw new Error('core.start.coreTelemetry.getCoreTelemetry is unsupported in legacy'); + }, + }, }; const router = setupDeps.core.http.createRouter('', this.legacyId); diff --git a/src/core/server/mocks.ts b/src/core/server/mocks.ts index 8e139b48c2235..61e17ffe1078a 100644 --- a/src/core/server/mocks.ts +++ b/src/core/server/mocks.ts @@ -56,6 +56,7 @@ export { renderingMock } from './rendering/rendering_service.mock'; export { statusServiceMock } from './status/status_service.mock'; export { contextServiceMock } from './context/context_service.mock'; export { capabilitiesServiceMock } from './capabilities/capabilities_service.mock'; +export { coreTelemetryServiceMock } from './telemetry/telemetry_service.mock'; export function pluginInitializerContextConfigMock(config: T) { const globalConfig: SharedGlobalConfig = { @@ -158,6 +159,7 @@ function createCoreStartMock() { metrics: metricsServiceMock.createStartContract(), savedObjects: savedObjectsServiceMock.createStartContract(), uiSettings: uiSettingsServiceMock.createStartContract(), + coreTelemetry: coreTelemetryServiceMock.createStartContract(), }; return mock; diff --git a/src/core/server/plugins/plugin_context.ts b/src/core/server/plugins/plugin_context.ts index ab3f471fd7942..73d19744e4e94 100644 --- a/src/core/server/plugins/plugin_context.ts +++ b/src/core/server/plugins/plugin_context.ts @@ -251,5 +251,6 @@ export function createPluginStartContext( asScopedToClient: deps.uiSettings.asScopedToClient, }, auditTrail: deps.auditTrail, + coreTelemetry: deps.coreTelemetry, }; } diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index 450be3b0e9a6c..71fd60212f32a 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -439,6 +439,8 @@ export interface CoreStart { // (undocumented) capabilities: CapabilitiesStart; // (undocumented) + coreTelemetry: CoreTelemetryStart; + // (undocumented) elasticsearch: ElasticsearchServiceStart; // (undocumented) http: HttpServiceStart; @@ -458,6 +460,28 @@ export interface CoreStatus { savedObjects: ServiceStatus; } +// Warning: (ae-missing-release-tag) "CoreTelemetry" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export interface CoreTelemetry { + // Warning: (ae-forgotten-export) The symbol "CoreConfigTelemetry" needs to be exported by the entry point index.d.ts + // + // (undocumented) + config: CoreConfigTelemetry; + // Warning: (ae-forgotten-export) The symbol "CoreEnvironmentTelemetry" needs to be exported by the entry point index.d.ts + // + // (undocumented) + environment: CoreEnvironmentTelemetry; +} + +// Warning: (ae-missing-release-tag) "CoreTelemetryStart" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export interface CoreTelemetryStart { + // @internal + getCoreTelemetry(): CoreTelemetry | null; +} + // @public (undocumented) export interface CountResponse { // (undocumented) diff --git a/src/core/server/server.ts b/src/core/server/server.ts index 6f74c1ee97bc7..86b1f48c30117 100644 --- a/src/core/server/server.ts +++ b/src/core/server/server.ts @@ -48,7 +48,7 @@ import { config as statusConfig } from './status'; import { ContextService } from './context'; import { RequestHandlerContext } from '.'; import { InternalCoreSetup, InternalCoreStart, ServiceConfigDescriptor } from './internal_types'; -import { CoreTelemetryService } from './telemetry/telemetry_service'; +import { CoreTelemetryService } from './telemetry'; const coreId = Symbol('core'); const rootConfigPath = ''; diff --git a/src/core/server/telemetry/index.ts b/src/core/server/telemetry/index.ts new file mode 100644 index 0000000000000..d265cd67c5586 --- /dev/null +++ b/src/core/server/telemetry/index.ts @@ -0,0 +1,20 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +export { CoreTelemetryStart, CoreTelemetry } from './types'; +export { CoreTelemetryService } from './telemetry_service'; diff --git a/src/core/server/telemetry/is_defined.test.ts b/src/core/server/telemetry/is_defined.test.ts deleted file mode 100644 index 5b9aa8f23e75c..0000000000000 --- a/src/core/server/telemetry/is_defined.test.ts +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -// describe.skip('isConfigured', () => { -// it('returns true for a string', () => { -// expect(isConfigured('hello')).toEqual(true); -// expect(isConfigured('')).toEqual(true); -// expect(isConfigured(' ')).toEqual(true); -// }); - -// it('returns true for a number', () => { -// expect(isConfigured(1)).toEqual(true); -// expect(isConfigured(-1)).toEqual(true); -// expect(isConfigured(0)).toEqual(true); -// expect(isConfigured(-0)).toEqual(true); -// expect(isConfigured(Number.NaN)).toEqual(true); -// }); - -// it('returns true for an array', () => { -// expect(isConfigured(['hello'])).toEqual(true); -// expect(isConfigured([])).toEqual(true); -// expect(isConfigured([{ key: 'hello' }])).toEqual(true); -// expect(isConfigured([{}])).toEqual(true); -// }); - -// it('returns true for a record', () => { -// expect(isConfigured({})).toEqual(true); -// expect(isConfigured({ key: 'hello' })).toEqual(true); -// }); - -// it('returns true for a boolean', () => { -// expect(isConfigured(true)).toEqual(true); -// expect(isConfigured(false)).toEqual(true); -// }); - -// it('returns false for undefined', () => { -// expect(isConfigured(undefined)).toEqual(false); -// }); - -// it('returns false for null', () => { -// expect(isConfigured(null)).toEqual(false); -// }); -// }); diff --git a/src/core/server/telemetry/telemetry_service.mock.ts b/src/core/server/telemetry/telemetry_service.mock.ts index 71269df37e184..1dafa941bdca1 100644 --- a/src/core/server/telemetry/telemetry_service.mock.ts +++ b/src/core/server/telemetry/telemetry_service.mock.ts @@ -46,6 +46,8 @@ const createStartContractMock = () => { certificateConfigured: false, keyConfigured: false, verificationMode: 'full', + keystoreConfigured: false, + truststoreConfigured: false, }, }, http: { diff --git a/src/core/server/telemetry/telemetry_service.test.ts b/src/core/server/telemetry/telemetry_service.test.ts index e1f8de2670a7d..b792f95138ee8 100644 --- a/src/core/server/telemetry/telemetry_service.test.ts +++ b/src/core/server/telemetry/telemetry_service.test.ts @@ -93,6 +93,8 @@ describe('CoreTelemetryService', () => { "certificateAuthoritiesConfigured": false, "certificateConfigured": false, "keyConfigured": false, + "keystoreConfigured": false, + "truststoreConfigured": false, "verificationMode": "full", }, }, diff --git a/src/core/server/telemetry/telemetry_service.ts b/src/core/server/telemetry/telemetry_service.ts index 270df81050a69..a8a7c67407b92 100644 --- a/src/core/server/telemetry/telemetry_service.ts +++ b/src/core/server/telemetry/telemetry_service.ts @@ -98,6 +98,8 @@ export class CoreTelemetryService implements CoreService Date: Thu, 1 Oct 2020 20:11:56 +0200 Subject: [PATCH 04/18] Core usage collector --- src/plugins/kibana_usage_collection/README.md | 1 + .../collectors/core/core_usage_collector.ts | 144 ++++++++++++++++++ .../server/collectors/core/index.test.ts | 62 ++++++++ .../server/collectors/core/index.ts | 20 +++ .../server/collectors/index.ts | 1 + .../kibana_usage_collection/server/plugin.ts | 6 + 6 files changed, 234 insertions(+) create mode 100644 src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts create mode 100644 src/plugins/kibana_usage_collection/server/collectors/core/index.test.ts create mode 100644 src/plugins/kibana_usage_collection/server/collectors/core/index.ts diff --git a/src/plugins/kibana_usage_collection/README.md b/src/plugins/kibana_usage_collection/README.md index 73a4d53f305f2..69711d30cdc74 100644 --- a/src/plugins/kibana_usage_collection/README.md +++ b/src/plugins/kibana_usage_collection/README.md @@ -8,3 +8,4 @@ This plugin registers the basic usage collectors from Kibana: - Number of Saved Objects per type - Non-default UI Settings - CSP configuration +- Core Metrics diff --git a/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts b/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts new file mode 100644 index 0000000000000..bb6edf48cd24f --- /dev/null +++ b/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts @@ -0,0 +1,144 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { CoreTelemetry, CoreTelemetryStart } from 'src/core/server'; +import { UsageCollectionSetup } from 'src/plugins/usage_collection/server'; +import { KIBANA_STATS_TYPE } from '../../../common/constants'; + +export function getCoreUsageCollector( + usageCollection: UsageCollectionSetup, + getCoreTelemetry: () => CoreTelemetryStart +) { + return usageCollection.makeUsageCollector({ + type: 'core', + isReady: () => true, + schema: { + config: { + elasticsearch: { + sniffOnStart: { type: 'boolean' }, + sniffIntervalMs: { type: 'long' }, + sniffOnConnectionFault: { type: 'boolean' }, + numberOfHostsConfigured: { type: 'long' }, + requestHeadersWhitelistConfigured: { type: 'boolean' }, + customHeadersConfigured: { type: 'boolean' }, + shardTimeoutMs: { type: 'long' }, + requestTimeoutMs: { type: 'long' }, + pingTimeoutMs: { type: 'long' }, + logQueries: { type: 'boolean' }, + ssl: { + verificationMode: { type: 'keyword' }, + certificateAuthoritiesConfigured: { type: 'boolean' }, + certificateConfigured: { type: 'boolean' }, + keyConfigured: { type: 'boolean' }, + keystoreConfigured: { type: 'boolean' }, + truststoreConfigured: { type: 'boolean' }, + alwaysPresentCertificate: { type: 'boolean' }, + }, + apiVersion: { type: 'keyword' }, + healthCheckDelayMs: { type: 'long' }, + }, + + http: { + basePathConfigured: { type: 'boolean' }, + maxPayloadInBytes: { type: 'long' }, + rewriteBasePath: { type: 'boolean' }, + keepaliveTimeout: { type: 'long' }, + socketTimeout: { type: 'long' }, + compression: { + enabled: { type: 'boolean' }, + referrerWhitelistConfigured: { type: 'boolean' }, + }, + xsrf: { + disableProtection: { type: 'boolean' }, + whitelistConfigured: { type: 'boolean' }, + }, + requestId: { + allowFromAnyIp: { type: 'boolean' }, + ipAllowlistConfigured: { type: 'boolean' }, + }, + ssl: { + certificateAuthoritiesConfigured: { type: 'boolean' }, + certificateConfigured: { type: 'boolean' }, + cipherSuites: { type: 'array', items: { type: 'keyword' } }, + keyConfigured: { type: 'boolean' }, + keystoreConfigured: { type: 'boolean' }, + truststoreConfigured: { type: 'boolean' }, + redirectHttpFromPortConfigured: { type: 'boolean' }, + supportedProtocols: { type: 'array', items: { type: 'keyword' } }, + clientAuthentication: { type: 'keyword' }, + }, + }, + + logging: { + appendersTypesUsed: { type: 'array', items: { type: 'keyword' } }, + loggersConfiguredCount: { type: 'long' }, + }, + + savedObjects: { + maxImportPayloadBytes: { type: 'long' }, + maxImportExportSizeBytes: { type: 'long' }, + }, + }, + environment: { + memory: { + heapSizeLimit: { type: 'long' }, + heapTotalBytes: { type: 'long' }, + heapUsedBytes: { type: 'long' }, + }, + os: { + distro: { type: 'keyword' }, + distroRelease: { type: 'keyword' }, + platform: { type: 'keyword' }, + platformRelease: { type: 'keyword' }, + }, + }, + }, + fetch() { + return new Promise((resolve, reject) => { + const result = getCoreTelemetry().getCoreTelemetry(); + if (result == null) { + reject(new Error('Unable to collect Core telemetry')); + } else { + resolve(result); + } + }); + }, + + /* + * Format the response data into a model for internal upload + * 1. Make this data part of the "kibana_stats" type + * 2. Organize the payload in the usage namespace of the data payload (usage.index, etc) + */ + formatForBulkUpload: (result) => { + return { + type: KIBANA_STATS_TYPE, + payload: { + core: result, + }, + }; + }, + }); +} + +export function registerCoreUsageCollector( + usageCollection: UsageCollectionSetup, + getCoreTelemetry: () => CoreTelemetryStart +) { + usageCollection.registerCollector(getCoreUsageCollector(usageCollection, getCoreTelemetry)); +} diff --git a/src/plugins/kibana_usage_collection/server/collectors/core/index.test.ts b/src/plugins/kibana_usage_collection/server/collectors/core/index.test.ts new file mode 100644 index 0000000000000..62db760509e1f --- /dev/null +++ b/src/plugins/kibana_usage_collection/server/collectors/core/index.test.ts @@ -0,0 +1,62 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { + CollectorOptions, + createUsageCollectionSetupMock, +} from '../../../../usage_collection/server/usage_collection.mock'; + +import { registerCoreUsageCollector } from '.'; +import { coreTelemetryServiceMock } from '../../../../../core/server/mocks'; +import { CoreTelemetry } from 'src/core/server'; + +describe('telemetry_core', () => { + let collector: CollectorOptions; + + const usageCollectionMock = createUsageCollectionSetupMock(); + usageCollectionMock.makeUsageCollector.mockImplementation((config) => { + collector = config; + return createUsageCollectionSetupMock().makeUsageCollector(config); + }); + + const callCluster = jest.fn().mockImplementation(() => ({})); + const coreTelemetryStart = coreTelemetryServiceMock.createStartContract(); + const getCoreTelemetryReturnValue = (Symbol('core telemetry') as any) as CoreTelemetry; + coreTelemetryStart.getCoreTelemetry.mockReturnValue(getCoreTelemetryReturnValue); + + beforeAll(() => registerCoreUsageCollector(usageCollectionMock, () => coreTelemetryStart)); + + test('registered collector is set', () => { + expect(collector).not.toBeUndefined(); + expect(collector.type).toBe('core'); + }); + + test('fetch', async () => { + expect(await collector.fetch(callCluster)).toEqual(getCoreTelemetryReturnValue); + }); + + test('formatForBulkUpload', async () => { + expect(collector.formatForBulkUpload!(getCoreTelemetryReturnValue)).toStrictEqual({ + type: 'kibana_stats', + payload: { + core: getCoreTelemetryReturnValue, + }, + }); + }); +}); diff --git a/src/plugins/kibana_usage_collection/server/collectors/core/index.ts b/src/plugins/kibana_usage_collection/server/collectors/core/index.ts new file mode 100644 index 0000000000000..79a4b83b41355 --- /dev/null +++ b/src/plugins/kibana_usage_collection/server/collectors/core/index.ts @@ -0,0 +1,20 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export { registerCoreUsageCollector } from './core_usage_collector'; diff --git a/src/plugins/kibana_usage_collection/server/collectors/index.ts b/src/plugins/kibana_usage_collection/server/collectors/index.ts index 1f9fe130fa45d..2408dc84c2e56 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/index.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/index.ts @@ -23,3 +23,4 @@ export { registerApplicationUsageCollector } from './application_usage'; export { registerKibanaUsageCollector } from './kibana'; export { registerOpsStatsCollector } from './ops_stats'; export { registerCspCollector } from './csp'; +export { registerCoreUsageCollector } from './core'; diff --git a/src/plugins/kibana_usage_collection/server/plugin.ts b/src/plugins/kibana_usage_collection/server/plugin.ts index 260acd19ab516..379964242fc27 100644 --- a/src/plugins/kibana_usage_collection/server/plugin.ts +++ b/src/plugins/kibana_usage_collection/server/plugin.ts @@ -31,6 +31,7 @@ import { SavedObjectsServiceSetup, OpsMetrics, Logger, + CoreTelemetryStart, } from '../../../core/server'; import { registerApplicationUsageCollector, @@ -39,6 +40,7 @@ import { registerOpsStatsCollector, registerUiMetricUsageCollector, registerCspCollector, + registerCoreUsageCollector, } from './collectors'; interface KibanaUsageCollectionPluginsDepsSetup { @@ -53,6 +55,7 @@ export class KibanaUsageCollectionPlugin implements Plugin { private savedObjectsClient?: ISavedObjectsRepository; private uiSettingsClient?: IUiSettingsClient; private metric$: Subject; + private coreTelemetry?: CoreTelemetryStart; constructor(initializerContext: PluginInitializerContext) { this.logger = initializerContext.logger.get(); @@ -72,6 +75,7 @@ export class KibanaUsageCollectionPlugin implements Plugin { const savedObjectsClient = new SavedObjectsClient(this.savedObjectsClient); this.uiSettingsClient = uiSettings.asScopedToClient(savedObjectsClient); core.metrics.getOpsMetrics$().subscribe(this.metric$); + this.coreTelemetry = core.coreTelemetry; } public stop() { @@ -86,6 +90,7 @@ export class KibanaUsageCollectionPlugin implements Plugin { ) { const getSavedObjectsClient = () => this.savedObjectsClient; const getUiSettingsClient = () => this.uiSettingsClient; + const getCoreTelemetry = () => this.coreTelemetry!; registerOpsStatsCollector(usageCollection, metric$); registerKibanaUsageCollector(usageCollection, this.legacyConfig$); @@ -98,5 +103,6 @@ export class KibanaUsageCollectionPlugin implements Plugin { getSavedObjectsClient ); registerCspCollector(usageCollection, coreSetup.http); + registerCoreUsageCollector(usageCollection, getCoreTelemetry); } } From 9c5be45c3e1ec2df20e0a339c14402cf507a6c84 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Thu, 1 Oct 2020 20:41:36 +0200 Subject: [PATCH 05/18] HttpConfig path is 'server' --- src/core/server/telemetry/telemetry_service.test.ts | 2 +- src/core/server/telemetry/telemetry_service.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/server/telemetry/telemetry_service.test.ts b/src/core/server/telemetry/telemetry_service.test.ts index b792f95138ee8..9f888384c234f 100644 --- a/src/core/server/telemetry/telemetry_service.test.ts +++ b/src/core/server/telemetry/telemetry_service.test.ts @@ -43,7 +43,7 @@ describe('CoreTelemetryService', () => { configService.atPath.mockImplementation((path) => { if (path === 'elasticsearch') { return new BehaviorSubject(RawElasticsearchConfig.schema.validate({})); - } else if (path === 'http') { + } else if (path === 'server') { return new BehaviorSubject(RawHttpConfig.schema.validate({})); } else if (path === 'logging') { return new BehaviorSubject(RawLoggingConfig.schema.validate({})); diff --git a/src/core/server/telemetry/telemetry_service.ts b/src/core/server/telemetry/telemetry_service.ts index a8a7c67407b92..0d3c3b1edc093 100644 --- a/src/core/server/telemetry/telemetry_service.ts +++ b/src/core/server/telemetry/telemetry_service.ts @@ -177,7 +177,7 @@ export class CoreTelemetryService implements CoreService('http') + .atPath('server') .pipe(takeUntil(this.stop$)) .subscribe((config) => { this.httpConfig = config; From fd290e0c9a6ae6e91702667c32e1a139f550b9ee Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Thu, 1 Oct 2020 20:46:55 +0200 Subject: [PATCH 06/18] Fix tests --- .../server/__snapshots__/index.test.ts.snap | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/plugins/kibana_usage_collection/server/__snapshots__/index.test.ts.snap b/src/plugins/kibana_usage_collection/server/__snapshots__/index.test.ts.snap index 47a4c458a8398..1c6f87275f00f 100644 --- a/src/plugins/kibana_usage_collection/server/__snapshots__/index.test.ts.snap +++ b/src/plugins/kibana_usage_collection/server/__snapshots__/index.test.ts.snap @@ -11,3 +11,5 @@ exports[`kibana_usage_collection Runs the setup method without issues 4`] = `fal exports[`kibana_usage_collection Runs the setup method without issues 5`] = `false`; exports[`kibana_usage_collection Runs the setup method without issues 6`] = `true`; + +exports[`kibana_usage_collection Runs the setup method without issues 7`] = `true`; From 0a8339915e5fb04aeccb9327391e8912a6a1a52a Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Thu, 1 Oct 2020 23:02:15 +0200 Subject: [PATCH 07/18] CoreTelemetry -> CoreUsageData --- ...in-core-server.corestart.coreusagedata.md} | 8 +++--- .../kibana-plugin-core-server.corestart.md | 2 +- ...plugin-core-server.coretelemetry.config.md | 11 -------- ...n-core-server.coretelemetry.environment.md | 11 -------- ...kibana-plugin-core-server.coretelemetry.md | 19 -------------- ...plugin-core-server.coreusagedata.config.md | 11 ++++++++ ...n-core-server.coreusagedata.environment.md | 11 ++++++++ ...kibana-plugin-core-server.coreusagedata.md | 19 ++++++++++++++ ...-plugin-core-server.coreusagedatastart.md} | 6 ++--- .../core/server/kibana-plugin-core-server.md | 4 +-- .../core_usage_data_service.mock.ts} | 14 +++++----- .../core_usage_data_service.test.ts} | 18 ++++++------- .../core_usage_data_service.ts} | 14 +++++----- .../{telemetry => core_usage_data}/index.ts | 4 +-- .../is_configured.test.ts | 0 .../is_configured.ts | 2 +- .../{telemetry => core_usage_data}/types.ts | 26 +++++++++---------- src/core/server/index.ts | 8 +++--- src/core/server/internal_types.ts | 4 +-- src/core/server/legacy/legacy_service.ts | 6 ++--- src/core/server/mocks.ts | 8 +++--- src/core/server/plugins/plugin_context.ts | 2 +- src/core/server/server.api.md | 20 +++++++------- src/core/server/server.ts | 12 ++++----- .../collectors/core/core_usage_collector.ts | 12 ++++----- .../server/collectors/core/index.test.ts | 18 ++++++------- .../kibana_usage_collection/server/plugin.ts | 10 +++---- 27 files changed, 140 insertions(+), 140 deletions(-) rename docs/development/core/server/{kibana-plugin-core-server.corestart.coretelemetry.md => kibana-plugin-core-server.corestart.coreusagedata.md} (53%) delete mode 100644 docs/development/core/server/kibana-plugin-core-server.coretelemetry.config.md delete mode 100644 docs/development/core/server/kibana-plugin-core-server.coretelemetry.environment.md delete mode 100644 docs/development/core/server/kibana-plugin-core-server.coretelemetry.md create mode 100644 docs/development/core/server/kibana-plugin-core-server.coreusagedata.config.md create mode 100644 docs/development/core/server/kibana-plugin-core-server.coreusagedata.environment.md create mode 100644 docs/development/core/server/kibana-plugin-core-server.coreusagedata.md rename docs/development/core/server/{kibana-plugin-core-server.coretelemetrystart.md => kibana-plugin-core-server.coreusagedatastart.md} (52%) rename src/core/server/{telemetry/telemetry_service.mock.ts => core_usage_data/core_usage_data_service.mock.ts} (91%) rename src/core/server/{telemetry/telemetry_service.test.ts => core_usage_data/core_usage_data_service.test.ts} (94%) rename src/core/server/{telemetry/telemetry_service.ts => core_usage_data/core_usage_data_service.ts} (95%) rename src/core/server/{telemetry => core_usage_data}/index.ts (86%) rename src/core/server/{telemetry => core_usage_data}/is_configured.test.ts (100%) rename src/core/server/{telemetry => core_usage_data}/is_configured.ts (98%) rename src/core/server/{telemetry => core_usage_data}/types.ts (84%) diff --git a/docs/development/core/server/kibana-plugin-core-server.corestart.coretelemetry.md b/docs/development/core/server/kibana-plugin-core-server.corestart.coreusagedata.md similarity index 53% rename from docs/development/core/server/kibana-plugin-core-server.corestart.coretelemetry.md rename to docs/development/core/server/kibana-plugin-core-server.corestart.coreusagedata.md index 51d170565e0ee..bbcc238ce0e87 100644 --- a/docs/development/core/server/kibana-plugin-core-server.corestart.coretelemetry.md +++ b/docs/development/core/server/kibana-plugin-core-server.corestart.coreusagedata.md @@ -1,13 +1,13 @@ -[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreStart](./kibana-plugin-core-server.corestart.md) > [coreTelemetry](./kibana-plugin-core-server.corestart.coretelemetry.md) +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreStart](./kibana-plugin-core-server.corestart.md) > [coreUsageData](./kibana-plugin-core-server.corestart.coreusagedata.md) -## CoreStart.coreTelemetry property +## CoreStart.coreUsageData property -[CoreTelemetryStart](./kibana-plugin-core-server.coretelemetrystart.md) +[CoreUsageDataStart](./kibana-plugin-core-server.coreusagedatastart.md) Signature: ```typescript -coreTelemetry: CoreTelemetryStart; +coreUsageData: CoreUsageDataStart; ``` diff --git a/docs/development/core/server/kibana-plugin-core-server.corestart.md b/docs/development/core/server/kibana-plugin-core-server.corestart.md index 42054e458c501..66f972d500db0 100644 --- a/docs/development/core/server/kibana-plugin-core-server.corestart.md +++ b/docs/development/core/server/kibana-plugin-core-server.corestart.md @@ -18,7 +18,7 @@ export interface CoreStart | --- | --- | --- | | [auditTrail](./kibana-plugin-core-server.corestart.audittrail.md) | AuditTrailStart | [AuditTrailSetup](./kibana-plugin-core-server.audittrailsetup.md) | | [capabilities](./kibana-plugin-core-server.corestart.capabilities.md) | CapabilitiesStart | [CapabilitiesStart](./kibana-plugin-core-server.capabilitiesstart.md) | -| [coreTelemetry](./kibana-plugin-core-server.corestart.coretelemetry.md) | CoreTelemetryStart | [CoreTelemetryStart](./kibana-plugin-core-server.coretelemetrystart.md) | +| [coreUsageData](./kibana-plugin-core-server.corestart.coreusagedata.md) | CoreUsageDataStart | [CoreUsageDataStart](./kibana-plugin-core-server.coreusagedatastart.md) | | [elasticsearch](./kibana-plugin-core-server.corestart.elasticsearch.md) | ElasticsearchServiceStart | [ElasticsearchServiceStart](./kibana-plugin-core-server.elasticsearchservicestart.md) | | [http](./kibana-plugin-core-server.corestart.http.md) | HttpServiceStart | [HttpServiceStart](./kibana-plugin-core-server.httpservicestart.md) | | [metrics](./kibana-plugin-core-server.corestart.metrics.md) | MetricsServiceStart | [MetricsServiceStart](./kibana-plugin-core-server.metricsservicestart.md) | diff --git a/docs/development/core/server/kibana-plugin-core-server.coretelemetry.config.md b/docs/development/core/server/kibana-plugin-core-server.coretelemetry.config.md deleted file mode 100644 index d0aaaf736e1a5..0000000000000 --- a/docs/development/core/server/kibana-plugin-core-server.coretelemetry.config.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreTelemetry](./kibana-plugin-core-server.coretelemetry.md) > [config](./kibana-plugin-core-server.coretelemetry.config.md) - -## CoreTelemetry.config property - -Signature: - -```typescript -config: CoreConfigTelemetry; -``` diff --git a/docs/development/core/server/kibana-plugin-core-server.coretelemetry.environment.md b/docs/development/core/server/kibana-plugin-core-server.coretelemetry.environment.md deleted file mode 100644 index cb0da8267b6cb..0000000000000 --- a/docs/development/core/server/kibana-plugin-core-server.coretelemetry.environment.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreTelemetry](./kibana-plugin-core-server.coretelemetry.md) > [environment](./kibana-plugin-core-server.coretelemetry.environment.md) - -## CoreTelemetry.environment property - -Signature: - -```typescript -environment: CoreEnvironmentTelemetry; -``` diff --git a/docs/development/core/server/kibana-plugin-core-server.coretelemetry.md b/docs/development/core/server/kibana-plugin-core-server.coretelemetry.md deleted file mode 100644 index a8cf3fb976c5f..0000000000000 --- a/docs/development/core/server/kibana-plugin-core-server.coretelemetry.md +++ /dev/null @@ -1,19 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreTelemetry](./kibana-plugin-core-server.coretelemetry.md) - -## CoreTelemetry interface - -Signature: - -```typescript -export interface CoreTelemetry -``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [config](./kibana-plugin-core-server.coretelemetry.config.md) | CoreConfigTelemetry | | -| [environment](./kibana-plugin-core-server.coretelemetry.environment.md) | CoreEnvironmentTelemetry | | - diff --git a/docs/development/core/server/kibana-plugin-core-server.coreusagedata.config.md b/docs/development/core/server/kibana-plugin-core-server.coreusagedata.config.md new file mode 100644 index 0000000000000..237cc16c9412a --- /dev/null +++ b/docs/development/core/server/kibana-plugin-core-server.coreusagedata.config.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreUsageData](./kibana-plugin-core-server.coreusagedata.md) > [config](./kibana-plugin-core-server.coreusagedata.config.md) + +## CoreUsageData.config property + +Signature: + +```typescript +config: CoreConfigUsageData; +``` diff --git a/docs/development/core/server/kibana-plugin-core-server.coreusagedata.environment.md b/docs/development/core/server/kibana-plugin-core-server.coreusagedata.environment.md new file mode 100644 index 0000000000000..b1d651144c7a1 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-core-server.coreusagedata.environment.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreUsageData](./kibana-plugin-core-server.coreusagedata.md) > [environment](./kibana-plugin-core-server.coreusagedata.environment.md) + +## CoreUsageData.environment property + +Signature: + +```typescript +environment: CoreEnvironmentUsageData; +``` diff --git a/docs/development/core/server/kibana-plugin-core-server.coreusagedata.md b/docs/development/core/server/kibana-plugin-core-server.coreusagedata.md new file mode 100644 index 0000000000000..f490fdf754201 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-core-server.coreusagedata.md @@ -0,0 +1,19 @@ + + +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreUsageData](./kibana-plugin-core-server.coreusagedata.md) + +## CoreUsageData interface + +Signature: + +```typescript +export interface CoreUsageData +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [config](./kibana-plugin-core-server.coreusagedata.config.md) | CoreConfigUsageData | | +| [environment](./kibana-plugin-core-server.coreusagedata.environment.md) | CoreEnvironmentUsageData | | + diff --git a/docs/development/core/server/kibana-plugin-core-server.coretelemetrystart.md b/docs/development/core/server/kibana-plugin-core-server.coreusagedatastart.md similarity index 52% rename from docs/development/core/server/kibana-plugin-core-server.coretelemetrystart.md rename to docs/development/core/server/kibana-plugin-core-server.coreusagedatastart.md index 5892587ca6a56..1ad5d25e2cf06 100644 --- a/docs/development/core/server/kibana-plugin-core-server.coretelemetrystart.md +++ b/docs/development/core/server/kibana-plugin-core-server.coreusagedatastart.md @@ -1,11 +1,11 @@ -[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreTelemetryStart](./kibana-plugin-core-server.coretelemetrystart.md) +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreUsageDataStart](./kibana-plugin-core-server.coreusagedatastart.md) -## CoreTelemetryStart interface +## CoreUsageDataStart interface Signature: ```typescript -export interface CoreTelemetryStart +export interface CoreUsageDataStart ``` diff --git a/docs/development/core/server/kibana-plugin-core-server.md b/docs/development/core/server/kibana-plugin-core-server.md index d7b4221cf4072..9c5b7b65d6011 100644 --- a/docs/development/core/server/kibana-plugin-core-server.md +++ b/docs/development/core/server/kibana-plugin-core-server.md @@ -70,8 +70,8 @@ The plugin integrates with the core system via lifecycle events: `setup` | [CoreSetup](./kibana-plugin-core-server.coresetup.md) | Context passed to the plugins setup method. | | [CoreStart](./kibana-plugin-core-server.corestart.md) | Context passed to the plugins start method. | | [CoreStatus](./kibana-plugin-core-server.corestatus.md) | Status of core services. | -| [CoreTelemetry](./kibana-plugin-core-server.coretelemetry.md) | | -| [CoreTelemetryStart](./kibana-plugin-core-server.coretelemetrystart.md) | | +| [CoreUsageData](./kibana-plugin-core-server.coreusagedata.md) | | +| [CoreUsageDataStart](./kibana-plugin-core-server.coreusagedatastart.md) | | | [CountResponse](./kibana-plugin-core-server.countresponse.md) | | | [CustomHttpResponseOptions](./kibana-plugin-core-server.customhttpresponseoptions.md) | HTTP response parameters for a response with adjustable status code. | | [DeleteDocumentResponse](./kibana-plugin-core-server.deletedocumentresponse.md) | | diff --git a/src/core/server/telemetry/telemetry_service.mock.ts b/src/core/server/core_usage_data/core_usage_data_service.mock.ts similarity index 91% rename from src/core/server/telemetry/telemetry_service.mock.ts rename to src/core/server/core_usage_data/core_usage_data_service.mock.ts index 1dafa941bdca1..02d4a456b7219 100644 --- a/src/core/server/telemetry/telemetry_service.mock.ts +++ b/src/core/server/core_usage_data/core_usage_data_service.mock.ts @@ -19,13 +19,13 @@ import { PublicMethodsOf } from '@kbn/utility-types'; import { BehaviorSubject } from 'rxjs'; -import { CoreTelemetryService } from './telemetry_service'; -import { CoreTelemetry, CoreTelemetryStart } from './types'; +import { CoreUsageDataService } from './core_usage_data_service'; +import { CoreUsageData, CoreUsageDataStart } from './types'; const createStartContractMock = () => { - const startContract: jest.Mocked = { - getCoreTelemetry: jest.fn().mockReturnValue( - new BehaviorSubject({ + const startContract: jest.Mocked = { + getCoreUsageData: jest.fn().mockReturnValue( + new BehaviorSubject({ config: { elasticsearch: { apiVersion: 'master', @@ -130,7 +130,7 @@ const createStartContractMock = () => { }; const createMock = () => { - const mocked: jest.Mocked> = { + const mocked: jest.Mocked> = { setup: jest.fn(), start: jest.fn().mockReturnValue(createStartContractMock()), stop: jest.fn(), @@ -138,7 +138,7 @@ const createMock = () => { return mocked; }; -export const coreTelemetryServiceMock = { +export const coreUsageDataServiceMock = { create: createMock, createStartContract: createStartContractMock, }; diff --git a/src/core/server/telemetry/telemetry_service.test.ts b/src/core/server/core_usage_data/core_usage_data_service.test.ts similarity index 94% rename from src/core/server/telemetry/telemetry_service.test.ts rename to src/core/server/core_usage_data/core_usage_data_service.test.ts index 9f888384c234f..515377fd8a205 100644 --- a/src/core/server/telemetry/telemetry_service.test.ts +++ b/src/core/server/core_usage_data/core_usage_data_service.test.ts @@ -30,15 +30,15 @@ import { config as RawLoggingConfig } from '../logging/logging_config'; import { savedObjectsConfig as RawSavedObjectsConfig } from '../saved_objects/saved_objects_config'; import { metricsServiceMock } from '../metrics/metrics_service.mock'; -import { CoreTelemetryService } from './telemetry_service'; +import { CoreUsageDataService } from './core_usage_data_service'; -describe('CoreTelemetryService', () => { +describe('CoreUsageDataService', () => { const getTestScheduler = () => new TestScheduler((actual, expected) => { expect(actual).toEqual(expected); }); - let service: CoreTelemetryService; + let service: CoreUsageDataService; const configService = configServiceMock.create(); configService.atPath.mockImplementation((path) => { if (path === 'elasticsearch') { @@ -55,24 +55,24 @@ describe('CoreTelemetryService', () => { const coreContext = mockCoreContext.create({ configService }); beforeEach(() => { - service = new CoreTelemetryService(coreContext); + service = new CoreUsageDataService(coreContext); }); describe('start', () => { - describe('getCoreTelemetry', () => { + describe('getCoreUsageData', () => { it('returns null if an exception occurs', () => { const metrics = metricsServiceMock.createInternalSetupContract(); metrics.getOpsMetrics$.mockReturnValueOnce(new BehaviorSubject({} as any)); service.setup({ metrics }); - const { getCoreTelemetry } = service.start(); - expect(getCoreTelemetry()).toEqual(null); + const { getCoreUsageData } = service.start(); + expect(getCoreUsageData()).toEqual(null); }); it('returns core metrics for default config', () => { const metrics = metricsServiceMock.createInternalSetupContract(); service.setup({ metrics }); - const { getCoreTelemetry } = service.start(); - expect(getCoreTelemetry()).toMatchInlineSnapshot(` + const { getCoreUsageData } = service.start(); + expect(getCoreUsageData()).toMatchInlineSnapshot(` Object { "config": Object { "elasticsearch": Object { diff --git a/src/core/server/telemetry/telemetry_service.ts b/src/core/server/core_usage_data/core_usage_data_service.ts similarity index 95% rename from src/core/server/telemetry/telemetry_service.ts rename to src/core/server/core_usage_data/core_usage_data_service.ts index 0d3c3b1edc093..585d5f0f0b62e 100644 --- a/src/core/server/telemetry/telemetry_service.ts +++ b/src/core/server/core_usage_data/core_usage_data_service.ts @@ -26,7 +26,7 @@ import { ElasticsearchConfigType } from '../elasticsearch/elasticsearch_config'; import { HttpConfigType } from '../http'; import { Logger, LoggingConfigType } from '../logging'; import { SavedObjectsConfigType } from '../saved_objects/saved_objects_config'; -import { CoreTelemetry, CoreTelemetryStart } from './types'; +import { CoreUsageData, CoreUsageDataStart } from './types'; import { SavedObjectsService } from '../saved_objects'; import { isConfigured } from './is_configured'; import { MetricsServiceSetup, OpsMetrics } from '..'; @@ -39,7 +39,7 @@ export interface StartDeps { savedObjectsService: SavedObjectsService; } -export class CoreTelemetryService implements CoreService { +export class CoreUsageDataService implements CoreService { private readonly log: Logger; private elasticsearchConfig?: ElasticsearchConfigType; private configService: CoreContext['configService']; @@ -50,12 +50,12 @@ export class CoreTelemetryService implements CoreService { + getCoreUsageData: () => { try { - return this.getCoreTelemetry(); + return this.getCoreUsageData(); } catch (e) { - this.log.error('Error collecting core telemetry', e); + this.log.error('Error collecting core usage data', e); return null; } }, diff --git a/src/core/server/telemetry/index.ts b/src/core/server/core_usage_data/index.ts similarity index 86% rename from src/core/server/telemetry/index.ts rename to src/core/server/core_usage_data/index.ts index d265cd67c5586..76541991c2a05 100644 --- a/src/core/server/telemetry/index.ts +++ b/src/core/server/core_usage_data/index.ts @@ -16,5 +16,5 @@ * specific language governing permissions and limitations * under the License. */ -export { CoreTelemetryStart, CoreTelemetry } from './types'; -export { CoreTelemetryService } from './telemetry_service'; +export { CoreUsageDataStart, CoreUsageData } from './types'; +export { CoreUsageDataService } from './core_usage_data_service'; diff --git a/src/core/server/telemetry/is_configured.test.ts b/src/core/server/core_usage_data/is_configured.test.ts similarity index 100% rename from src/core/server/telemetry/is_configured.test.ts rename to src/core/server/core_usage_data/is_configured.test.ts diff --git a/src/core/server/telemetry/is_configured.ts b/src/core/server/core_usage_data/is_configured.ts similarity index 98% rename from src/core/server/telemetry/is_configured.ts rename to src/core/server/core_usage_data/is_configured.ts index 07e63854ef57d..22af53e86a462 100644 --- a/src/core/server/telemetry/is_configured.ts +++ b/src/core/server/core_usage_data/is_configured.ts @@ -24,7 +24,7 @@ import { isEqual } from 'lodash'; * Our configuration schema and code often accept and ignore empty values like * `elasticsearch.customHeaders: {}`. However, for telemetry purposes, we're * only interested when these values have been set to something that will - * change the behaivour of Kibana. + * change the behaviour of Kibana. */ export const isConfigured = { /** diff --git a/src/core/server/telemetry/types.ts b/src/core/server/core_usage_data/types.ts similarity index 84% rename from src/core/server/telemetry/types.ts rename to src/core/server/core_usage_data/types.ts index 06d466fe37e6e..fdfb1bd827659 100644 --- a/src/core/server/telemetry/types.ts +++ b/src/core/server/core_usage_data/types.ts @@ -17,16 +17,16 @@ * under the License. */ -export interface CoreTelemetry { - config: CoreConfigTelemetry; - // usage: CoreUsageTelemetry; - environment: CoreEnvironmentTelemetry; +export interface CoreUsageData { + config: CoreConfigUsageData; + // services: CoreServicesUsageData; + environment: CoreEnvironmentUsageData; } /** - * Telemetry data on this cluster's usage of Core features + * Usage data from Core services */ -export interface CoreUsageTelemetry { +export interface CoreServicesUsageData { savedObjects: { totalCount: number; typesCount: number; @@ -34,9 +34,9 @@ export interface CoreUsageTelemetry { } /** - * Telemetry data on this Kibana node's runtime environment. + * Usage data on this Kibana node's runtime environment. */ -export interface CoreEnvironmentTelemetry { +export interface CoreEnvironmentUsageData { memory: { heapTotalBytes: number; heapUsedBytes: number; @@ -52,9 +52,9 @@ export interface CoreEnvironmentTelemetry { } /** - * Telemetry data on this cluster's configuration of Core features + * Usage data on this cluster's configuration of Core features */ -export interface CoreConfigTelemetry { +export interface CoreConfigUsageData { elasticsearch: { sniffOnStart: boolean; sniffIntervalMs?: number; @@ -132,10 +132,10 @@ export interface CoreConfigTelemetry { // }; } -export interface CoreTelemetryStart { +export interface CoreUsageDataStart { /** - * Internal API for collecting Core telemetry data + * Internal API for collecting Core usage data * @internal * */ - getCoreTelemetry(): CoreTelemetry | null; + getCoreUsageData(): CoreUsageData | null; } diff --git a/src/core/server/index.ts b/src/core/server/index.ts index 5f711720c85f9..ee1f9a4e815aa 100644 --- a/src/core/server/index.ts +++ b/src/core/server/index.ts @@ -64,7 +64,7 @@ import { MetricsServiceSetup, MetricsServiceStart } from './metrics'; import { StatusServiceSetup } from './status'; import { Auditor, AuditTrailSetup, AuditTrailStart } from './audit_trail'; import { AppenderConfigType, appendersSchema, LoggingServiceSetup } from './logging'; -import { CoreTelemetryStart } from './telemetry'; +import { CoreUsageDataStart } from './core_usage_data'; export { AuditableEvent, Auditor, AuditorFactory, AuditTrailSetup } from './audit_trail'; export { bootstrap } from './bootstrap'; @@ -350,7 +350,7 @@ export { StatusServiceSetup, } from './status'; -export { CoreTelemetryStart, CoreTelemetry } from './telemetry'; +export { CoreUsageDataStart, CoreUsageData } from './core_usage_data'; /** * Plugin specific context passed to a route handler. @@ -459,8 +459,8 @@ export interface CoreStart { uiSettings: UiSettingsServiceStart; /** {@link AuditTrailSetup} */ auditTrail: AuditTrailStart; - /** {@link CoreTelemetryStart} */ - coreTelemetry: CoreTelemetryStart; + /** {@link CoreUsageDataStart} */ + coreUsageData: CoreUsageDataStart; } export { diff --git a/src/core/server/internal_types.ts b/src/core/server/internal_types.ts index 0d5d72508c280..ce58348a14153 100644 --- a/src/core/server/internal_types.ts +++ b/src/core/server/internal_types.ts @@ -39,7 +39,7 @@ import { InternalHttpResourcesSetup } from './http_resources'; import { InternalStatusServiceSetup } from './status'; import { AuditTrailSetup, AuditTrailStart } from './audit_trail'; import { InternalLoggingServiceSetup } from './logging'; -import { CoreTelemetryStart } from './telemetry'; +import { CoreUsageDataStart } from './core_usage_data'; /** @internal */ export interface InternalCoreSetup { @@ -69,7 +69,7 @@ export interface InternalCoreStart { savedObjects: InternalSavedObjectsServiceStart; uiSettings: InternalUiSettingsServiceStart; auditTrail: AuditTrailStart; - coreTelemetry: CoreTelemetryStart; + coreUsageData: CoreUsageDataStart; } /** diff --git a/src/core/server/legacy/legacy_service.ts b/src/core/server/legacy/legacy_service.ts index ba6f237737e5a..75e8ae6524920 100644 --- a/src/core/server/legacy/legacy_service.ts +++ b/src/core/server/legacy/legacy_service.ts @@ -217,9 +217,9 @@ export class LegacyService implements CoreService { }, uiSettings: { asScopedToClient: startDeps.core.uiSettings.asScopedToClient }, auditTrail: startDeps.core.auditTrail, - coreTelemetry: { - getCoreTelemetry: () => { - throw new Error('core.start.coreTelemetry.getCoreTelemetry is unsupported in legacy'); + coreUsageData: { + getCoreUsageData: () => { + throw new Error('core.start.coreUsageData.getCoreUsageData is unsupported in legacy'); }, }, }; diff --git a/src/core/server/mocks.ts b/src/core/server/mocks.ts index 61e17ffe1078a..34e85920efb24 100644 --- a/src/core/server/mocks.ts +++ b/src/core/server/mocks.ts @@ -37,7 +37,7 @@ import { metricsServiceMock } from './metrics/metrics_service.mock'; import { environmentServiceMock } from './environment/environment_service.mock'; import { statusServiceMock } from './status/status_service.mock'; import { auditTrailServiceMock } from './audit_trail/audit_trail_service.mock'; -import { coreTelemetryServiceMock } from './telemetry/telemetry_service.mock'; +import { coreUsageDataServiceMock } from './core_usage_data/core_usage_data_service.mock'; export { configServiceMock } from './config/mocks'; export { httpServerMock } from './http/http_server.mocks'; @@ -56,7 +56,7 @@ export { renderingMock } from './rendering/rendering_service.mock'; export { statusServiceMock } from './status/status_service.mock'; export { contextServiceMock } from './context/context_service.mock'; export { capabilitiesServiceMock } from './capabilities/capabilities_service.mock'; -export { coreTelemetryServiceMock } from './telemetry/telemetry_service.mock'; +export { coreUsageDataServiceMock } from './core_usage_data/core_usage_data_service.mock'; export function pluginInitializerContextConfigMock(config: T) { const globalConfig: SharedGlobalConfig = { @@ -159,7 +159,7 @@ function createCoreStartMock() { metrics: metricsServiceMock.createStartContract(), savedObjects: savedObjectsServiceMock.createStartContract(), uiSettings: uiSettingsServiceMock.createStartContract(), - coreTelemetry: coreTelemetryServiceMock.createStartContract(), + coreUsageData: coreUsageDataServiceMock.createStartContract(), }; return mock; @@ -193,7 +193,7 @@ function createInternalCoreStartMock() { savedObjects: savedObjectsServiceMock.createInternalStartContract(), uiSettings: uiSettingsServiceMock.createStartContract(), auditTrail: auditTrailServiceMock.createStartContract(), - coreTelemetry: coreTelemetryServiceMock.createStartContract(), + coreUsageData: coreUsageDataServiceMock.createStartContract(), }; return startDeps; } diff --git a/src/core/server/plugins/plugin_context.ts b/src/core/server/plugins/plugin_context.ts index 73d19744e4e94..a8249ed7e3218 100644 --- a/src/core/server/plugins/plugin_context.ts +++ b/src/core/server/plugins/plugin_context.ts @@ -251,6 +251,6 @@ export function createPluginStartContext( asScopedToClient: deps.uiSettings.asScopedToClient, }, auditTrail: deps.auditTrail, - coreTelemetry: deps.coreTelemetry, + coreUsageData: deps.coreUsageData, }; } diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index 71fd60212f32a..0f12e90990c61 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -439,7 +439,7 @@ export interface CoreStart { // (undocumented) capabilities: CapabilitiesStart; // (undocumented) - coreTelemetry: CoreTelemetryStart; + coreUsageData: CoreUsageDataStart; // (undocumented) elasticsearch: ElasticsearchServiceStart; // (undocumented) @@ -460,26 +460,26 @@ export interface CoreStatus { savedObjects: ServiceStatus; } -// Warning: (ae-missing-release-tag) "CoreTelemetry" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// Warning: (ae-missing-release-tag) "CoreUsageData" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -export interface CoreTelemetry { - // Warning: (ae-forgotten-export) The symbol "CoreConfigTelemetry" needs to be exported by the entry point index.d.ts +export interface CoreUsageData { + // Warning: (ae-forgotten-export) The symbol "CoreConfigUsageData" needs to be exported by the entry point index.d.ts // // (undocumented) - config: CoreConfigTelemetry; - // Warning: (ae-forgotten-export) The symbol "CoreEnvironmentTelemetry" needs to be exported by the entry point index.d.ts + config: CoreConfigUsageData; + // Warning: (ae-forgotten-export) The symbol "CoreEnvironmentUsageData" needs to be exported by the entry point index.d.ts // // (undocumented) - environment: CoreEnvironmentTelemetry; + environment: CoreEnvironmentUsageData; } -// Warning: (ae-missing-release-tag) "CoreTelemetryStart" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// Warning: (ae-missing-release-tag) "CoreUsageDataStart" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -export interface CoreTelemetryStart { +export interface CoreUsageDataStart { // @internal - getCoreTelemetry(): CoreTelemetry | null; + getCoreUsageData(): CoreUsageData | null; } // @public (undocumented) diff --git a/src/core/server/server.ts b/src/core/server/server.ts index 081eb8e28a09b..b3f9cf3250436 100644 --- a/src/core/server/server.ts +++ b/src/core/server/server.ts @@ -48,7 +48,7 @@ import { config as statusConfig } from './status'; import { ContextService } from './context'; import { RequestHandlerContext } from '.'; import { InternalCoreSetup, InternalCoreStart, ServiceConfigDescriptor } from './internal_types'; -import { CoreTelemetryService } from './telemetry'; +import { CoreUsageDataService } from './core_usage_data'; import { CoreRouteHandlerContext } from './core_route_handler_context'; const coreId = Symbol('core'); @@ -73,7 +73,7 @@ export class Server { private readonly logging: LoggingService; private readonly coreApp: CoreApp; private readonly auditTrail: AuditTrailService; - private readonly coreTelemetry: CoreTelemetryService; + private readonly coreUsageData: CoreUsageDataService; #pluginsInitialized?: boolean; private coreStart?: InternalCoreStart; @@ -105,7 +105,7 @@ export class Server { this.httpResources = new HttpResourcesService(core); this.auditTrail = new AuditTrailService(core); this.logging = new LoggingService(core); - this.coreTelemetry = new CoreTelemetryService(core); + this.coreUsageData = new CoreUsageDataService(core); } public async setup() { @@ -184,7 +184,7 @@ export class Server { loggingSystem: this.loggingSystem, }); - this.coreTelemetry.setup({ metrics: metricsSetup }); + this.coreUsageData.setup({ metrics: metricsSetup }); const coreSetup: InternalCoreSetup = { capabilities: capabilitiesSetup, @@ -237,7 +237,7 @@ export class Server { const uiSettingsStart = await this.uiSettings.start(); const metricsStart = await this.metrics.start(); const httpStart = this.http.getStartContract(); - const coreTelemetryStart = this.coreTelemetry.start(); + const coreUsageDataStart = this.coreUsageData.start(); this.coreStart = { capabilities: capabilitiesStart, @@ -247,7 +247,7 @@ export class Server { savedObjects: savedObjectsStart, uiSettings: uiSettingsStart, auditTrail: auditTrailStart, - coreTelemetry: coreTelemetryStart, + coreUsageData: coreUsageDataStart, }; const pluginsStart = await this.plugins.start(this.coreStart); diff --git a/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts b/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts index bb6edf48cd24f..07cd9fb1c1ef9 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts @@ -17,15 +17,15 @@ * under the License. */ -import { CoreTelemetry, CoreTelemetryStart } from 'src/core/server'; +import { CoreUsageData, CoreUsageDataStart } from 'src/core/server'; import { UsageCollectionSetup } from 'src/plugins/usage_collection/server'; import { KIBANA_STATS_TYPE } from '../../../common/constants'; export function getCoreUsageCollector( usageCollection: UsageCollectionSetup, - getCoreTelemetry: () => CoreTelemetryStart + getCoreUsageData: () => CoreUsageDataStart ) { - return usageCollection.makeUsageCollector({ + return usageCollection.makeUsageCollector({ type: 'core', isReady: () => true, schema: { @@ -111,7 +111,7 @@ export function getCoreUsageCollector( }, fetch() { return new Promise((resolve, reject) => { - const result = getCoreTelemetry().getCoreTelemetry(); + const result = getCoreUsageData().getCoreUsageData(); if (result == null) { reject(new Error('Unable to collect Core telemetry')); } else { @@ -138,7 +138,7 @@ export function getCoreUsageCollector( export function registerCoreUsageCollector( usageCollection: UsageCollectionSetup, - getCoreTelemetry: () => CoreTelemetryStart + getCoreUsageData: () => CoreUsageDataStart ) { - usageCollection.registerCollector(getCoreUsageCollector(usageCollection, getCoreTelemetry)); + usageCollection.registerCollector(getCoreUsageCollector(usageCollection, getCoreUsageData)); } diff --git a/src/plugins/kibana_usage_collection/server/collectors/core/index.test.ts b/src/plugins/kibana_usage_collection/server/collectors/core/index.test.ts index 62db760509e1f..07683dd703430 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/core/index.test.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/core/index.test.ts @@ -23,8 +23,8 @@ import { } from '../../../../usage_collection/server/usage_collection.mock'; import { registerCoreUsageCollector } from '.'; -import { coreTelemetryServiceMock } from '../../../../../core/server/mocks'; -import { CoreTelemetry } from 'src/core/server'; +import { coreUsageDataServiceMock } from '../../../../../core/server/mocks'; +import { CoreUsageData } from 'src/core/server'; describe('telemetry_core', () => { let collector: CollectorOptions; @@ -36,11 +36,11 @@ describe('telemetry_core', () => { }); const callCluster = jest.fn().mockImplementation(() => ({})); - const coreTelemetryStart = coreTelemetryServiceMock.createStartContract(); - const getCoreTelemetryReturnValue = (Symbol('core telemetry') as any) as CoreTelemetry; - coreTelemetryStart.getCoreTelemetry.mockReturnValue(getCoreTelemetryReturnValue); + const coreUsageDataStart = coreUsageDataServiceMock.createStartContract(); + const getCoreUsageDataReturnValue = (Symbol('core telemetry') as any) as CoreUsageData; + coreUsageDataStart.getCoreUsageData.mockReturnValue(getCoreUsageDataReturnValue); - beforeAll(() => registerCoreUsageCollector(usageCollectionMock, () => coreTelemetryStart)); + beforeAll(() => registerCoreUsageCollector(usageCollectionMock, () => coreUsageDataStart)); test('registered collector is set', () => { expect(collector).not.toBeUndefined(); @@ -48,14 +48,14 @@ describe('telemetry_core', () => { }); test('fetch', async () => { - expect(await collector.fetch(callCluster)).toEqual(getCoreTelemetryReturnValue); + expect(await collector.fetch(callCluster)).toEqual(getCoreUsageDataReturnValue); }); test('formatForBulkUpload', async () => { - expect(collector.formatForBulkUpload!(getCoreTelemetryReturnValue)).toStrictEqual({ + expect(collector.formatForBulkUpload!(getCoreUsageDataReturnValue)).toStrictEqual({ type: 'kibana_stats', payload: { - core: getCoreTelemetryReturnValue, + core: getCoreUsageDataReturnValue, }, }); }); diff --git a/src/plugins/kibana_usage_collection/server/plugin.ts b/src/plugins/kibana_usage_collection/server/plugin.ts index 379964242fc27..98fc785a1e047 100644 --- a/src/plugins/kibana_usage_collection/server/plugin.ts +++ b/src/plugins/kibana_usage_collection/server/plugin.ts @@ -31,7 +31,7 @@ import { SavedObjectsServiceSetup, OpsMetrics, Logger, - CoreTelemetryStart, + CoreUsageDataStart, } from '../../../core/server'; import { registerApplicationUsageCollector, @@ -55,7 +55,7 @@ export class KibanaUsageCollectionPlugin implements Plugin { private savedObjectsClient?: ISavedObjectsRepository; private uiSettingsClient?: IUiSettingsClient; private metric$: Subject; - private coreTelemetry?: CoreTelemetryStart; + private coreUsageData?: CoreUsageDataStart; constructor(initializerContext: PluginInitializerContext) { this.logger = initializerContext.logger.get(); @@ -75,7 +75,7 @@ export class KibanaUsageCollectionPlugin implements Plugin { const savedObjectsClient = new SavedObjectsClient(this.savedObjectsClient); this.uiSettingsClient = uiSettings.asScopedToClient(savedObjectsClient); core.metrics.getOpsMetrics$().subscribe(this.metric$); - this.coreTelemetry = core.coreTelemetry; + this.coreUsageData = core.coreUsageData; } public stop() { @@ -90,7 +90,7 @@ export class KibanaUsageCollectionPlugin implements Plugin { ) { const getSavedObjectsClient = () => this.savedObjectsClient; const getUiSettingsClient = () => this.uiSettingsClient; - const getCoreTelemetry = () => this.coreTelemetry!; + const getcoreUsageData = () => this.coreUsageData!; registerOpsStatsCollector(usageCollection, metric$); registerKibanaUsageCollector(usageCollection, this.legacyConfig$); @@ -103,6 +103,6 @@ export class KibanaUsageCollectionPlugin implements Plugin { getSavedObjectsClient ); registerCspCollector(usageCollection, coreSetup.http); - registerCoreUsageCollector(usageCollection, getCoreTelemetry); + registerCoreUsageCollector(usageCollection, getcoreUsageData); } } From aa2ef677c59f64991bce88ad54583f3d3fff45fc Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Fri, 2 Oct 2020 09:23:03 +0200 Subject: [PATCH 08/18] Improve tests / docs --- ...gin-core-server.corestart.coreusagedata.md | 1 - .../kibana-plugin-core-server.corestart.md | 2 +- ...plugin-core-server.coreusagedata.config.md | 11 ----------- ...n-core-server.coreusagedata.environment.md | 11 ----------- ...kibana-plugin-core-server.coreusagedata.md | 19 ------------------- ...a-plugin-core-server.coreusagedatastart.md | 11 ----------- .../core/server/kibana-plugin-core-server.md | 2 -- src/core/server/core_usage_data/index.ts | 7 ++++++- .../core_usage_data/is_configured.test.ts | 6 ++++++ .../server/core_usage_data/is_configured.ts | 2 +- src/core/server/core_usage_data/types.ts | 8 ++++++++ src/core/server/server.api.md | 11 ++++------- 12 files changed, 26 insertions(+), 65 deletions(-) delete mode 100644 docs/development/core/server/kibana-plugin-core-server.coreusagedata.config.md delete mode 100644 docs/development/core/server/kibana-plugin-core-server.coreusagedata.environment.md delete mode 100644 docs/development/core/server/kibana-plugin-core-server.coreusagedata.md delete mode 100644 docs/development/core/server/kibana-plugin-core-server.coreusagedatastart.md diff --git a/docs/development/core/server/kibana-plugin-core-server.corestart.coreusagedata.md b/docs/development/core/server/kibana-plugin-core-server.corestart.coreusagedata.md index bbcc238ce0e87..f214975d7b90c 100644 --- a/docs/development/core/server/kibana-plugin-core-server.corestart.coreusagedata.md +++ b/docs/development/core/server/kibana-plugin-core-server.corestart.coreusagedata.md @@ -4,7 +4,6 @@ ## CoreStart.coreUsageData property -[CoreUsageDataStart](./kibana-plugin-core-server.coreusagedatastart.md) Signature: diff --git a/docs/development/core/server/kibana-plugin-core-server.corestart.md b/docs/development/core/server/kibana-plugin-core-server.corestart.md index 66f972d500db0..7f47034911822 100644 --- a/docs/development/core/server/kibana-plugin-core-server.corestart.md +++ b/docs/development/core/server/kibana-plugin-core-server.corestart.md @@ -18,7 +18,7 @@ export interface CoreStart | --- | --- | --- | | [auditTrail](./kibana-plugin-core-server.corestart.audittrail.md) | AuditTrailStart | [AuditTrailSetup](./kibana-plugin-core-server.audittrailsetup.md) | | [capabilities](./kibana-plugin-core-server.corestart.capabilities.md) | CapabilitiesStart | [CapabilitiesStart](./kibana-plugin-core-server.capabilitiesstart.md) | -| [coreUsageData](./kibana-plugin-core-server.corestart.coreusagedata.md) | CoreUsageDataStart | [CoreUsageDataStart](./kibana-plugin-core-server.coreusagedatastart.md) | +| [coreUsageData](./kibana-plugin-core-server.corestart.coreusagedata.md) | CoreUsageDataStart | | | [elasticsearch](./kibana-plugin-core-server.corestart.elasticsearch.md) | ElasticsearchServiceStart | [ElasticsearchServiceStart](./kibana-plugin-core-server.elasticsearchservicestart.md) | | [http](./kibana-plugin-core-server.corestart.http.md) | HttpServiceStart | [HttpServiceStart](./kibana-plugin-core-server.httpservicestart.md) | | [metrics](./kibana-plugin-core-server.corestart.metrics.md) | MetricsServiceStart | [MetricsServiceStart](./kibana-plugin-core-server.metricsservicestart.md) | diff --git a/docs/development/core/server/kibana-plugin-core-server.coreusagedata.config.md b/docs/development/core/server/kibana-plugin-core-server.coreusagedata.config.md deleted file mode 100644 index 237cc16c9412a..0000000000000 --- a/docs/development/core/server/kibana-plugin-core-server.coreusagedata.config.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreUsageData](./kibana-plugin-core-server.coreusagedata.md) > [config](./kibana-plugin-core-server.coreusagedata.config.md) - -## CoreUsageData.config property - -Signature: - -```typescript -config: CoreConfigUsageData; -``` diff --git a/docs/development/core/server/kibana-plugin-core-server.coreusagedata.environment.md b/docs/development/core/server/kibana-plugin-core-server.coreusagedata.environment.md deleted file mode 100644 index b1d651144c7a1..0000000000000 --- a/docs/development/core/server/kibana-plugin-core-server.coreusagedata.environment.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreUsageData](./kibana-plugin-core-server.coreusagedata.md) > [environment](./kibana-plugin-core-server.coreusagedata.environment.md) - -## CoreUsageData.environment property - -Signature: - -```typescript -environment: CoreEnvironmentUsageData; -``` diff --git a/docs/development/core/server/kibana-plugin-core-server.coreusagedata.md b/docs/development/core/server/kibana-plugin-core-server.coreusagedata.md deleted file mode 100644 index f490fdf754201..0000000000000 --- a/docs/development/core/server/kibana-plugin-core-server.coreusagedata.md +++ /dev/null @@ -1,19 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreUsageData](./kibana-plugin-core-server.coreusagedata.md) - -## CoreUsageData interface - -Signature: - -```typescript -export interface CoreUsageData -``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [config](./kibana-plugin-core-server.coreusagedata.config.md) | CoreConfigUsageData | | -| [environment](./kibana-plugin-core-server.coreusagedata.environment.md) | CoreEnvironmentUsageData | | - diff --git a/docs/development/core/server/kibana-plugin-core-server.coreusagedatastart.md b/docs/development/core/server/kibana-plugin-core-server.coreusagedatastart.md deleted file mode 100644 index 1ad5d25e2cf06..0000000000000 --- a/docs/development/core/server/kibana-plugin-core-server.coreusagedatastart.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreUsageDataStart](./kibana-plugin-core-server.coreusagedatastart.md) - -## CoreUsageDataStart interface - -Signature: - -```typescript -export interface CoreUsageDataStart -``` diff --git a/docs/development/core/server/kibana-plugin-core-server.md b/docs/development/core/server/kibana-plugin-core-server.md index 9c5b7b65d6011..be8b7c27495ad 100644 --- a/docs/development/core/server/kibana-plugin-core-server.md +++ b/docs/development/core/server/kibana-plugin-core-server.md @@ -70,8 +70,6 @@ The plugin integrates with the core system via lifecycle events: `setup` | [CoreSetup](./kibana-plugin-core-server.coresetup.md) | Context passed to the plugins setup method. | | [CoreStart](./kibana-plugin-core-server.corestart.md) | Context passed to the plugins start method. | | [CoreStatus](./kibana-plugin-core-server.corestatus.md) | Status of core services. | -| [CoreUsageData](./kibana-plugin-core-server.coreusagedata.md) | | -| [CoreUsageDataStart](./kibana-plugin-core-server.coreusagedatastart.md) | | | [CountResponse](./kibana-plugin-core-server.countresponse.md) | | | [CustomHttpResponseOptions](./kibana-plugin-core-server.customhttpresponseoptions.md) | HTTP response parameters for a response with adjustable status code. | | [DeleteDocumentResponse](./kibana-plugin-core-server.deletedocumentresponse.md) | | diff --git a/src/core/server/core_usage_data/index.ts b/src/core/server/core_usage_data/index.ts index 76541991c2a05..87e5654e57f05 100644 --- a/src/core/server/core_usage_data/index.ts +++ b/src/core/server/core_usage_data/index.ts @@ -16,5 +16,10 @@ * specific language governing permissions and limitations * under the License. */ -export { CoreUsageDataStart, CoreUsageData } from './types'; +export { + CoreUsageDataStart, + CoreUsageData, + CoreConfigUsageData, + CoreEnvironmentUsageData, +} from './types'; export { CoreUsageDataService } from './core_usage_data_service'; diff --git a/src/core/server/core_usage_data/is_configured.test.ts b/src/core/server/core_usage_data/is_configured.test.ts index cfb436e38d737..eed981560e51d 100644 --- a/src/core/server/core_usage_data/is_configured.test.ts +++ b/src/core/server/core_usage_data/is_configured.test.ts @@ -101,6 +101,12 @@ describe('isConfigured', () => { it('returns false for an empty record', () => { expect(isConfigured.record({})).toEqual(false); }); + it('returns false for undefined', () => { + expect(isConfigured.record(undefined)).toEqual(false); + }); + it('returns false for null', () => { + expect(isConfigured.record(null)).toEqual(false); + }); }); describe('number', () => { diff --git a/src/core/server/core_usage_data/is_configured.ts b/src/core/server/core_usage_data/is_configured.ts index 22af53e86a462..e66f990f1037c 100644 --- a/src/core/server/core_usage_data/is_configured.ts +++ b/src/core/server/core_usage_data/is_configured.ts @@ -53,7 +53,7 @@ export const isConfigured = { * config is a record with at least one key */ record: (config?: Record): boolean => { - return typeof config === 'object' && Object.keys(config).length > 0; + return config != null && typeof config === 'object' && Object.keys(config).length > 0; }, /** * config is a number diff --git a/src/core/server/core_usage_data/types.ts b/src/core/server/core_usage_data/types.ts index fdfb1bd827659..12cb0226e8758 100644 --- a/src/core/server/core_usage_data/types.ts +++ b/src/core/server/core_usage_data/types.ts @@ -17,6 +17,10 @@ * under the License. */ +/** + * Type describing Core's usage data payload + * @internal + */ export interface CoreUsageData { config: CoreConfigUsageData; // services: CoreServicesUsageData; @@ -132,6 +136,10 @@ export interface CoreConfigUsageData { // }; } +/** + * Internal API for getting Core's usage data payload + * @internal + */ export interface CoreUsageDataStart { /** * Internal API for collecting Core usage data diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index 0f12e90990c61..77af677b56c18 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -438,6 +438,8 @@ export interface CoreStart { auditTrail: AuditTrailStart; // (undocumented) capabilities: CapabilitiesStart; + // Warning: (ae-incompatible-release-tags) The symbol "coreUsageData" is marked as @public, but its signature references "CoreUsageDataStart" which is marked as @internal + // // (undocumented) coreUsageData: CoreUsageDataStart; // (undocumented) @@ -460,9 +462,7 @@ export interface CoreStatus { savedObjects: ServiceStatus; } -// Warning: (ae-missing-release-tag) "CoreUsageData" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public (undocumented) +// @internal export interface CoreUsageData { // Warning: (ae-forgotten-export) The symbol "CoreConfigUsageData" needs to be exported by the entry point index.d.ts // @@ -474,11 +474,8 @@ export interface CoreUsageData { environment: CoreEnvironmentUsageData; } -// Warning: (ae-missing-release-tag) "CoreUsageDataStart" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public (undocumented) +// @internal export interface CoreUsageDataStart { - // @internal getCoreUsageData(): CoreUsageData | null; } From a508a0a9639a21969472ecafcf56040ecd60d744 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Fri, 2 Oct 2020 09:24:51 +0200 Subject: [PATCH 09/18] Fix telemetry_check --- .../server/collectors/core/core_usage_collector.ts | 8 +++++++- .../server/collectors/core/index.test.ts | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts b/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts index 07cd9fb1c1ef9..f221e93f2e876 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts @@ -17,8 +17,14 @@ * under the License. */ -import { CoreUsageData, CoreUsageDataStart } from 'src/core/server'; import { UsageCollectionSetup } from 'src/plugins/usage_collection/server'; +import { + CoreUsageData, + CoreUsageDataStart, + // eslint-disable-next-line @kbn/eslint/no-restricted-paths +} from '../../../../../core/server/core_usage_data/types'; +// telemetry_check is unable to check types which are re-exported, it only +// works when pointed to the typescript file where the type was defined. import { KIBANA_STATS_TYPE } from '../../../common/constants'; export function getCoreUsageCollector( diff --git a/src/plugins/kibana_usage_collection/server/collectors/core/index.test.ts b/src/plugins/kibana_usage_collection/server/collectors/core/index.test.ts index 07683dd703430..30686da81a354 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/core/index.test.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/core/index.test.ts @@ -24,7 +24,7 @@ import { import { registerCoreUsageCollector } from '.'; import { coreUsageDataServiceMock } from '../../../../../core/server/mocks'; -import { CoreUsageData } from 'src/core/server'; +import { CoreUsageData } from 'src/core/server/'; describe('telemetry_core', () => { let collector: CollectorOptions; From dbee8f915b3f0d55ca86ec4b75ca9c5bf4ebe3ef Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Fri, 2 Oct 2020 10:12:12 +0200 Subject: [PATCH 10/18] Don't catch fetch function exceptions, let usage collector handle it --- ...lugin-core-server.corestart.coreusagedata.md | 12 ------------ .../kibana-plugin-core-server.corestart.md | 1 - .../core_usage_data_service.test.ts | 8 -------- .../core_usage_data/core_usage_data_service.ts | 11 ++--------- .../core_usage_data/is_configured.test.ts | 2 +- src/core/server/index.ts | 2 +- src/core/server/server.api.md | 4 +--- .../collectors/core/core_usage_collector.ts | 17 ++++++----------- 8 files changed, 11 insertions(+), 46 deletions(-) delete mode 100644 docs/development/core/server/kibana-plugin-core-server.corestart.coreusagedata.md diff --git a/docs/development/core/server/kibana-plugin-core-server.corestart.coreusagedata.md b/docs/development/core/server/kibana-plugin-core-server.corestart.coreusagedata.md deleted file mode 100644 index f214975d7b90c..0000000000000 --- a/docs/development/core/server/kibana-plugin-core-server.corestart.coreusagedata.md +++ /dev/null @@ -1,12 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreStart](./kibana-plugin-core-server.corestart.md) > [coreUsageData](./kibana-plugin-core-server.corestart.coreusagedata.md) - -## CoreStart.coreUsageData property - - -Signature: - -```typescript -coreUsageData: CoreUsageDataStart; -``` diff --git a/docs/development/core/server/kibana-plugin-core-server.corestart.md b/docs/development/core/server/kibana-plugin-core-server.corestart.md index 7f47034911822..0d5474fae5e16 100644 --- a/docs/development/core/server/kibana-plugin-core-server.corestart.md +++ b/docs/development/core/server/kibana-plugin-core-server.corestart.md @@ -18,7 +18,6 @@ export interface CoreStart | --- | --- | --- | | [auditTrail](./kibana-plugin-core-server.corestart.audittrail.md) | AuditTrailStart | [AuditTrailSetup](./kibana-plugin-core-server.audittrailsetup.md) | | [capabilities](./kibana-plugin-core-server.corestart.capabilities.md) | CapabilitiesStart | [CapabilitiesStart](./kibana-plugin-core-server.capabilitiesstart.md) | -| [coreUsageData](./kibana-plugin-core-server.corestart.coreusagedata.md) | CoreUsageDataStart | | | [elasticsearch](./kibana-plugin-core-server.corestart.elasticsearch.md) | ElasticsearchServiceStart | [ElasticsearchServiceStart](./kibana-plugin-core-server.elasticsearchservicestart.md) | | [http](./kibana-plugin-core-server.corestart.http.md) | HttpServiceStart | [HttpServiceStart](./kibana-plugin-core-server.httpservicestart.md) | | [metrics](./kibana-plugin-core-server.corestart.metrics.md) | MetricsServiceStart | [MetricsServiceStart](./kibana-plugin-core-server.metricsservicestart.md) | diff --git a/src/core/server/core_usage_data/core_usage_data_service.test.ts b/src/core/server/core_usage_data/core_usage_data_service.test.ts index 515377fd8a205..9ecb970ef4e9b 100644 --- a/src/core/server/core_usage_data/core_usage_data_service.test.ts +++ b/src/core/server/core_usage_data/core_usage_data_service.test.ts @@ -60,14 +60,6 @@ describe('CoreUsageDataService', () => { describe('start', () => { describe('getCoreUsageData', () => { - it('returns null if an exception occurs', () => { - const metrics = metricsServiceMock.createInternalSetupContract(); - metrics.getOpsMetrics$.mockReturnValueOnce(new BehaviorSubject({} as any)); - service.setup({ metrics }); - const { getCoreUsageData } = service.start(); - expect(getCoreUsageData()).toEqual(null); - }); - it('returns core metrics for default config', () => { const metrics = metricsServiceMock.createInternalSetupContract(); service.setup({ metrics }); diff --git a/src/core/server/core_usage_data/core_usage_data_service.ts b/src/core/server/core_usage_data/core_usage_data_service.ts index 585d5f0f0b62e..7bfc391fdeddc 100644 --- a/src/core/server/core_usage_data/core_usage_data_service.ts +++ b/src/core/server/core_usage_data/core_usage_data_service.ts @@ -24,7 +24,7 @@ import { CoreService } from 'src/core/types'; import { CoreContext } from '../core_context'; import { ElasticsearchConfigType } from '../elasticsearch/elasticsearch_config'; import { HttpConfigType } from '../http'; -import { Logger, LoggingConfigType } from '../logging'; +import { LoggingConfigType } from '../logging'; import { SavedObjectsConfigType } from '../saved_objects/saved_objects_config'; import { CoreUsageData, CoreUsageDataStart } from './types'; import { SavedObjectsService } from '../saved_objects'; @@ -40,7 +40,6 @@ export interface StartDeps { } export class CoreUsageDataService implements CoreService { - private readonly log: Logger; private elasticsearchConfig?: ElasticsearchConfigType; private configService: CoreContext['configService']; private httpConfig?: HttpConfigType; @@ -50,7 +49,6 @@ export class CoreUsageDataService implements CoreService { - try { - return this.getCoreUsageData(); - } catch (e) { - this.log.error('Error collecting core usage data', e); - return null; - } + return this.getCoreUsageData(); }, }; } diff --git a/src/core/server/core_usage_data/is_configured.test.ts b/src/core/server/core_usage_data/is_configured.test.ts index eed981560e51d..e5d04946b8766 100644 --- a/src/core/server/core_usage_data/is_configured.test.ts +++ b/src/core/server/core_usage_data/is_configured.test.ts @@ -105,7 +105,7 @@ describe('isConfigured', () => { expect(isConfigured.record(undefined)).toEqual(false); }); it('returns false for null', () => { - expect(isConfigured.record(null)).toEqual(false); + expect(isConfigured.record(null as any)).toEqual(false); }); }); diff --git a/src/core/server/index.ts b/src/core/server/index.ts index ee1f9a4e815aa..823623600e4c0 100644 --- a/src/core/server/index.ts +++ b/src/core/server/index.ts @@ -459,7 +459,7 @@ export interface CoreStart { uiSettings: UiSettingsServiceStart; /** {@link AuditTrailSetup} */ auditTrail: AuditTrailStart; - /** {@link CoreUsageDataStart} */ + /** @internal {@link CoreUsageDataStart} */ coreUsageData: CoreUsageDataStart; } diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index 77af677b56c18..482b9dc9f74f0 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -438,9 +438,7 @@ export interface CoreStart { auditTrail: AuditTrailStart; // (undocumented) capabilities: CapabilitiesStart; - // Warning: (ae-incompatible-release-tags) The symbol "coreUsageData" is marked as @public, but its signature references "CoreUsageDataStart" which is marked as @internal - // - // (undocumented) + // @internal (undocumented) coreUsageData: CoreUsageDataStart; // (undocumented) elasticsearch: ElasticsearchServiceStart; diff --git a/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts b/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts index f221e93f2e876..daf7cde0b94f0 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts @@ -29,7 +29,7 @@ import { KIBANA_STATS_TYPE } from '../../../common/constants'; export function getCoreUsageCollector( usageCollection: UsageCollectionSetup, - getCoreUsageData: () => CoreUsageDataStart + getCoreUsageDataService: () => CoreUsageDataStart ) { return usageCollection.makeUsageCollector({ type: 'core', @@ -116,14 +116,7 @@ export function getCoreUsageCollector( }, }, fetch() { - return new Promise((resolve, reject) => { - const result = getCoreUsageData().getCoreUsageData(); - if (result == null) { - reject(new Error('Unable to collect Core telemetry')); - } else { - resolve(result); - } - }); + return getCoreUsageDataService().getCoreUsageData(); }, /* @@ -144,7 +137,9 @@ export function getCoreUsageCollector( export function registerCoreUsageCollector( usageCollection: UsageCollectionSetup, - getCoreUsageData: () => CoreUsageDataStart + getCoreUsageDataService: () => CoreUsageDataStart ) { - usageCollection.registerCollector(getCoreUsageCollector(usageCollection, getCoreUsageData)); + usageCollection.registerCollector( + getCoreUsageCollector(usageCollection, getCoreUsageDataService) + ); } From 4de37e22011a6b357fbe70d67ec68ec770106942 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Fri, 2 Oct 2020 13:48:31 +0200 Subject: [PATCH 11/18] Code review --- src/core/server/core_usage_data/types.ts | 2 +- .../collectors/core/core_usage_collector.ts | 15 --------------- .../server/collectors/core/index.test.ts | 9 --------- .../kibana_usage_collection/server/plugin.ts | 4 ++-- 4 files changed, 3 insertions(+), 27 deletions(-) diff --git a/src/core/server/core_usage_data/types.ts b/src/core/server/core_usage_data/types.ts index 12cb0226e8758..4e3ef842f47fc 100644 --- a/src/core/server/core_usage_data/types.ts +++ b/src/core/server/core_usage_data/types.ts @@ -145,5 +145,5 @@ export interface CoreUsageDataStart { * Internal API for collecting Core usage data * @internal * */ - getCoreUsageData(): CoreUsageData | null; + getCoreUsageData(): CoreUsageData; } diff --git a/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts b/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts index daf7cde0b94f0..566c02b91746d 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts @@ -25,7 +25,6 @@ import { } from '../../../../../core/server/core_usage_data/types'; // telemetry_check is unable to check types which are re-exported, it only // works when pointed to the typescript file where the type was defined. -import { KIBANA_STATS_TYPE } from '../../../common/constants'; export function getCoreUsageCollector( usageCollection: UsageCollectionSetup, @@ -118,20 +117,6 @@ export function getCoreUsageCollector( fetch() { return getCoreUsageDataService().getCoreUsageData(); }, - - /* - * Format the response data into a model for internal upload - * 1. Make this data part of the "kibana_stats" type - * 2. Organize the payload in the usage namespace of the data payload (usage.index, etc) - */ - formatForBulkUpload: (result) => { - return { - type: KIBANA_STATS_TYPE, - payload: { - core: result, - }, - }; - }, }); } diff --git a/src/plugins/kibana_usage_collection/server/collectors/core/index.test.ts b/src/plugins/kibana_usage_collection/server/collectors/core/index.test.ts index 30686da81a354..22ab21f9dc11e 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/core/index.test.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/core/index.test.ts @@ -50,13 +50,4 @@ describe('telemetry_core', () => { test('fetch', async () => { expect(await collector.fetch(callCluster)).toEqual(getCoreUsageDataReturnValue); }); - - test('formatForBulkUpload', async () => { - expect(collector.formatForBulkUpload!(getCoreUsageDataReturnValue)).toStrictEqual({ - type: 'kibana_stats', - payload: { - core: getCoreUsageDataReturnValue, - }, - }); - }); }); diff --git a/src/plugins/kibana_usage_collection/server/plugin.ts b/src/plugins/kibana_usage_collection/server/plugin.ts index 98fc785a1e047..198fdbb7a8703 100644 --- a/src/plugins/kibana_usage_collection/server/plugin.ts +++ b/src/plugins/kibana_usage_collection/server/plugin.ts @@ -90,7 +90,7 @@ export class KibanaUsageCollectionPlugin implements Plugin { ) { const getSavedObjectsClient = () => this.savedObjectsClient; const getUiSettingsClient = () => this.uiSettingsClient; - const getcoreUsageData = () => this.coreUsageData!; + const getCoreUsageDataService = () => this.coreUsageData!; registerOpsStatsCollector(usageCollection, metric$); registerKibanaUsageCollector(usageCollection, this.legacyConfig$); @@ -103,6 +103,6 @@ export class KibanaUsageCollectionPlugin implements Plugin { getSavedObjectsClient ); registerCspCollector(usageCollection, coreSetup.http); - registerCoreUsageCollector(usageCollection, getcoreUsageData); + registerCoreUsageCollector(usageCollection, getCoreUsageDataService); } } From 65954a60bf1130820ca054d3bb72716f732626fb Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Fri, 2 Oct 2020 14:25:47 +0200 Subject: [PATCH 12/18] Collect saved object index usage data --- .../core_usage_data_service.mock.ts | 15 +++- .../core_usage_data_service.test.ts | 11 ++- .../core_usage_data_service.ts | 78 +++++++++++++++++-- src/core/server/core_usage_data/types.ts | 13 +++- src/core/server/server.api.md | 6 +- src/core/server/server.ts | 5 +- .../collectors/core/core_usage_collector.ts | 14 ++++ .../server/collectors/core/index.test.ts | 2 +- 8 files changed, 129 insertions(+), 15 deletions(-) diff --git a/src/core/server/core_usage_data/core_usage_data_service.mock.ts b/src/core/server/core_usage_data/core_usage_data_service.mock.ts index 02d4a456b7219..f59d172ef32f1 100644 --- a/src/core/server/core_usage_data/core_usage_data_service.mock.ts +++ b/src/core/server/core_usage_data/core_usage_data_service.mock.ts @@ -24,7 +24,7 @@ import { CoreUsageData, CoreUsageDataStart } from './types'; const createStartContractMock = () => { const startContract: jest.Mocked = { - getCoreUsageData: jest.fn().mockReturnValue( + getCoreUsageData: jest.fn().mockResolvedValue( new BehaviorSubject({ config: { elasticsearch: { @@ -122,6 +122,19 @@ const createStartContractMock = () => { platformRelease: 'test', }, }, + services: { + savedObjects: { + indices: [ + { + docsCount: 1, + docsDeleted: 1, + name: 'test_index', + primaryStoreSizeBytes: 1, + storeSizeBytes: 1, + }, + ], + }, + }, }) ), }; diff --git a/src/core/server/core_usage_data/core_usage_data_service.test.ts b/src/core/server/core_usage_data/core_usage_data_service.test.ts index 9ecb970ef4e9b..6f6e036a5780a 100644 --- a/src/core/server/core_usage_data/core_usage_data_service.test.ts +++ b/src/core/server/core_usage_data/core_usage_data_service.test.ts @@ -27,10 +27,13 @@ import { mockCoreContext } from '../core_context.mock'; import { config as RawElasticsearchConfig } from '../elasticsearch/elasticsearch_config'; import { config as RawHttpConfig } from '../http/http_config'; import { config as RawLoggingConfig } from '../logging/logging_config'; +import { config as RawKibanaConfig } from '../kibana_config'; import { savedObjectsConfig as RawSavedObjectsConfig } from '../saved_objects/saved_objects_config'; import { metricsServiceMock } from '../metrics/metrics_service.mock'; +import { savedObjectsServiceMock } from '../saved_objects/saved_objects_service.mock'; import { CoreUsageDataService } from './core_usage_data_service'; +import { elasticsearchServiceMock } from '../elasticsearch/elasticsearch_service.mock'; describe('CoreUsageDataService', () => { const getTestScheduler = () => @@ -49,6 +52,8 @@ describe('CoreUsageDataService', () => { return new BehaviorSubject(RawLoggingConfig.schema.validate({})); } else if (path === 'savedObjects') { return new BehaviorSubject(RawSavedObjectsConfig.schema.validate({})); + } else if (path === 'kibana') { + return new BehaviorSubject(RawKibanaConfig.schema.validate({})); } return new BehaviorSubject({}); }); @@ -63,7 +68,11 @@ describe('CoreUsageDataService', () => { it('returns core metrics for default config', () => { const metrics = metricsServiceMock.createInternalSetupContract(); service.setup({ metrics }); - const { getCoreUsageData } = service.start(); + + const { getCoreUsageData } = service.start({ + savedObjects: savedObjectsServiceMock.createInternalStartContract(), + elasticsearch: elasticsearchServiceMock.createStart(), + }); expect(getCoreUsageData()).toMatchInlineSnapshot(` Object { "config": Object { diff --git a/src/core/server/core_usage_data/core_usage_data_service.ts b/src/core/server/core_usage_data/core_usage_data_service.ts index 7bfc391fdeddc..3c98b828818a3 100644 --- a/src/core/server/core_usage_data/core_usage_data_service.ts +++ b/src/core/server/core_usage_data/core_usage_data_service.ts @@ -21,14 +21,16 @@ import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; import { CoreService } from 'src/core/types'; +import { SavedObjectsServiceStart } from 'src/core/server'; import { CoreContext } from '../core_context'; import { ElasticsearchConfigType } from '../elasticsearch/elasticsearch_config'; import { HttpConfigType } from '../http'; import { LoggingConfigType } from '../logging'; import { SavedObjectsConfigType } from '../saved_objects/saved_objects_config'; -import { CoreUsageData, CoreUsageDataStart } from './types'; -import { SavedObjectsService } from '../saved_objects'; +import { CoreServicesUsageData, CoreUsageData, CoreUsageDataStart } from './types'; import { isConfigured } from './is_configured'; +import { ElasticsearchServiceStart } from '../elasticsearch'; +import { KibanaConfigType } from '../kibana_config'; import { MetricsServiceSetup, OpsMetrics } from '..'; export interface SetupDeps { @@ -36,7 +38,8 @@ export interface SetupDeps { } export interface StartDeps { - savedObjectsService: SavedObjectsService; + savedObjects: SavedObjectsServiceStart; + elasticsearch: ElasticsearchServiceStart; } export class CoreUsageDataService implements CoreService { @@ -47,13 +50,63 @@ export class CoreUsageDataService implements CoreService; private opsMetrics?: OpsMetrics; + private kibanaConfig?: KibanaConfigType; constructor(core: CoreContext) { this.configService = core.configService; this.stop$ = new Subject(); } - private getCoreUsageData(): CoreUsageData { + private async getSavedObjectIndicesUsageData( + savedObjects: SavedObjectsServiceStart, + elasticsearch: ElasticsearchServiceStart + ): Promise { + const indices = await Promise.all( + Array.from( + savedObjects + .getTypeRegistry() + .getAllTypes() + .reduce((acc, type) => { + // TODO: Let the registry return `kibana.index` instead of reading + // the config value here. + const index = + savedObjects.getTypeRegistry().getIndex(type.name) || this.kibanaConfig!.index; + return index != null ? acc.add(index) : acc; + }, new Set()) + .values() + ).map((alias) => { + // The _cat/indices API returns the _index_ and doesn't return a way + // to map back from the index to the alias. So we have to make an API + // call for every alias + return elasticsearch.client.asInternalUser.cat + .indices({ + index: alias, + format: 'JSON', + bytes: 'b', + }) + .then(({ body }) => { + const index = body[0]; + return { + name: index.index, + alias, + docsCount: index['docs.count'], + docsDeleted: index['docs.deleted'], + storeSizeBytes: index['store.size'], + primaryStoreSizeBytes: index['pri.store.size'], + }; + }); + }) + ); + + return { + indices, + }; + } + + private async getCoreUsageData( + savedObjects: SavedObjectsServiceStart, + elasticsearch: ElasticsearchServiceStart + ): Promise { if ( this.elasticsearchConfig == null || this.httpConfig == null || @@ -64,6 +117,7 @@ export class CoreUsageDataService implements CoreService { this.soConfig = config; }); + + this.configService + .atPath('kibana') + .pipe(takeUntil(this.stop$)) + .subscribe((config) => { + this.kibanaConfig = config; + }); } - start() { + start({ savedObjects, elasticsearch }: StartDeps) { return { getCoreUsageData: () => { - return this.getCoreUsageData(); + return this.getCoreUsageData(savedObjects, elasticsearch); }, }; } diff --git a/src/core/server/core_usage_data/types.ts b/src/core/server/core_usage_data/types.ts index 4e3ef842f47fc..c847356b9c525 100644 --- a/src/core/server/core_usage_data/types.ts +++ b/src/core/server/core_usage_data/types.ts @@ -23,7 +23,7 @@ */ export interface CoreUsageData { config: CoreConfigUsageData; - // services: CoreServicesUsageData; + services: CoreServicesUsageData; environment: CoreEnvironmentUsageData; } @@ -32,8 +32,13 @@ export interface CoreUsageData { */ export interface CoreServicesUsageData { savedObjects: { - totalCount: number; - typesCount: number; + indices: Array<{ + name: string; + docsCount: number; + docsDeleted: number; + storeSizeBytes: number; + primaryStoreSizeBytes: number; + }>; }; } @@ -145,5 +150,5 @@ export interface CoreUsageDataStart { * Internal API for collecting Core usage data * @internal * */ - getCoreUsageData(): CoreUsageData; + getCoreUsageData(): Promise; } diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index 482b9dc9f74f0..f0f91c14f3220 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -470,11 +470,15 @@ export interface CoreUsageData { // // (undocumented) environment: CoreEnvironmentUsageData; + // Warning: (ae-forgotten-export) The symbol "CoreServicesUsageData" needs to be exported by the entry point index.d.ts + // + // (undocumented) + services: CoreServicesUsageData; } // @internal export interface CoreUsageDataStart { - getCoreUsageData(): CoreUsageData | null; + getCoreUsageData(): Promise; } // @public (undocumented) diff --git a/src/core/server/server.ts b/src/core/server/server.ts index b3f9cf3250436..fcefc12ab01f3 100644 --- a/src/core/server/server.ts +++ b/src/core/server/server.ts @@ -237,7 +237,10 @@ export class Server { const uiSettingsStart = await this.uiSettings.start(); const metricsStart = await this.metrics.start(); const httpStart = this.http.getStartContract(); - const coreUsageDataStart = this.coreUsageData.start(); + const coreUsageDataStart = this.coreUsageData.start({ + elasticsearch: elasticsearchStart, + savedObjects: savedObjectsStart, + }); this.coreStart = { capabilities: capabilitiesStart, diff --git a/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts b/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts index 566c02b91746d..3c438d098f563 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts @@ -113,6 +113,20 @@ export function getCoreUsageCollector( platformRelease: { type: 'keyword' }, }, }, + services: { + savedObjects: { + indices: { + type: 'array', + items: { + docsCount: { type: 'long' }, + docsDeleted: { type: 'long' }, + name: { type: 'text' }, + primaryStoreSizeBytes: { type: 'long' }, + storeSizeBytes: { type: 'long' }, + }, + }, + }, + }, }, fetch() { return getCoreUsageDataService().getCoreUsageData(); diff --git a/src/plugins/kibana_usage_collection/server/collectors/core/index.test.ts b/src/plugins/kibana_usage_collection/server/collectors/core/index.test.ts index 22ab21f9dc11e..b712e9ebbce48 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/core/index.test.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/core/index.test.ts @@ -38,7 +38,7 @@ describe('telemetry_core', () => { const callCluster = jest.fn().mockImplementation(() => ({})); const coreUsageDataStart = coreUsageDataServiceMock.createStartContract(); const getCoreUsageDataReturnValue = (Symbol('core telemetry') as any) as CoreUsageData; - coreUsageDataStart.getCoreUsageData.mockReturnValue(getCoreUsageDataReturnValue); + coreUsageDataStart.getCoreUsageData.mockResolvedValue(getCoreUsageDataReturnValue); beforeAll(() => registerCoreUsageCollector(usageCollectionMock, () => coreUsageDataStart)); From a1f476a3d914ef75b40c85ec17511e8516951645 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Mon, 5 Oct 2020 00:03:18 +0200 Subject: [PATCH 13/18] Fix tests and telemetry_check --- .../core_usage_data/core_usage_data_service.test.ts | 9 ++++++++- src/core/server/core_usage_data/types.ts | 6 ++++-- .../server/collectors/core/core_usage_collector.ts | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/core/server/core_usage_data/core_usage_data_service.test.ts b/src/core/server/core_usage_data/core_usage_data_service.test.ts index 6f6e036a5780a..716bc72f7992a 100644 --- a/src/core/server/core_usage_data/core_usage_data_service.test.ts +++ b/src/core/server/core_usage_data/core_usage_data_service.test.ts @@ -73,7 +73,7 @@ describe('CoreUsageDataService', () => { savedObjects: savedObjectsServiceMock.createInternalStartContract(), elasticsearch: elasticsearchServiceMock.createStart(), }); - expect(getCoreUsageData()).toMatchInlineSnapshot(` + expect(getCoreUsageData()).resolves.toMatchInlineSnapshot(` Object { "config": Object { "elasticsearch": Object { @@ -170,10 +170,17 @@ describe('CoreUsageDataService', () => { "heapUsedBytes": 1, }, "os": Object { + "distro": undefined, + "distroRelease": undefined, "platform": "darwin", "platformRelease": "test", }, }, + "services": Object { + "savedObjects": Object { + "indices": Array [], + }, + }, } `); }); diff --git a/src/core/server/core_usage_data/types.ts b/src/core/server/core_usage_data/types.ts index c847356b9c525..a329b7e8be275 100644 --- a/src/core/server/core_usage_data/types.ts +++ b/src/core/server/core_usage_data/types.ts @@ -32,13 +32,15 @@ export interface CoreUsageData { */ export interface CoreServicesUsageData { savedObjects: { - indices: Array<{ + // scripts/telemetry_check.js does not support parsing Array<{...}> types + // eslint-disable-next-line @typescript-eslint/array-type + indices: { name: string; docsCount: number; docsDeleted: number; storeSizeBytes: number; primaryStoreSizeBytes: number; - }>; + }[]; }; } diff --git a/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts b/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts index 3c438d098f563..fd96363892bc1 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts @@ -32,7 +32,7 @@ export function getCoreUsageCollector( ) { return usageCollection.makeUsageCollector({ type: 'core', - isReady: () => true, + isReady: () => typeof getCoreUsageDataService() !== 'undefined', schema: { config: { elasticsearch: { From 949e6a585a820ecfe6eb906b2004df5d088ed973 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Mon, 5 Oct 2020 00:10:27 +0200 Subject: [PATCH 14/18] explicitly import/export usage data types for telemetry_check --- src/core/server/core_usage_data/index.ts | 12 +++++++++--- src/core/server/core_usage_data/types.ts | 12 ++++++++++-- src/core/server/index.ts | 13 ++++++++++++- .../server/collectors/core/core_usage_collector.ts | 8 +------- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/core/server/core_usage_data/index.ts b/src/core/server/core_usage_data/index.ts index 87e5654e57f05..b78c126657ef6 100644 --- a/src/core/server/core_usage_data/index.ts +++ b/src/core/server/core_usage_data/index.ts @@ -16,10 +16,16 @@ * specific language governing permissions and limitations * under the License. */ -export { - CoreUsageDataStart, +export { CoreUsageDataStart } from './types'; +export { CoreUsageDataService } from './core_usage_data_service'; + +// Because of #79265 we need to explicity import, then export these types for +// scripts/telemetry_check.js to work as expected +import { CoreUsageData, CoreConfigUsageData, CoreEnvironmentUsageData, + CoreServicesUsageData, } from './types'; -export { CoreUsageDataService } from './core_usage_data_service'; + +export { CoreUsageData, CoreConfigUsageData, CoreEnvironmentUsageData, CoreServicesUsageData }; diff --git a/src/core/server/core_usage_data/types.ts b/src/core/server/core_usage_data/types.ts index a329b7e8be275..5bbbb35d2ac09 100644 --- a/src/core/server/core_usage_data/types.ts +++ b/src/core/server/core_usage_data/types.ts @@ -144,12 +144,20 @@ export interface CoreConfigUsageData { } /** - * Internal API for getting Core's usage data payload + * Internal API for getting Core's usage data payload. + * + * @note This API should never be used to drive application logic and is only + * intended for telemetry purposes. + * * @internal */ export interface CoreUsageDataStart { /** - * Internal API for collecting Core usage data + * Internal API for getting Core's usage data payload. + * + * @note This API should never be used to drive application logic and is only + * intended for telemetry purposes. + * * @internal * */ getCoreUsageData(): Promise; diff --git a/src/core/server/index.ts b/src/core/server/index.ts index 823623600e4c0..887dc50d5f78b 100644 --- a/src/core/server/index.ts +++ b/src/core/server/index.ts @@ -66,6 +66,17 @@ import { Auditor, AuditTrailSetup, AuditTrailStart } from './audit_trail'; import { AppenderConfigType, appendersSchema, LoggingServiceSetup } from './logging'; import { CoreUsageDataStart } from './core_usage_data'; +// Because of #79265 we need to explicity import, then export these types for +// scripts/telemetry_check.js to work as expected +import { + CoreUsageData, + CoreConfigUsageData, + CoreEnvironmentUsageData, + CoreServicesUsageData, +} from './core_usage_data'; + +export { CoreUsageData, CoreConfigUsageData, CoreEnvironmentUsageData, CoreServicesUsageData }; + export { AuditableEvent, Auditor, AuditorFactory, AuditTrailSetup } from './audit_trail'; export { bootstrap } from './bootstrap'; export { Capabilities, CapabilitiesProvider, CapabilitiesSwitcher } from './capabilities'; @@ -350,7 +361,7 @@ export { StatusServiceSetup, } from './status'; -export { CoreUsageDataStart, CoreUsageData } from './core_usage_data'; +export { CoreUsageDataStart } from './core_usage_data'; /** * Plugin specific context passed to a route handler. diff --git a/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts b/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts index fd96363892bc1..129e547481d90 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts @@ -18,13 +18,7 @@ */ import { UsageCollectionSetup } from 'src/plugins/usage_collection/server'; -import { - CoreUsageData, - CoreUsageDataStart, - // eslint-disable-next-line @kbn/eslint/no-restricted-paths -} from '../../../../../core/server/core_usage_data/types'; -// telemetry_check is unable to check types which are re-exported, it only -// works when pointed to the typescript file where the type was defined. +import { CoreUsageData, CoreUsageDataStart } from '../../../../../core/server'; export function getCoreUsageCollector( usageCollection: UsageCollectionSetup, From 062280e68d915afcc80a56cdc2e63fab2d2deb9d Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Mon, 5 Oct 2020 01:36:16 +0200 Subject: [PATCH 15/18] Remove OS data for now, test for SO usage data --- ...erver.coreconfigusagedata.elasticsearch.md | 33 ++++++ ...in-core-server.coreconfigusagedata.http.md | 40 +++++++ ...core-server.coreconfigusagedata.logging.md | 14 +++ ...-plugin-core-server.coreconfigusagedata.md | 23 ++++ ...server.coreconfigusagedata.savedobjects.md | 14 +++ ...in-core-server.coreenvironmentusagedata.md | 20 ++++ ...-server.coreenvironmentusagedata.memory.md | 15 +++ ...lugin-core-server.coreservicesusagedata.md | 20 ++++ ...rver.coreservicesusagedata.savedobjects.md | 19 ++++ .../core/server/kibana-plugin-core-server.md | 3 + .../core_usage_data_service.mock.ts | 6 +- .../core_usage_data_service.test.ts | 55 +++++++-- .../core_usage_data_service.ts | 46 ++++---- src/core/server/core_usage_data/types.ts | 9 +- .../saved_objects_service.mock.ts | 11 +- src/core/server/server.api.md | 105 +++++++++++++++++- .../collectors/core/core_usage_collector.ts | 8 +- 17 files changed, 384 insertions(+), 57 deletions(-) create mode 100644 docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.elasticsearch.md create mode 100644 docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.http.md create mode 100644 docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.logging.md create mode 100644 docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.md create mode 100644 docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.savedobjects.md create mode 100644 docs/development/core/server/kibana-plugin-core-server.coreenvironmentusagedata.md create mode 100644 docs/development/core/server/kibana-plugin-core-server.coreenvironmentusagedata.memory.md create mode 100644 docs/development/core/server/kibana-plugin-core-server.coreservicesusagedata.md create mode 100644 docs/development/core/server/kibana-plugin-core-server.coreservicesusagedata.savedobjects.md diff --git a/docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.elasticsearch.md b/docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.elasticsearch.md new file mode 100644 index 0000000000000..9382b68bac6fa --- /dev/null +++ b/docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.elasticsearch.md @@ -0,0 +1,33 @@ + + +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreConfigUsageData](./kibana-plugin-core-server.coreconfigusagedata.md) > [elasticsearch](./kibana-plugin-core-server.coreconfigusagedata.elasticsearch.md) + +## CoreConfigUsageData.elasticsearch property + +Signature: + +```typescript +elasticsearch: { + sniffOnStart: boolean; + sniffIntervalMs?: number; + sniffOnConnectionFault: boolean; + numberOfHostsConfigured: number; + requestHeadersWhitelistConfigured: boolean; + customHeadersConfigured: boolean; + shardTimeoutMs: number; + requestTimeoutMs: number; + pingTimeoutMs: number; + logQueries: boolean; + ssl: { + verificationMode: 'none' | 'certificate' | 'full'; + certificateAuthoritiesConfigured: boolean; + certificateConfigured: boolean; + keyConfigured: boolean; + keystoreConfigured: boolean; + truststoreConfigured: boolean; + alwaysPresentCertificate: boolean; + }; + apiVersion: string; + healthCheckDelayMs: number; + }; +``` diff --git a/docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.http.md b/docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.http.md new file mode 100644 index 0000000000000..1cfbef4992e07 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.http.md @@ -0,0 +1,40 @@ + + +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreConfigUsageData](./kibana-plugin-core-server.coreconfigusagedata.md) > [http](./kibana-plugin-core-server.coreconfigusagedata.http.md) + +## CoreConfigUsageData.http property + +Signature: + +```typescript +http: { + basePathConfigured: boolean; + maxPayloadInBytes: number; + rewriteBasePath: boolean; + keepaliveTimeout: number; + socketTimeout: number; + compression: { + enabled: boolean; + referrerWhitelistConfigured: boolean; + }; + xsrf: { + disableProtection: boolean; + whitelistConfigured: boolean; + }; + requestId: { + allowFromAnyIp: boolean; + ipAllowlistConfigured: boolean; + }; + ssl: { + certificateAuthoritiesConfigured: boolean; + certificateConfigured: boolean; + cipherSuites: string[]; + keyConfigured: boolean; + keystoreConfigured: boolean; + truststoreConfigured: boolean; + redirectHttpFromPortConfigured: boolean; + supportedProtocols: string[]; + clientAuthentication: 'none' | 'optional' | 'required'; + }; + }; +``` diff --git a/docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.logging.md b/docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.logging.md new file mode 100644 index 0000000000000..53961b6169bd1 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.logging.md @@ -0,0 +1,14 @@ + + +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreConfigUsageData](./kibana-plugin-core-server.coreconfigusagedata.md) > [logging](./kibana-plugin-core-server.coreconfigusagedata.logging.md) + +## CoreConfigUsageData.logging property + +Signature: + +```typescript +logging: { + appendersTypesUsed: string[]; + loggersConfiguredCount: number; + }; +``` diff --git a/docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.md b/docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.md new file mode 100644 index 0000000000000..5af673c572945 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.md @@ -0,0 +1,23 @@ + + +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreConfigUsageData](./kibana-plugin-core-server.coreconfigusagedata.md) + +## CoreConfigUsageData interface + +Usage data on this cluster's configuration of Core features + +Signature: + +```typescript +export interface CoreConfigUsageData +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [elasticsearch](./kibana-plugin-core-server.coreconfigusagedata.elasticsearch.md) | {
sniffOnStart: boolean;
sniffIntervalMs?: number;
sniffOnConnectionFault: boolean;
numberOfHostsConfigured: number;
requestHeadersWhitelistConfigured: boolean;
customHeadersConfigured: boolean;
shardTimeoutMs: number;
requestTimeoutMs: number;
pingTimeoutMs: number;
logQueries: boolean;
ssl: {
verificationMode: 'none' | 'certificate' | 'full';
certificateAuthoritiesConfigured: boolean;
certificateConfigured: boolean;
keyConfigured: boolean;
keystoreConfigured: boolean;
truststoreConfigured: boolean;
alwaysPresentCertificate: boolean;
};
apiVersion: string;
healthCheckDelayMs: number;
} | | +| [http](./kibana-plugin-core-server.coreconfigusagedata.http.md) | {
basePathConfigured: boolean;
maxPayloadInBytes: number;
rewriteBasePath: boolean;
keepaliveTimeout: number;
socketTimeout: number;
compression: {
enabled: boolean;
referrerWhitelistConfigured: boolean;
};
xsrf: {
disableProtection: boolean;
whitelistConfigured: boolean;
};
requestId: {
allowFromAnyIp: boolean;
ipAllowlistConfigured: boolean;
};
ssl: {
certificateAuthoritiesConfigured: boolean;
certificateConfigured: boolean;
cipherSuites: string[];
keyConfigured: boolean;
keystoreConfigured: boolean;
truststoreConfigured: boolean;
redirectHttpFromPortConfigured: boolean;
supportedProtocols: string[];
clientAuthentication: 'none' | 'optional' | 'required';
};
} | | +| [logging](./kibana-plugin-core-server.coreconfigusagedata.logging.md) | {
appendersTypesUsed: string[];
loggersConfiguredCount: number;
} | | +| [savedObjects](./kibana-plugin-core-server.coreconfigusagedata.savedobjects.md) | {
maxImportPayloadBytes: number;
maxImportExportSizeBytes: number;
} | | + diff --git a/docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.savedobjects.md b/docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.savedobjects.md new file mode 100644 index 0000000000000..cfa02191947af --- /dev/null +++ b/docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.savedobjects.md @@ -0,0 +1,14 @@ + + +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreConfigUsageData](./kibana-plugin-core-server.coreconfigusagedata.md) > [savedObjects](./kibana-plugin-core-server.coreconfigusagedata.savedobjects.md) + +## CoreConfigUsageData.savedObjects property + +Signature: + +```typescript +savedObjects: { + maxImportPayloadBytes: number; + maxImportExportSizeBytes: number; + }; +``` diff --git a/docs/development/core/server/kibana-plugin-core-server.coreenvironmentusagedata.md b/docs/development/core/server/kibana-plugin-core-server.coreenvironmentusagedata.md new file mode 100644 index 0000000000000..6b919c41622bd --- /dev/null +++ b/docs/development/core/server/kibana-plugin-core-server.coreenvironmentusagedata.md @@ -0,0 +1,20 @@ + + +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreEnvironmentUsageData](./kibana-plugin-core-server.coreenvironmentusagedata.md) + +## CoreEnvironmentUsageData interface + +Usage data on this Kibana node's runtime environment. + +Signature: + +```typescript +export interface CoreEnvironmentUsageData +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [memory](./kibana-plugin-core-server.coreenvironmentusagedata.memory.md) | {
heapTotalBytes: number;
heapUsedBytes: number;
heapSizeLimit: number;
} | | + diff --git a/docs/development/core/server/kibana-plugin-core-server.coreenvironmentusagedata.memory.md b/docs/development/core/server/kibana-plugin-core-server.coreenvironmentusagedata.memory.md new file mode 100644 index 0000000000000..0d3cb6bc5282c --- /dev/null +++ b/docs/development/core/server/kibana-plugin-core-server.coreenvironmentusagedata.memory.md @@ -0,0 +1,15 @@ + + +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreEnvironmentUsageData](./kibana-plugin-core-server.coreenvironmentusagedata.md) > [memory](./kibana-plugin-core-server.coreenvironmentusagedata.memory.md) + +## CoreEnvironmentUsageData.memory property + +Signature: + +```typescript +memory: { + heapTotalBytes: number; + heapUsedBytes: number; + heapSizeLimit: number; + }; +``` diff --git a/docs/development/core/server/kibana-plugin-core-server.coreservicesusagedata.md b/docs/development/core/server/kibana-plugin-core-server.coreservicesusagedata.md new file mode 100644 index 0000000000000..af315a3743f47 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-core-server.coreservicesusagedata.md @@ -0,0 +1,20 @@ + + +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreServicesUsageData](./kibana-plugin-core-server.coreservicesusagedata.md) + +## CoreServicesUsageData interface + +Usage data from Core services + +Signature: + +```typescript +export interface CoreServicesUsageData +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [savedObjects](./kibana-plugin-core-server.coreservicesusagedata.savedobjects.md) | {
indices: {
alias: string;
docsCount: number;
docsDeleted: number;
storeSizeBytes: number;
primaryStoreSizeBytes: number;
}[];
} | | + diff --git a/docs/development/core/server/kibana-plugin-core-server.coreservicesusagedata.savedobjects.md b/docs/development/core/server/kibana-plugin-core-server.coreservicesusagedata.savedobjects.md new file mode 100644 index 0000000000000..047c730501086 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-core-server.coreservicesusagedata.savedobjects.md @@ -0,0 +1,19 @@ + + +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreServicesUsageData](./kibana-plugin-core-server.coreservicesusagedata.md) > [savedObjects](./kibana-plugin-core-server.coreservicesusagedata.savedobjects.md) + +## CoreServicesUsageData.savedObjects property + +Signature: + +```typescript +savedObjects: { + indices: { + alias: string; + docsCount: number; + docsDeleted: number; + storeSizeBytes: number; + primaryStoreSizeBytes: number; + }[]; + }; +``` diff --git a/docs/development/core/server/kibana-plugin-core-server.md b/docs/development/core/server/kibana-plugin-core-server.md index be8b7c27495ad..b65c155705f27 100644 --- a/docs/development/core/server/kibana-plugin-core-server.md +++ b/docs/development/core/server/kibana-plugin-core-server.md @@ -67,6 +67,9 @@ The plugin integrates with the core system via lifecycle events: `setup` | [CapabilitiesSetup](./kibana-plugin-core-server.capabilitiessetup.md) | APIs to manage the [Capabilities](./kibana-plugin-core-server.capabilities.md) that will be used by the application.Plugins relying on capabilities to toggle some of their features should register them during the setup phase using the registerProvider method.Plugins having the responsibility to restrict capabilities depending on a given context should register their capabilities switcher using the registerSwitcher method.Refers to the methods documentation for complete description and examples. | | [CapabilitiesStart](./kibana-plugin-core-server.capabilitiesstart.md) | APIs to access the application [Capabilities](./kibana-plugin-core-server.capabilities.md). | | [ContextSetup](./kibana-plugin-core-server.contextsetup.md) | An object that handles registration of context providers and configuring handlers with context. | +| [CoreConfigUsageData](./kibana-plugin-core-server.coreconfigusagedata.md) | Usage data on this cluster's configuration of Core features | +| [CoreEnvironmentUsageData](./kibana-plugin-core-server.coreenvironmentusagedata.md) | Usage data on this Kibana node's runtime environment. | +| [CoreServicesUsageData](./kibana-plugin-core-server.coreservicesusagedata.md) | Usage data from Core services | | [CoreSetup](./kibana-plugin-core-server.coresetup.md) | Context passed to the plugins setup method. | | [CoreStart](./kibana-plugin-core-server.corestart.md) | Context passed to the plugins start method. | | [CoreStatus](./kibana-plugin-core-server.corestatus.md) | Status of core services. | diff --git a/src/core/server/core_usage_data/core_usage_data_service.mock.ts b/src/core/server/core_usage_data/core_usage_data_service.mock.ts index f59d172ef32f1..c443ce72f5ed7 100644 --- a/src/core/server/core_usage_data/core_usage_data_service.mock.ts +++ b/src/core/server/core_usage_data/core_usage_data_service.mock.ts @@ -117,10 +117,6 @@ const createStartContractMock = () => { heapTotalBytes: 1, heapUsedBytes: 1, }, - os: { - platform: 'darwin', - platformRelease: 'test', - }, }, services: { savedObjects: { @@ -128,7 +124,7 @@ const createStartContractMock = () => { { docsCount: 1, docsDeleted: 1, - name: 'test_index', + alias: 'test_index', primaryStoreSizeBytes: 1, storeSizeBytes: 1, }, diff --git a/src/core/server/core_usage_data/core_usage_data_service.test.ts b/src/core/server/core_usage_data/core_usage_data_service.test.ts index 716bc72f7992a..a664f6514e9c8 100644 --- a/src/core/server/core_usage_data/core_usage_data_service.test.ts +++ b/src/core/server/core_usage_data/core_usage_data_service.test.ts @@ -68,10 +68,38 @@ describe('CoreUsageDataService', () => { it('returns core metrics for default config', () => { const metrics = metricsServiceMock.createInternalSetupContract(); service.setup({ metrics }); + const elasticsearch = elasticsearchServiceMock.createStart(); + elasticsearch.client.asInternalUser.cat.indices.mockResolvedValueOnce({ + body: [ + { + name: '.kibana_task_manager_1', + 'docs.count': 10, + 'docs.deleted': 10, + 'store.size': 1000, + 'pri.store.size': 2000, + }, + ], + } as any); + elasticsearch.client.asInternalUser.cat.indices.mockResolvedValueOnce({ + body: [ + { + name: '.kibana_1', + 'docs.count': 20, + 'docs.deleted': 20, + 'store.size': 2000, + 'pri.store.size': 4000, + }, + ], + } as any); + const typeRegistry = savedObjectsServiceMock.createTypeRegistryMock(); + typeRegistry.getAllTypes.mockReturnValue([ + { name: 'type 1', indexPattern: '.kibana' }, + { name: 'type 2', indexPattern: '.kibana_task_manager' }, + ] as any); const { getCoreUsageData } = service.start({ - savedObjects: savedObjectsServiceMock.createInternalStartContract(), - elasticsearch: elasticsearchServiceMock.createStart(), + savedObjects: savedObjectsServiceMock.createInternalStartContract(typeRegistry), + elasticsearch, }); expect(getCoreUsageData()).resolves.toMatchInlineSnapshot(` Object { @@ -169,16 +197,25 @@ describe('CoreUsageDataService', () => { "heapTotalBytes": 1, "heapUsedBytes": 1, }, - "os": Object { - "distro": undefined, - "distroRelease": undefined, - "platform": "darwin", - "platformRelease": "test", - }, }, "services": Object { "savedObjects": Object { - "indices": Array [], + "indices": Array [ + Object { + "alias": ".kibana", + "docsCount": 10, + "docsDeleted": 10, + "primaryStoreSizeBytes": 2000, + "storeSizeBytes": 1000, + }, + Object { + "alias": ".kibana_task_manager", + "docsCount": 20, + "docsDeleted": 20, + "primaryStoreSizeBytes": 4000, + "storeSizeBytes": 2000, + }, + ], }, }, } diff --git a/src/core/server/core_usage_data/core_usage_data_service.ts b/src/core/server/core_usage_data/core_usage_data_service.ts index 3c98b828818a3..f729e23cb68bc 100644 --- a/src/core/server/core_usage_data/core_usage_data_service.ts +++ b/src/core/server/core_usage_data/core_usage_data_service.ts @@ -42,6 +42,24 @@ export interface StartDeps { elasticsearch: ElasticsearchServiceStart; } +/** + * Because users can configure their Saved Object to any arbitrary index name, + * we need to map customized index names back to a "standard" index name. + * + * e.g. If a user configures `kibana.index: .my_saved_objects` we want to the + * collected data to be grouped under `.kibana` not ".my_saved_objects". + * + * This is rather brittle, but the option to configure index names might go + * away completely anyway (see #60053). + * + * @param index The index name configured for this SO type + * @param kibanaConfigIndex The default kibana index as configured by the user + * with `kibana.index` + */ +const kibanaOrTaskManagerIndex = (index: string, kibanaConfigIndex: string) => { + return index === kibanaConfigIndex ? '.kibana' : '.kibana_task_manager'; +}; + export class CoreUsageDataService implements CoreService { private elasticsearchConfig?: ElasticsearchConfigType; private configService: CoreContext['configService']; @@ -67,32 +85,28 @@ export class CoreUsageDataService implements CoreService { - // TODO: Let the registry return `kibana.index` instead of reading - // the config value here. - const index = - savedObjects.getTypeRegistry().getIndex(type.name) || this.kibanaConfig!.index; + const index = type.indexPattern ?? this.kibanaConfig!.index; return index != null ? acc.add(index) : acc; }, new Set()) .values() - ).map((alias) => { + ).map((index) => { // The _cat/indices API returns the _index_ and doesn't return a way // to map back from the index to the alias. So we have to make an API // call for every alias return elasticsearch.client.asInternalUser.cat .indices({ - index: alias, + index, format: 'JSON', bytes: 'b', }) .then(({ body }) => { - const index = body[0]; + const stats = body[0]; return { - name: index.index, - alias, - docsCount: index['docs.count'], - docsDeleted: index['docs.deleted'], - storeSizeBytes: index['store.size'], - primaryStoreSizeBytes: index['pri.store.size'], + alias: kibanaOrTaskManagerIndex(index, this.kibanaConfig!.index), + docsCount: stats['docs.count'], + docsDeleted: stats['docs.deleted'], + storeSizeBytes: stats['store.size'], + primaryStoreSizeBytes: stats['pri.store.size'], }; }); }) @@ -207,12 +221,6 @@ export class CoreUsageDataService implements CoreService types + // so we have to disable eslint here and use {...}[] // eslint-disable-next-line @typescript-eslint/array-type indices: { - name: string; + alias: string; docsCount: number; docsDeleted: number; storeSizeBytes: number; @@ -54,12 +55,6 @@ export interface CoreEnvironmentUsageData { /** V8 heap size limit */ heapSizeLimit: number; }; - os: { - platform: string; - platformRelease: string; - distro?: string; - distroRelease?: string; - }; } /** diff --git a/src/core/server/saved_objects/saved_objects_service.mock.ts b/src/core/server/saved_objects/saved_objects_service.mock.ts index bd76658c21731..c56cdabf6e4cd 100644 --- a/src/core/server/saved_objects/saved_objects_service.mock.ts +++ b/src/core/server/saved_objects/saved_objects_service.mock.ts @@ -33,10 +33,11 @@ import { savedObjectsClientMock } from './service/saved_objects_client.mock'; import { typeRegistryMock } from './saved_objects_type_registry.mock'; import { migrationMocks } from './migrations/mocks'; import { ServiceStatusLevels } from '../status'; +import { ISavedObjectTypeRegistry } from './saved_objects_type_registry'; type SavedObjectsServiceContract = PublicMethodsOf; -const createStartContractMock = () => { +const createStartContractMock = (typeRegistry?: jest.Mocked) => { const startContrat: jest.Mocked = { getScopedClient: jest.fn(), createInternalRepository: jest.fn(), @@ -48,13 +49,15 @@ const createStartContractMock = () => { startContrat.getScopedClient.mockReturnValue(savedObjectsClientMock.create()); startContrat.createInternalRepository.mockReturnValue(savedObjectsRepositoryMock.create()); startContrat.createScopedRepository.mockReturnValue(savedObjectsRepositoryMock.create()); - startContrat.getTypeRegistry.mockReturnValue(typeRegistryMock.create()); + startContrat.getTypeRegistry.mockReturnValue(typeRegistry ?? typeRegistryMock.create()); return startContrat; }; -const createInternalStartContractMock = () => { - const internalStartContract: jest.Mocked = createStartContractMock(); +const createInternalStartContractMock = (typeRegistry?: jest.Mocked) => { + const internalStartContract: jest.Mocked = createStartContractMock( + typeRegistry + ); return internalStartContract; }; diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index f0f91c14f3220..6b4cecd0b0ec0 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -401,9 +401,108 @@ export interface ContextSetup { createContextContainer>(): IContextContainer; } +// Warning: (ae-missing-release-tag) "CoreConfigUsageData" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public +export interface CoreConfigUsageData { + // (undocumented) + elasticsearch: { + sniffOnStart: boolean; + sniffIntervalMs?: number; + sniffOnConnectionFault: boolean; + numberOfHostsConfigured: number; + requestHeadersWhitelistConfigured: boolean; + customHeadersConfigured: boolean; + shardTimeoutMs: number; + requestTimeoutMs: number; + pingTimeoutMs: number; + logQueries: boolean; + ssl: { + verificationMode: 'none' | 'certificate' | 'full'; + certificateAuthoritiesConfigured: boolean; + certificateConfigured: boolean; + keyConfigured: boolean; + keystoreConfigured: boolean; + truststoreConfigured: boolean; + alwaysPresentCertificate: boolean; + }; + apiVersion: string; + healthCheckDelayMs: number; + }; + // (undocumented) + http: { + basePathConfigured: boolean; + maxPayloadInBytes: number; + rewriteBasePath: boolean; + keepaliveTimeout: number; + socketTimeout: number; + compression: { + enabled: boolean; + referrerWhitelistConfigured: boolean; + }; + xsrf: { + disableProtection: boolean; + whitelistConfigured: boolean; + }; + requestId: { + allowFromAnyIp: boolean; + ipAllowlistConfigured: boolean; + }; + ssl: { + certificateAuthoritiesConfigured: boolean; + certificateConfigured: boolean; + cipherSuites: string[]; + keyConfigured: boolean; + keystoreConfigured: boolean; + truststoreConfigured: boolean; + redirectHttpFromPortConfigured: boolean; + supportedProtocols: string[]; + clientAuthentication: 'none' | 'optional' | 'required'; + }; + }; + // (undocumented) + logging: { + appendersTypesUsed: string[]; + loggersConfiguredCount: number; + }; + // (undocumented) + savedObjects: { + maxImportPayloadBytes: number; + maxImportExportSizeBytes: number; + }; +} + +// Warning: (ae-missing-release-tag) "CoreEnvironmentUsageData" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public +export interface CoreEnvironmentUsageData { + // (undocumented) + memory: { + heapTotalBytes: number; + heapUsedBytes: number; + heapSizeLimit: number; + }; +} + // @internal (undocumented) export type CoreId = symbol; +// Warning: (ae-missing-release-tag) "CoreServicesUsageData" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public +export interface CoreServicesUsageData { + // (undocumented) + savedObjects: { + indices: { + alias: string; + docsCount: number; + docsDeleted: number; + storeSizeBytes: number; + primaryStoreSizeBytes: number; + }[]; + }; +} + // @public export interface CoreSetup { // (undocumented) @@ -462,16 +561,10 @@ export interface CoreStatus { // @internal export interface CoreUsageData { - // Warning: (ae-forgotten-export) The symbol "CoreConfigUsageData" needs to be exported by the entry point index.d.ts - // // (undocumented) config: CoreConfigUsageData; - // Warning: (ae-forgotten-export) The symbol "CoreEnvironmentUsageData" needs to be exported by the entry point index.d.ts - // // (undocumented) environment: CoreEnvironmentUsageData; - // Warning: (ae-forgotten-export) The symbol "CoreServicesUsageData" needs to be exported by the entry point index.d.ts - // // (undocumented) services: CoreServicesUsageData; } diff --git a/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts b/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts index 129e547481d90..297baf016e9e6 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts @@ -100,12 +100,6 @@ export function getCoreUsageCollector( heapTotalBytes: { type: 'long' }, heapUsedBytes: { type: 'long' }, }, - os: { - distro: { type: 'keyword' }, - distroRelease: { type: 'keyword' }, - platform: { type: 'keyword' }, - platformRelease: { type: 'keyword' }, - }, }, services: { savedObjects: { @@ -114,7 +108,7 @@ export function getCoreUsageCollector( items: { docsCount: { type: 'long' }, docsDeleted: { type: 'long' }, - name: { type: 'text' }, + alias: { type: 'text' }, primaryStoreSizeBytes: { type: 'long' }, storeSizeBytes: { type: 'long' }, }, From 012acd2f289851c46007664a1974e6a7d4c74f83 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Mon, 5 Oct 2020 09:58:36 +0200 Subject: [PATCH 16/18] Fix tests --- ' | 36 +++++++++++++++++++ .../server/__snapshots__/index.test.ts.snap | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 ' diff --git a/' b/' new file mode 100644 index 0000000000000..02d8d7a0e9e65 --- /dev/null +++ b/' @@ -0,0 +1,36 @@ +# This is a combination of 2 commits. +# This is the 1st commit message: + +Remove OS data for now, test for SO usage data + +# Please enter the commit message for your changes. Lines starting +# with '#' will be ignored, and an empty message aborts the commit. +# +# Date: Mon Oct 5 01:36:16 2020 +0200 +# +# interactive rebase in progress; onto a1f476a3d91 +# Last commands done (3 commands done): +# pick fcbe0a2cbd0 Remove OS data for now +# squash b03de91bb4e Test for SO usage data +# No commands remaining. +# You are currently rebasing branch 'core-telemetry' on 'a1f476a3d91'. +# +# Changes to be committed: +# new file: docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.elasticsearch.md +# new file: docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.http.md +# new file: docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.logging.md +# new file: docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.md +# new file: docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.savedobjects.md +# new file: docs/development/core/server/kibana-plugin-core-server.coreenvironmentusagedata.md +# new file: docs/development/core/server/kibana-plugin-core-server.coreenvironmentusagedata.memory.md +# new file: docs/development/core/server/kibana-plugin-core-server.coreservicesusagedata.md +# new file: docs/development/core/server/kibana-plugin-core-server.coreservicesusagedata.savedobjects.md +# modified: docs/development/core/server/kibana-plugin-core-server.md +# modified: src/core/server/core_usage_data/core_usage_data_service.mock.ts +# modified: src/core/server/core_usage_data/core_usage_data_service.test.ts +# modified: src/core/server/core_usage_data/core_usage_data_service.ts +# modified: src/core/server/core_usage_data/types.ts +# modified: src/core/server/saved_objects/saved_objects_service.mock.ts +# modified: src/core/server/server.api.md +# modified: src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts +# diff --git a/src/plugins/kibana_usage_collection/server/__snapshots__/index.test.ts.snap b/src/plugins/kibana_usage_collection/server/__snapshots__/index.test.ts.snap index 1c6f87275f00f..c479562795512 100644 --- a/src/plugins/kibana_usage_collection/server/__snapshots__/index.test.ts.snap +++ b/src/plugins/kibana_usage_collection/server/__snapshots__/index.test.ts.snap @@ -12,4 +12,4 @@ exports[`kibana_usage_collection Runs the setup method without issues 5`] = `fal exports[`kibana_usage_collection Runs the setup method without issues 6`] = `true`; -exports[`kibana_usage_collection Runs the setup method without issues 7`] = `true`; +exports[`kibana_usage_collection Runs the setup method without issues 7`] = `false`; From 333b3d4162ec89f1cfa5f037f7e641602352d3da Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Mon, 5 Oct 2020 10:15:20 +0200 Subject: [PATCH 17/18] Polish core docs --- ...erver.coreconfigusagedata.elasticsearch.md | 33 --------------- ...in-core-server.coreconfigusagedata.http.md | 40 ------------------- ...core-server.coreconfigusagedata.logging.md | 14 ------- ...-plugin-core-server.coreconfigusagedata.md | 23 ----------- ...server.coreconfigusagedata.savedobjects.md | 14 ------- ...in-core-server.coreenvironmentusagedata.md | 20 ---------- ...-server.coreenvironmentusagedata.memory.md | 15 ------- ...lugin-core-server.coreservicesusagedata.md | 20 ---------- ...rver.coreservicesusagedata.savedobjects.md | 19 --------- .../core/server/kibana-plugin-core-server.md | 3 -- src/core/server/core_usage_data/types.ts | 3 ++ src/core/server/server.api.md | 12 ++---- 12 files changed, 6 insertions(+), 210 deletions(-) delete mode 100644 docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.elasticsearch.md delete mode 100644 docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.http.md delete mode 100644 docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.logging.md delete mode 100644 docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.md delete mode 100644 docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.savedobjects.md delete mode 100644 docs/development/core/server/kibana-plugin-core-server.coreenvironmentusagedata.md delete mode 100644 docs/development/core/server/kibana-plugin-core-server.coreenvironmentusagedata.memory.md delete mode 100644 docs/development/core/server/kibana-plugin-core-server.coreservicesusagedata.md delete mode 100644 docs/development/core/server/kibana-plugin-core-server.coreservicesusagedata.savedobjects.md diff --git a/docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.elasticsearch.md b/docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.elasticsearch.md deleted file mode 100644 index 9382b68bac6fa..0000000000000 --- a/docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.elasticsearch.md +++ /dev/null @@ -1,33 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreConfigUsageData](./kibana-plugin-core-server.coreconfigusagedata.md) > [elasticsearch](./kibana-plugin-core-server.coreconfigusagedata.elasticsearch.md) - -## CoreConfigUsageData.elasticsearch property - -Signature: - -```typescript -elasticsearch: { - sniffOnStart: boolean; - sniffIntervalMs?: number; - sniffOnConnectionFault: boolean; - numberOfHostsConfigured: number; - requestHeadersWhitelistConfigured: boolean; - customHeadersConfigured: boolean; - shardTimeoutMs: number; - requestTimeoutMs: number; - pingTimeoutMs: number; - logQueries: boolean; - ssl: { - verificationMode: 'none' | 'certificate' | 'full'; - certificateAuthoritiesConfigured: boolean; - certificateConfigured: boolean; - keyConfigured: boolean; - keystoreConfigured: boolean; - truststoreConfigured: boolean; - alwaysPresentCertificate: boolean; - }; - apiVersion: string; - healthCheckDelayMs: number; - }; -``` diff --git a/docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.http.md b/docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.http.md deleted file mode 100644 index 1cfbef4992e07..0000000000000 --- a/docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.http.md +++ /dev/null @@ -1,40 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreConfigUsageData](./kibana-plugin-core-server.coreconfigusagedata.md) > [http](./kibana-plugin-core-server.coreconfigusagedata.http.md) - -## CoreConfigUsageData.http property - -Signature: - -```typescript -http: { - basePathConfigured: boolean; - maxPayloadInBytes: number; - rewriteBasePath: boolean; - keepaliveTimeout: number; - socketTimeout: number; - compression: { - enabled: boolean; - referrerWhitelistConfigured: boolean; - }; - xsrf: { - disableProtection: boolean; - whitelistConfigured: boolean; - }; - requestId: { - allowFromAnyIp: boolean; - ipAllowlistConfigured: boolean; - }; - ssl: { - certificateAuthoritiesConfigured: boolean; - certificateConfigured: boolean; - cipherSuites: string[]; - keyConfigured: boolean; - keystoreConfigured: boolean; - truststoreConfigured: boolean; - redirectHttpFromPortConfigured: boolean; - supportedProtocols: string[]; - clientAuthentication: 'none' | 'optional' | 'required'; - }; - }; -``` diff --git a/docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.logging.md b/docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.logging.md deleted file mode 100644 index 53961b6169bd1..0000000000000 --- a/docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.logging.md +++ /dev/null @@ -1,14 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreConfigUsageData](./kibana-plugin-core-server.coreconfigusagedata.md) > [logging](./kibana-plugin-core-server.coreconfigusagedata.logging.md) - -## CoreConfigUsageData.logging property - -Signature: - -```typescript -logging: { - appendersTypesUsed: string[]; - loggersConfiguredCount: number; - }; -``` diff --git a/docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.md b/docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.md deleted file mode 100644 index 5af673c572945..0000000000000 --- a/docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.md +++ /dev/null @@ -1,23 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreConfigUsageData](./kibana-plugin-core-server.coreconfigusagedata.md) - -## CoreConfigUsageData interface - -Usage data on this cluster's configuration of Core features - -Signature: - -```typescript -export interface CoreConfigUsageData -``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [elasticsearch](./kibana-plugin-core-server.coreconfigusagedata.elasticsearch.md) | {
sniffOnStart: boolean;
sniffIntervalMs?: number;
sniffOnConnectionFault: boolean;
numberOfHostsConfigured: number;
requestHeadersWhitelistConfigured: boolean;
customHeadersConfigured: boolean;
shardTimeoutMs: number;
requestTimeoutMs: number;
pingTimeoutMs: number;
logQueries: boolean;
ssl: {
verificationMode: 'none' | 'certificate' | 'full';
certificateAuthoritiesConfigured: boolean;
certificateConfigured: boolean;
keyConfigured: boolean;
keystoreConfigured: boolean;
truststoreConfigured: boolean;
alwaysPresentCertificate: boolean;
};
apiVersion: string;
healthCheckDelayMs: number;
} | | -| [http](./kibana-plugin-core-server.coreconfigusagedata.http.md) | {
basePathConfigured: boolean;
maxPayloadInBytes: number;
rewriteBasePath: boolean;
keepaliveTimeout: number;
socketTimeout: number;
compression: {
enabled: boolean;
referrerWhitelistConfigured: boolean;
};
xsrf: {
disableProtection: boolean;
whitelistConfigured: boolean;
};
requestId: {
allowFromAnyIp: boolean;
ipAllowlistConfigured: boolean;
};
ssl: {
certificateAuthoritiesConfigured: boolean;
certificateConfigured: boolean;
cipherSuites: string[];
keyConfigured: boolean;
keystoreConfigured: boolean;
truststoreConfigured: boolean;
redirectHttpFromPortConfigured: boolean;
supportedProtocols: string[];
clientAuthentication: 'none' | 'optional' | 'required';
};
} | | -| [logging](./kibana-plugin-core-server.coreconfigusagedata.logging.md) | {
appendersTypesUsed: string[];
loggersConfiguredCount: number;
} | | -| [savedObjects](./kibana-plugin-core-server.coreconfigusagedata.savedobjects.md) | {
maxImportPayloadBytes: number;
maxImportExportSizeBytes: number;
} | | - diff --git a/docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.savedobjects.md b/docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.savedobjects.md deleted file mode 100644 index cfa02191947af..0000000000000 --- a/docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.savedobjects.md +++ /dev/null @@ -1,14 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreConfigUsageData](./kibana-plugin-core-server.coreconfigusagedata.md) > [savedObjects](./kibana-plugin-core-server.coreconfigusagedata.savedobjects.md) - -## CoreConfigUsageData.savedObjects property - -Signature: - -```typescript -savedObjects: { - maxImportPayloadBytes: number; - maxImportExportSizeBytes: number; - }; -``` diff --git a/docs/development/core/server/kibana-plugin-core-server.coreenvironmentusagedata.md b/docs/development/core/server/kibana-plugin-core-server.coreenvironmentusagedata.md deleted file mode 100644 index 6b919c41622bd..0000000000000 --- a/docs/development/core/server/kibana-plugin-core-server.coreenvironmentusagedata.md +++ /dev/null @@ -1,20 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreEnvironmentUsageData](./kibana-plugin-core-server.coreenvironmentusagedata.md) - -## CoreEnvironmentUsageData interface - -Usage data on this Kibana node's runtime environment. - -Signature: - -```typescript -export interface CoreEnvironmentUsageData -``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [memory](./kibana-plugin-core-server.coreenvironmentusagedata.memory.md) | {
heapTotalBytes: number;
heapUsedBytes: number;
heapSizeLimit: number;
} | | - diff --git a/docs/development/core/server/kibana-plugin-core-server.coreenvironmentusagedata.memory.md b/docs/development/core/server/kibana-plugin-core-server.coreenvironmentusagedata.memory.md deleted file mode 100644 index 0d3cb6bc5282c..0000000000000 --- a/docs/development/core/server/kibana-plugin-core-server.coreenvironmentusagedata.memory.md +++ /dev/null @@ -1,15 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreEnvironmentUsageData](./kibana-plugin-core-server.coreenvironmentusagedata.md) > [memory](./kibana-plugin-core-server.coreenvironmentusagedata.memory.md) - -## CoreEnvironmentUsageData.memory property - -Signature: - -```typescript -memory: { - heapTotalBytes: number; - heapUsedBytes: number; - heapSizeLimit: number; - }; -``` diff --git a/docs/development/core/server/kibana-plugin-core-server.coreservicesusagedata.md b/docs/development/core/server/kibana-plugin-core-server.coreservicesusagedata.md deleted file mode 100644 index af315a3743f47..0000000000000 --- a/docs/development/core/server/kibana-plugin-core-server.coreservicesusagedata.md +++ /dev/null @@ -1,20 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreServicesUsageData](./kibana-plugin-core-server.coreservicesusagedata.md) - -## CoreServicesUsageData interface - -Usage data from Core services - -Signature: - -```typescript -export interface CoreServicesUsageData -``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [savedObjects](./kibana-plugin-core-server.coreservicesusagedata.savedobjects.md) | {
indices: {
alias: string;
docsCount: number;
docsDeleted: number;
storeSizeBytes: number;
primaryStoreSizeBytes: number;
}[];
} | | - diff --git a/docs/development/core/server/kibana-plugin-core-server.coreservicesusagedata.savedobjects.md b/docs/development/core/server/kibana-plugin-core-server.coreservicesusagedata.savedobjects.md deleted file mode 100644 index 047c730501086..0000000000000 --- a/docs/development/core/server/kibana-plugin-core-server.coreservicesusagedata.savedobjects.md +++ /dev/null @@ -1,19 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [CoreServicesUsageData](./kibana-plugin-core-server.coreservicesusagedata.md) > [savedObjects](./kibana-plugin-core-server.coreservicesusagedata.savedobjects.md) - -## CoreServicesUsageData.savedObjects property - -Signature: - -```typescript -savedObjects: { - indices: { - alias: string; - docsCount: number; - docsDeleted: number; - storeSizeBytes: number; - primaryStoreSizeBytes: number; - }[]; - }; -``` diff --git a/docs/development/core/server/kibana-plugin-core-server.md b/docs/development/core/server/kibana-plugin-core-server.md index b65c155705f27..be8b7c27495ad 100644 --- a/docs/development/core/server/kibana-plugin-core-server.md +++ b/docs/development/core/server/kibana-plugin-core-server.md @@ -67,9 +67,6 @@ The plugin integrates with the core system via lifecycle events: `setup` | [CapabilitiesSetup](./kibana-plugin-core-server.capabilitiessetup.md) | APIs to manage the [Capabilities](./kibana-plugin-core-server.capabilities.md) that will be used by the application.Plugins relying on capabilities to toggle some of their features should register them during the setup phase using the registerProvider method.Plugins having the responsibility to restrict capabilities depending on a given context should register their capabilities switcher using the registerSwitcher method.Refers to the methods documentation for complete description and examples. | | [CapabilitiesStart](./kibana-plugin-core-server.capabilitiesstart.md) | APIs to access the application [Capabilities](./kibana-plugin-core-server.capabilities.md). | | [ContextSetup](./kibana-plugin-core-server.contextsetup.md) | An object that handles registration of context providers and configuring handlers with context. | -| [CoreConfigUsageData](./kibana-plugin-core-server.coreconfigusagedata.md) | Usage data on this cluster's configuration of Core features | -| [CoreEnvironmentUsageData](./kibana-plugin-core-server.coreenvironmentusagedata.md) | Usage data on this Kibana node's runtime environment. | -| [CoreServicesUsageData](./kibana-plugin-core-server.coreservicesusagedata.md) | Usage data from Core services | | [CoreSetup](./kibana-plugin-core-server.coresetup.md) | Context passed to the plugins setup method. | | [CoreStart](./kibana-plugin-core-server.corestart.md) | Context passed to the plugins start method. | | [CoreStatus](./kibana-plugin-core-server.corestatus.md) | Status of core services. | diff --git a/src/core/server/core_usage_data/types.ts b/src/core/server/core_usage_data/types.ts index a98e61d8017df..52d2eadcf1377 100644 --- a/src/core/server/core_usage_data/types.ts +++ b/src/core/server/core_usage_data/types.ts @@ -29,6 +29,7 @@ export interface CoreUsageData { /** * Usage data from Core services + * @internal */ export interface CoreServicesUsageData { savedObjects: { @@ -47,6 +48,7 @@ export interface CoreServicesUsageData { /** * Usage data on this Kibana node's runtime environment. + * @internal */ export interface CoreEnvironmentUsageData { memory: { @@ -59,6 +61,7 @@ export interface CoreEnvironmentUsageData { /** * Usage data on this cluster's configuration of Core features + * @internal */ export interface CoreConfigUsageData { elasticsearch: { diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index 6b4cecd0b0ec0..275a70a764918 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -401,9 +401,7 @@ export interface ContextSetup { createContextContainer>(): IContextContainer; } -// Warning: (ae-missing-release-tag) "CoreConfigUsageData" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public +// @internal export interface CoreConfigUsageData { // (undocumented) elasticsearch: { @@ -472,9 +470,7 @@ export interface CoreConfigUsageData { }; } -// Warning: (ae-missing-release-tag) "CoreEnvironmentUsageData" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public +// @internal export interface CoreEnvironmentUsageData { // (undocumented) memory: { @@ -487,9 +483,7 @@ export interface CoreEnvironmentUsageData { // @internal (undocumented) export type CoreId = symbol; -// Warning: (ae-missing-release-tag) "CoreServicesUsageData" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public +// @internal export interface CoreServicesUsageData { // (undocumented) savedObjects: { From afe01146ca4c22b03b149e2f79bde619ee006124 Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Mon, 5 Oct 2020 10:31:46 +0200 Subject: [PATCH 18/18] This shouldn't be here --- ' | 36 ------------------------------------ 1 file changed, 36 deletions(-) delete mode 100644 ' diff --git a/' b/' deleted file mode 100644 index 02d8d7a0e9e65..0000000000000 --- a/' +++ /dev/null @@ -1,36 +0,0 @@ -# This is a combination of 2 commits. -# This is the 1st commit message: - -Remove OS data for now, test for SO usage data - -# Please enter the commit message for your changes. Lines starting -# with '#' will be ignored, and an empty message aborts the commit. -# -# Date: Mon Oct 5 01:36:16 2020 +0200 -# -# interactive rebase in progress; onto a1f476a3d91 -# Last commands done (3 commands done): -# pick fcbe0a2cbd0 Remove OS data for now -# squash b03de91bb4e Test for SO usage data -# No commands remaining. -# You are currently rebasing branch 'core-telemetry' on 'a1f476a3d91'. -# -# Changes to be committed: -# new file: docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.elasticsearch.md -# new file: docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.http.md -# new file: docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.logging.md -# new file: docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.md -# new file: docs/development/core/server/kibana-plugin-core-server.coreconfigusagedata.savedobjects.md -# new file: docs/development/core/server/kibana-plugin-core-server.coreenvironmentusagedata.md -# new file: docs/development/core/server/kibana-plugin-core-server.coreenvironmentusagedata.memory.md -# new file: docs/development/core/server/kibana-plugin-core-server.coreservicesusagedata.md -# new file: docs/development/core/server/kibana-plugin-core-server.coreservicesusagedata.savedobjects.md -# modified: docs/development/core/server/kibana-plugin-core-server.md -# modified: src/core/server/core_usage_data/core_usage_data_service.mock.ts -# modified: src/core/server/core_usage_data/core_usage_data_service.test.ts -# modified: src/core/server/core_usage_data/core_usage_data_service.ts -# modified: src/core/server/core_usage_data/types.ts -# modified: src/core/server/saved_objects/saved_objects_service.mock.ts -# modified: src/core/server/server.api.md -# modified: src/plugins/kibana_usage_collection/server/collectors/core/core_usage_collector.ts -#