Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flexible EBT Performance Metric Schema #136395

Merged
merged 65 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
c96659e
use flexible performancce event schema
Jul 14, 2022
4a4f5c8
fix
Jul 14, 2022
d86ea42
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Jul 14, 2022
266d2d8
import
Jul 14, 2022
70dbbbe
code review
Jul 14, 2022
6ce59fe
Merge branch 'normalize-ebt-events' of github.com:lizozom/kibana into…
Jul 14, 2022
e3baa5f
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Jul 14, 2022
e7dae10
fixes
Jul 18, 2022
0375310
Merge branch 'main' of https://github.com/elastic/kibana into normali…
Jul 18, 2022
2153b6e
Merge branch 'normalize-ebt-events' of github.com:lizozom/kibana into…
Jul 18, 2022
dd48217
jest
Jul 18, 2022
a1f742d
dd
Jul 18, 2022
5791c43
fix
Jul 18, 2022
daa56fa
tests
Jul 19, 2022
b4bc48f
Merge branch 'main' of https://github.com/elastic/kibana into normali…
Jul 19, 2022
03dc26a
Review 1
Jul 19, 2022
f5e846d
Move code to package
Jul 19, 2022
6839713
Merge branch 'main' of https://github.com/elastic/kibana into normali…
Jul 19, 2022
4f217a4
rename
Jul 19, 2022
ce91896
lint
Jul 19, 2022
af0f047
ts
Jul 19, 2022
94b1a65
import
Jul 19, 2022
0c7de8b
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Jul 19, 2022
8fcf8c3
[CI] Auto-commit changed files from 'node scripts/generate packages_b…
kibanamachine Jul 19, 2022
1b15981
import
Jul 19, 2022
25499dd
Merge branch 'normalize-ebt-events' of github.com:lizozom/kibana into…
Jul 19, 2022
cb98b78
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Jul 19, 2022
27f6d5c
fix package + create wrapper
Jul 19, 2022
b0b2c0e
Merge branch 'main' of https://github.com/elastic/kibana into normali…
Jul 19, 2022
60cf6e9
Merge branch 'normalize-ebt-events' of github.com:lizozom/kibana into…
Jul 19, 2022
5214952
reporting wrappers
Jul 19, 2022
e3ce4f2
naming consistency
Jul 19, 2022
62f6509
meta
Jul 19, 2022
fa20280
AnalyticsServiceSetup
Jul 19, 2022
25c9659
func
Jul 19, 2022
bde7a42
fix(NA): types typo for @kbn/ebt-tools
mistic Jul 19, 2022
a5d57d3
Fix tests, add docs, apply nits, fix types
afharo Jul 20, 2022
7728ba7
Merge pull request #10 from afharo/afharo/normalize-ebt-events
lizozom Jul 20, 2022
06a8f38
Convert KIBANA_STARTED_EVENT times to ms
Jul 20, 2022
b33c9b4
Merge branch 'main' of https://github.com/elastic/kibana into normali…
Jul 20, 2022
adcce90
test
Jul 20, 2022
43d2f84
test
Jul 21, 2022
19b67b1
Merge branch 'main' of https://github.com/elastic/kibana into normali…
Jul 21, 2022
ffc7e6a
fix sec -> ms conversion
Jul 28, 2022
38dac93
rename metric->performance_metric
Jul 28, 2022
66c4532
Merge branch 'main' into normalize-ebt-events
kibanamachine Jul 28, 2022
ec00d0b
Merge branch 'main' of github.com:elastic/kibana into normalize-ebt-e…
Jul 29, 2022
51aa34b
update snapshots
Jul 29, 2022
ed9affc
Merge branch 'normalize-ebt-events' of github.com:lizozom/kibana into…
Jul 29, 2022
bcfd341
remove memory related fields from standardized fields
Jul 29, 2022
a5978ed
Merge branch 'main' into normalize-ebt-events
kibanamachine Jul 29, 2022
7633faa
fix type errors
Jul 29, 2022
eaf8c8b
Merge branch 'normalize-ebt-events' of github.com:lizozom/kibana into…
Jul 29, 2022
8373386
Merge branch 'main' into normalize-ebt-events
suchcodemuchwow Aug 1, 2022
bfd59bc
small fixes
Aug 1, 2022
9d8b950
fix meta type for tests
Aug 1, 2022
9db2bfd
Merge branch 'main' of github.com:elastic/kibana into normalize-ebt-e…
Aug 1, 2022
2d9e30f
remove status field
Aug 1, 2022
bab8873
Merge branch 'main' of github.com:elastic/kibana into normalize-ebt-e…
Aug 2, 2022
aef999c
fix pr comments
Aug 2, 2022
e3efd40
update eventName comment for MetricEvent
Aug 2, 2022
9f46d83
update event name test snapshot
Aug 2, 2022
4c0e883
update event name test snapshot for server
Aug 2, 2022
8068f99
fix pr comments
Aug 3, 2022
048b217
Merge branch 'main' of github.com:elastic/kibana into normalize-ebt-e…
Aug 3, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/core/public/core_system.test.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ jest.doMock('@kbn/core-analytics-browser-internal', () => ({
AnalyticsService: AnalyticsServiceConstructor,
}));

