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

[Bug] fix memory info extraction for fullstory #115756

Merged
merged 2 commits into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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