[Bug] fix memory info extraction for fullstory (#115756)

* fix memory info extraction

* ts
This commit is contained in:
Liza Katz 2021-10-20 18:19:53 +03:00 committed by GitHub
parent a7fff86390
commit f1fe71650b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 10 deletions

View file

@ -138,14 +138,22 @@ describe('Cloud Plugin', () => {
describe('with memory', () => {
beforeAll(() => {
// @ts-expect-error
// @ts-expect-error 2339
window.performance.memory = {
someMetric: 1,
get jsHeapSizeLimit() {
return 3;
},
get totalJSHeapSize() {
return 2;
},
get usedJSHeapSize() {
return 1;
},
};
});
afterAll(() => {
// @ts-expect-error
// @ts-expect-error 2339
delete window.performance.memory;
});
@ -159,7 +167,9 @@ describe('Cloud Plugin', () => {
expect(fullStoryApiMock.event).toHaveBeenCalledWith('Loaded Kibana', {
kibana_version_str: initContext.env.packageInfo.version,
some_metric_int: 1,
memory_js_heap_size_limit_int: 3,
memory_js_heap_size_total_int: 2,
memory_js_heap_size_used_int: 1,
});
});
});

View file

@ -16,7 +16,6 @@ import {
} from 'src/core/public';
import { i18n } from '@kbn/i18n';
import { Subscription } from 'rxjs';
import { mapKeys, snakeCase } from 'lodash';
import type {
AuthenticatedUser,
SecurityPluginSetup,
@ -250,11 +249,16 @@ export class CloudPlugin implements Plugin<CloudSetup> {
}
// Get performance information from the browser (non standard property
const memoryInfo = mapKeys(
// @ts-expect-error
window.performance.memory || {},
(_, key) => `${snakeCase(key)}_int`
);
// @ts-expect-error 2339
const memory = window.performance.memory;
let memoryInfo = {};
if (memory) {
memoryInfo = {
memory_js_heap_size_limit_int: memory.jsHeapSizeLimit,
memory_js_heap_size_total_int: memory.totalJSHeapSize,
memory_js_heap_size_used_int: memory.usedJSHeapSize,
};
}
// Record an event that Kibana was opened so we can easily search for sessions that use Kibana
fullStory.event('Loaded Kibana', {
// `str` suffix is required, see docs: https://help.fullstory.com/hc/en-us/articles/360020623234