export const fetchOptionalMemoryInfoMock = jest.fn();
jest.doMock('./fetch_optional_memory_info', () => ({
fetchOptionalMemoryInfo: fetchOptionalMemoryInfoMock,
}));

export const MockInjectedMetadataService = injectedMetadataServiceMock.create();
export const InjectedMetadataServiceConstructor = jest
.fn()
Expand Down
75 changes: 53 additions & 22 deletions src/core/public/core_system.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,18 @@ import {
AnalyticsServiceConstructor,
MockAnalyticsService,
analyticsServiceStartMock,
fetchOptionalMemoryInfoMock,
} from './core_system.test.mocks';

import { CoreSystem } from './core_system';
import {
KIBANA_LOADED_EVENT,
LOAD_START,
LOAD_BOOTSTRAP_START,
LOAD_CORE_CREATED,
LOAD_FIRST_NAV,
LOAD_SETUP_DONE,
LOAD_START_DONE,
} from './utils';

jest.spyOn(CoreSystem.prototype, 'stop');

Expand Down Expand Up @@ -75,12 +83,28 @@ beforeEach(() => {
window.performance.clearMarks = jest.fn();
window.performance.getEntriesByName = jest.fn().mockReturnValue([
{
detail: 'load_started',
startTime: 456,
detail: LOAD_START,
startTime: 111,
},
{
detail: LOAD_BOOTSTRAP_START,
startTime: 222,
},
{
detail: 'bootstrap_started',
startTime: 123,
detail: LOAD_CORE_CREATED,
startTime: 333,
},
{
detail: LOAD_SETUP_DONE,
startTime: 444,
},
{
detail: LOAD_START_DONE,
startTime: 555,
},
{
detail: LOAD_FIRST_NAV,
startTime: 666,
},
]);
});
Expand Down Expand Up @@ -251,34 +275,41 @@ describe('#start()', () => {
it('reports the event Loaded Kibana and clears marks', async () => {
await startCore();
expect(analyticsServiceStartMock.reportEvent).toHaveBeenCalledTimes(1);
expect(analyticsServiceStartMock.reportEvent).toHaveBeenCalledWith('Loaded Kibana', {
expect(analyticsServiceStartMock.reportEvent).toHaveBeenCalledWith(KIBANA_LOADED_EVENT, {
kibana_version: '1.2.3',
load_started: 456,
bootstrap_started: 123,
protocol: 'http:',
key1: LOAD_START,
key2: LOAD_BOOTSTRAP_START,
key3: LOAD_CORE_CREATED,
key4: LOAD_SETUP_DONE,
key5: LOAD_START_DONE,
value1: 111,
value2: 222,
value3: 333,
value4: 444,
value5: 555,
duration: 666,
});

expect(window.performance.clearMarks).toHaveBeenCalledTimes(1);
});

it('reports the event Loaded Kibana (with memory)', async () => {
fetchOptionalMemoryInfoMock.mockReturnValue({
load_started: 456,
bootstrap_started: 123,
memory_js_heap_size_limit: 3,
memory_js_heap_size_total: 2,
memory_js_heap_size_used: 1,
});

await startCore();
expect(analyticsServiceStartMock.reportEvent).toHaveBeenCalledTimes(1);
expect(analyticsServiceStartMock.reportEvent).toHaveBeenCalledWith('Loaded Kibana', {
load_started: 456,
bootstrap_started: 123,
expect(analyticsServiceStartMock.reportEvent).toHaveBeenCalledWith(KIBANA_LOADED_EVENT, {
kibana_version: '1.2.3',
memory_js_heap_size_limit: 3,
memory_js_heap_size_total: 2,
memory_js_heap_size_used: 1,
duration: 666,
key1: LOAD_START,
key2: LOAD_BOOTSTRAP_START,
key3: LOAD_CORE_CREATED,
key4: LOAD_SETUP_DONE,
key5: LOAD_START_DONE,
value1: 111,
value2: 222,
value3: 333,
value4: 444,
value5: 555,
protocol: 'http:',
});
});
Expand Down
85 changes: 34 additions & 51 deletions src/core/public/core_system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,17 @@ import { SavedObjectsService } from './saved_objects';
import { IntegrationsService } from './integrations';
import { CoreApp } from './core_app';
import type { InternalApplicationSetup, InternalApplicationStart } from './application/types';
import { fetchOptionalMemoryInfo } from './fetch_optional_memory_info';
import { KBN_LOAD_MARKS } from './utils';
import {
KBN_LOAD_MARKS,
LOAD_SETUP_DONE,
LOAD_START_DONE,
KIBANA_LOADED_EVENT,
LOAD_CORE_CREATED,
PERFORMANCE_METRIC_EVENT_SCHEMA,
LOAD_FIRST_NAV,
LOAD_BOOTSTRAP_START,
LOAD_START,
} from './utils';

interface Params {
rootDomElement: HTMLElement;
Expand Down Expand Up @@ -129,12 +138,12 @@ export class CoreSystem {
this.coreApp = new CoreApp(this.coreContext);

performance.mark(KBN_LOAD_MARKS, {
detail: 'core_created',
detail: LOAD_CORE_CREATED,
});
}

private getLoadMarksInfo() {
if (!performance) return [];
private getLoadMarksInfo(): Record<string, number> {
if (!performance) return {};
const reportData: Record<string, number> = {};
const marks = performance.getEntriesByName(KBN_LOAD_MARKS);
for (const mark of marks) {
Expand All @@ -145,11 +154,23 @@ export class CoreSystem {
}

private reportKibanaLoadedEvent(analytics: AnalyticsServiceStart) {
analytics.reportEvent('Loaded Kibana', {
const timing = this.getLoadMarksInfo();
analytics.reportEvent(KIBANA_LOADED_EVENT, {
kibana_version: this.coreContext.env.packageInfo.version,
protocol: window.location.protocol,
...fetchOptionalMemoryInfo(),
...this.getLoadMarksInfo(),
duration: timing[LOAD_FIRST_NAV],
// @ts-expect-error 2339
...performance.memory,
key1: LOAD_START,
value1: timing[LOAD_START],
key2: LOAD_BOOTSTRAP_START,
value2: timing[LOAD_BOOTSTRAP_START],
key3: LOAD_CORE_CREATED,
value3: timing[LOAD_CORE_CREATED],
key4: LOAD_SETUP_DONE,
value4: timing[LOAD_SETUP_DONE],
key5: LOAD_START_DONE,
value5: timing[LOAD_START_DONE],
});
performance.clearMarks(KBN_LOAD_MARKS);
}
Expand Down Expand Up @@ -200,7 +221,7 @@ export class CoreSystem {
await this.plugins.setup(core);

performance.mark(KBN_LOAD_MARKS, {
detail: 'setup_done',
detail: LOAD_SETUP_DONE,
});

return { fatalErrors: this.fatalErrorsSetup };
Expand Down Expand Up @@ -300,13 +321,13 @@ export class CoreSystem {
});

performance.mark(KBN_LOAD_MARKS, {
detail: 'start_done',
detail: LOAD_START_DONE,
});

// Wait for the first app navigation to report Kibana Loaded
firstValueFrom(application.currentAppId$.pipe(filter(Boolean))).then(() => {
performance.mark(KBN_LOAD_MARKS, {
detail: 'first_app_nav',
detail: LOAD_FIRST_NAV,
});
this.reportKibanaLoadedEvent(analytics);
});
Expand Down Expand Up @@ -344,51 +365,13 @@ export class CoreSystem {

private registerLoadedKibanaEventType(analytics: AnalyticsServiceSetup) {
analytics.registerEventType({
eventType: 'Loaded Kibana',
eventType: KIBANA_LOADED_EVENT,
schema: {
...PERFORMANCE_METRIC_EVENT_SCHEMA,
kibana_version: {
type: 'keyword',
_meta: { description: 'The version of Kibana' },
},
memory_js_heap_size_limit: {
type: 'long',
_meta: { description: 'The maximum size of the heap', optional: true },
},
memory_js_heap_size_total: {
type: 'long',
_meta: { description: 'The total size of the heap', optional: true },
},
memory_js_heap_size_used: {
type: 'long',
_meta: { description: 'The used size of the heap', optional: true },
},
load_started: {
type: 'long',
_meta: { description: 'When the render template starts loading assets', optional: true },
},
bootstrap_started: {
type: 'long',
_meta: { description: 'When kbnBootstrap callback is called', optional: true },
},
core_created: {
type: 'long',
_meta: { description: 'When core system is created', optional: true },
},
setup_done: {
type: 'long',
_meta: { description: 'When core system setup is complete', optional: true },
},
start_done: {
type: 'long',
_meta: { description: 'When core system start is complete', optional: true },
},
first_app_nav: {
type: 'long',
_meta: {
description: 'When the application emits the first app navigation',
optional: true,
},
},
protocol: {
type: 'keyword',
_meta: {
Expand Down
35 changes: 0 additions & 35 deletions src/core/public/fetch_optional_memory_info.test.ts

This file was deleted.

42 changes: 0 additions & 42 deletions src/core/public/fetch_optional_memory_info.ts

This file was deleted.

2 changes: 2 additions & 0 deletions src/core/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,4 +362,6 @@ export type {
NavType,
};

export type { PerformanceMetricEvent } from './utils';

export { __kbnBootstrap__ } from './kbn_bootstrap';
4 changes: 2 additions & 2 deletions src/core/public/kbn_bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
import { i18n } from '@kbn/i18n';
import { CoreSystem } from './core_system';
import { ApmSystem } from './apm_system';
import { KBN_LOAD_MARKS } from './utils';
import { KBN_LOAD_MARKS, LOAD_BOOTSTRAP_START } from './utils';

/** @internal */
export async function __kbnBootstrap__() {
performance.mark(KBN_LOAD_MARKS, {
detail: 'bootstrap_started',
detail: LOAD_BOOTSTRAP_START,
});

const injectedMetadata = JSON.parse(
Expand Down
Loading