forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[StdPerf] Extending kibana:plugin_render_time with custom metrics (el…
…astic#189115) ## Summary This PR enable consumers of `PerformanceContextProvider` to track customMetrics along `onPageReady`. Tracking customMetrics is important to further analyse and put into perspective TTFMP. e.g. is not the same trying to load a component that underneath is using thousand of documents vs one just using a couple of them. ### Changes Changes are leveraging existing `PerformanceMetricEvent` schema. ### Ideas One improvement could be reserving a pair of key/values (aka omitting them when defining `CustomMetrics` type) for explicitly dedicate them to timerange values. e.g. the amount of milliseconds between the start and end date in the timepicker. This could help us to keep the values in the same property for all observability applications and standardise the measurement of it.
- Loading branch information
Showing
6 changed files
with
185 additions
and
8 deletions.
There are no files selected for viewing
129 changes: 129 additions & 0 deletions
129
...e/analytics/core-analytics-browser-internal/src/track_performance_measure_entries.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
import { trackPerformanceMeasureEntries } from './track_performance_measure_entries'; | ||
import { analyticsClientMock } from './analytics_service.test.mocks'; | ||
|
||
interface MockEntryList { | ||
getEntries: () => [object]; | ||
} | ||
type ObsCallback = (_entries: MockEntryList, _obs: object) => undefined; | ||
const mockObs = { observe: jest.fn, disconnect: jest.fn }; | ||
|
||
const setupMockPerformanceObserver = (entries: [object]) => { | ||
const mockPerformanceObserver = function (callback: ObsCallback) { | ||
callback( | ||
{ | ||
getEntries: () => entries, | ||
}, | ||
mockObs | ||
); | ||
return mockObs; | ||
}; | ||
|
||
(global.PerformanceObserver as unknown) = mockPerformanceObserver; | ||
}; | ||
|
||
describe('trackPerformanceMeasureEntries', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test("doesn't report an analytics event when not receiving events", () => { | ||
setupMockPerformanceObserver([{}]); | ||
trackPerformanceMeasureEntries(analyticsClientMock, true); | ||
|
||
expect(analyticsClientMock.reportEvent).toHaveBeenCalledTimes(0); | ||
}); | ||
|
||
test("doesn't report an analytics event when receiving not 'kibana:performance' events", () => { | ||
setupMockPerformanceObserver([ | ||
{ | ||
name: '/', | ||
entryType: 'measure', | ||
startTime: 100, | ||
duration: 1000, | ||
detail: { | ||
eventName: 'kibana:plugin_render_time', | ||
type: 'anything', | ||
}, | ||
}, | ||
]); | ||
trackPerformanceMeasureEntries(analyticsClientMock, true); | ||
|
||
expect(analyticsClientMock.reportEvent).toHaveBeenCalledTimes(0); | ||
}); | ||
|
||
test("doesn't report an analytics event when receiving not 'measure' events", () => { | ||
setupMockPerformanceObserver([ | ||
{ | ||
name: '/', | ||
entryType: 'anything', | ||
startTime: 100, | ||
duration: 1000, | ||
detail: { | ||
eventName: 'kibana:plugin_render_time', | ||
type: 'kibana:performance', | ||
}, | ||
}, | ||
]); | ||
trackPerformanceMeasureEntries(analyticsClientMock, true); | ||
|
||
expect(analyticsClientMock.reportEvent).toHaveBeenCalledTimes(0); | ||
}); | ||
|
||
test('reports an analytics event when receiving "measure" and "kibana:performance" events', () => { | ||
setupMockPerformanceObserver([ | ||
{ | ||
name: '/', | ||
entryType: 'measure', | ||
startTime: 100, | ||
duration: 1000, | ||
detail: { | ||
eventName: 'kibana:plugin_render_time', | ||
type: 'kibana:performance', | ||
}, | ||
}, | ||
]); | ||
trackPerformanceMeasureEntries(analyticsClientMock, true); | ||
|
||
expect(analyticsClientMock.reportEvent).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('reports an analytics event ignoring keys and values not allowed', () => { | ||
setupMockPerformanceObserver([ | ||
{ | ||
name: '/', | ||
entryType: 'measure', | ||
startTime: 100, | ||
duration: 1000, | ||
detail: { | ||
eventName: 'kibana:plugin_render_time', | ||
type: 'kibana:performance', | ||
customMetrics: { | ||
key1: 'key1', | ||
value1: 'value1', | ||
key10: 'key10', | ||
value10: 'value10', | ||
anyKey: 'anyKey', | ||
anyValue: 'anyValue', | ||
}, | ||
}, | ||
}, | ||
]); | ||
trackPerformanceMeasureEntries(analyticsClientMock, true); | ||
|
||
expect(analyticsClientMock.reportEvent).toHaveBeenCalledTimes(1); | ||
expect(analyticsClientMock.reportEvent).toHaveBeenCalledWith('performance_metric', { | ||
duration: 1000, | ||
eventName: 'kibana:plugin_render_time', | ||
key1: 'key1', | ||
meta: { target: '/' }, | ||
value1: 'value1', | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters