[Fullstory] Report mem usage (#114108) (#114325)

* memory

* jest test

* typo

Co-authored-by: Liza Katz <lizka.k@gmail.com>
This commit is contained in:
Kibana Machine 2021-10-07 15:32:20 -04:00 committed by GitHub
parent b05ee6ddca
commit a94d4cc5de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 8 deletions

View file

@ -136,16 +136,31 @@ describe('Cloud Plugin', () => {
expect(fullStoryApiMock.identify).not.toHaveBeenCalled();
});
it('calls FS.event when security is available', async () => {
const { initContext } = await setupPlugin({
config: { full_story: { enabled: true, org_id: 'foo' } },
currentUserProps: {
username: '1234',
},
describe('with memory', () => {
beforeAll(() => {
// @ts-expect-error
window.performance.memory = {
someMetric: 1,
};
});
expect(fullStoryApiMock.event).toHaveBeenCalledWith('Loaded Kibana', {
kibana_version_str: initContext.env.packageInfo.version,
afterAll(() => {
// @ts-expect-error
delete window.performance.memory;
});
it('calls FS.event when security is available', async () => {
const { initContext } = await setupPlugin({
config: { full_story: { enabled: true, org_id: 'foo' } },
currentUserProps: {
username: '1234',
},
});
expect(fullStoryApiMock.event).toHaveBeenCalledWith('Loaded Kibana', {
kibana_version_str: initContext.env.packageInfo.version,
some_metric_int: 1,
});
});
});

View file

@ -16,6 +16,7 @@ import {
} from 'src/core/public';
import { i18n } from '@kbn/i18n';
import { Subscription } from 'rxjs';
import { mapKeys, snakeCase } from 'lodash';
import type {
AuthenticatedUser,
SecurityPluginSetup,
@ -248,10 +249,17 @@ 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`
);
// 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
kibana_version_str: this.initializerContext.env.packageInfo.version,
...memoryInfo,
});
}
}