Skip to content

Commit

Permalink
[Performance] Add navigator hw info to kibana-loaded event (#140291)
Browse files Browse the repository at this point in the history
* 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 <afharo@gmail.com>

* [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 <afharo@gmail.com>
  • Loading branch information
3 people authored Sep 14, 2022
1 parent 286a7c9 commit ed4ae8b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/core/public/core_system.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -325,6 +329,8 @@ describe('#start()', () => {
meta: {
kibana_version: '1.2.3',
protocol: 'http:',
deviceMemory: '5',
hardwareConcurrency: '4',
...performanceMemory,
},
key1: LOAD_START,
Expand Down
23 changes: 23 additions & 0 deletions src/core/public/core_system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ export interface InternalCoreStart extends Omit<CoreStart, 'application'> {
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
Expand Down Expand Up @@ -168,12 +179,24 @@ export class CoreSystem {
});

const timing = this.getLoadMarksInfo();

const navigatorExt = navigator as ExtendedNavigator;
const navigatorInfo: Record<string, string> = {};
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,
Expand Down

0 comments on commit ed4ae8b

Please sign in to comment.