From ed4ae8b2a1dc6b83905bd6b62f24b1e5c2b71267 Mon Sep 17 00:00:00 2001 From: Liza Katz Date: Wed, 14 Sep 2022 12:38:22 +0300 Subject: [PATCH] [Performance] Add navigator hw info to kibana-loaded event (#140291) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add hw info * [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' * removed effectiveNetworkType * Update src/core/public/core_system.ts Co-authored-by: Alejandro Fernández Haro * [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Alejandro Fernández Haro --- src/core/public/core_system.test.ts | 6 ++++++ src/core/public/core_system.ts | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/core/public/core_system.test.ts b/src/core/public/core_system.test.ts index f9f9f6e90afdd..8e2e980e5ea94 100644 --- a/src/core/public/core_system.test.ts +++ b/src/core/public/core_system.test.ts @@ -52,6 +52,8 @@ import { } from './events'; jest.spyOn(CoreSystem.prototype, 'stop'); +(global.navigator as any).deviceMemory = 5; +jest.spyOn(global.navigator as any, 'hardwareConcurrency', 'get').mockReturnValue(4); const defaultCoreSystemParams = { rootDomElement: document.createElement('div'), @@ -292,6 +294,8 @@ describe('#start()', () => { meta: { kibana_version: '1.2.3', protocol: 'http:', + deviceMemory: '5', + hardwareConcurrency: '4', }, key1: LOAD_START, key2: LOAD_BOOTSTRAP_START, @@ -325,6 +329,8 @@ describe('#start()', () => { meta: { kibana_version: '1.2.3', protocol: 'http:', + deviceMemory: '5', + hardwareConcurrency: '4', ...performanceMemory, }, key1: LOAD_START, diff --git a/src/core/public/core_system.ts b/src/core/public/core_system.ts index 47ea6dd2ec164..7b1e073e4b535 100644 --- a/src/core/public/core_system.ts +++ b/src/core/public/core_system.ts @@ -71,6 +71,17 @@ export interface InternalCoreStart extends Omit { injectedMetadata: InternalInjectedMetadataStart; } +// Expands the definition of navigator to include experimental features +interface ExtendedNavigator { + connection?: { + effectiveType?: string; + }; + // Estimated RAM + deviceMemory?: number; + // Number of cores + hardwareConcurrency?: number; +} + /** * The CoreSystem is the root of the new platform, and setups all parts * of Kibana in the UI, including the LegacyPlatform which is managed @@ -168,12 +179,24 @@ export class CoreSystem { }); const timing = this.getLoadMarksInfo(); + + const navigatorExt = navigator as ExtendedNavigator; + const navigatorInfo: Record = {}; + if (navigatorExt.deviceMemory) { + navigatorInfo.deviceMemory = String(navigatorExt.deviceMemory); + } + if (navigatorExt.hardwareConcurrency) { + navigatorInfo.hardwareConcurrency = String(navigatorExt.hardwareConcurrency); + } + reportPerformanceMetricEvent(analytics, { eventName: KIBANA_LOADED_EVENT, meta: { kibana_version: this.coreContext.env.packageInfo.version, protocol: window.location.protocol, ...fetchOptionalMemoryInfo(), + // Report some hardware metrics for bucketing + ...navigatorInfo, }, duration: timing[LOAD_FIRST_NAV], key1: LOAD_START,