Skip to content

Commit

Permalink
[Bug] fix memory info extraction for fullstory (elastic#115756)
Browse files Browse the repository at this point in the history
* fix memory info extraction

* ts
  • Loading branch information
lizozom authored and kibanamachine committed Oct 20, 2021
1 parent 1dd183a commit 0326dc2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
18 changes: 14 additions & 4 deletions x-pack/plugins/cloud/public/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});

Expand All @@ -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,
});
});
});
Expand Down
16 changes: 10 additions & 6 deletions x-pack/plugins/cloud/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0326dc2

Please sign in to comment.