2020-06-25 17:19:38 +02:00
|
|
|
/*
|
|
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
2021-02-04 03:12:39 +01:00
|
|
|
* or more contributor license agreements. Licensed under the Elastic License
|
|
|
|
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
|
|
* 2.0.
|
2020-06-25 17:19:38 +02:00
|
|
|
*/
|
2021-02-04 03:12:39 +01:00
|
|
|
|
2020-11-23 11:58:49 +01:00
|
|
|
import { registerDataHandler, getDataHandler } from './data_handler';
|
2020-07-14 11:05:48 +02:00
|
|
|
import moment from 'moment';
|
2021-06-18 17:30:53 +02:00
|
|
|
import { ApmIndicesConfig } from '../common/typings';
|
|
|
|
|
|
|
|
const sampleAPMIndices = {
|
|
|
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
|
|
'apm_oss.transactionIndices': 'apm-*',
|
|
|
|
} as ApmIndicesConfig;
|
2020-06-25 17:19:38 +02:00
|
|
|
|
|
|
|
const params = {
|
2020-07-14 11:05:48 +02:00
|
|
|
absoluteTime: {
|
|
|
|
start: moment('2020-07-02T13:25:11.629Z').valueOf(),
|
|
|
|
end: moment('2020-07-09T13:25:11.629Z').valueOf(),
|
|
|
|
},
|
|
|
|
relativeTime: {
|
|
|
|
start: 'now-15m',
|
|
|
|
end: 'now',
|
|
|
|
},
|
2020-06-25 17:19:38 +02:00
|
|
|
bucketSize: '10s',
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('registerDataHandler', () => {
|
2020-07-16 16:48:12 +02:00
|
|
|
const originalConsole = global.console;
|
|
|
|
beforeAll(() => {
|
2021-06-18 17:30:53 +02:00
|
|
|
// mocks console to avoid polluting the test output
|
2020-07-16 16:48:12 +02:00
|
|
|
global.console = ({ error: jest.fn() } as unknown) as typeof console;
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
global.console = originalConsole;
|
|
|
|
});
|
|
|
|
|
2020-06-25 17:19:38 +02:00
|
|
|
describe('APM', () => {
|
|
|
|
registerDataHandler({
|
|
|
|
appName: 'apm',
|
|
|
|
fetchData: async () => {
|
|
|
|
return {
|
|
|
|
title: 'apm',
|
|
|
|
appLink: '/apm',
|
|
|
|
stats: {
|
|
|
|
services: {
|
|
|
|
label: 'services',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
transactions: {
|
|
|
|
label: 'transactions',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
series: {
|
|
|
|
transactions: {
|
|
|
|
label: 'transactions',
|
|
|
|
coordinates: [{ x: 1 }],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
2021-06-18 17:30:53 +02:00
|
|
|
hasData: async () => ({ hasData: true, indices: sampleAPMIndices }),
|
2020-06-25 17:19:38 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('registered data handler', () => {
|
|
|
|
const dataHandler = getDataHandler('apm');
|
|
|
|
expect(dataHandler?.fetchData).toBeDefined();
|
|
|
|
expect(dataHandler?.hasData).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns data when fetchData is called', async () => {
|
|
|
|
const dataHandler = getDataHandler('apm');
|
|
|
|
const response = await dataHandler?.fetchData(params);
|
|
|
|
expect(response).toEqual({
|
|
|
|
title: 'apm',
|
|
|
|
appLink: '/apm',
|
|
|
|
stats: {
|
|
|
|
services: {
|
|
|
|
label: 'services',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
transactions: {
|
|
|
|
label: 'transactions',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
series: {
|
|
|
|
transactions: {
|
|
|
|
label: 'transactions',
|
|
|
|
coordinates: [{ x: 1 }],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns true when hasData is called', async () => {
|
|
|
|
const dataHandler = getDataHandler('apm');
|
|
|
|
const hasData = await dataHandler?.hasData();
|
|
|
|
expect(hasData).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('Logs', () => {
|
|
|
|
registerDataHandler({
|
|
|
|
appName: 'infra_logs',
|
|
|
|
fetchData: async () => {
|
|
|
|
return {
|
|
|
|
title: 'logs',
|
|
|
|
appLink: '/logs',
|
|
|
|
stats: {
|
|
|
|
foo: {
|
|
|
|
label: 'Foo',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
bar: {
|
|
|
|
label: 'bar',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
series: {
|
|
|
|
foo: {
|
|
|
|
label: 'Foo',
|
|
|
|
coordinates: [{ x: 1 }],
|
|
|
|
},
|
|
|
|
bar: {
|
|
|
|
label: 'Bar',
|
|
|
|
coordinates: [{ x: 1 }],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
hasData: async () => true,
|
|
|
|
});
|
|
|
|
|
|
|
|
it('registered data handler', () => {
|
|
|
|
const dataHandler = getDataHandler('infra_logs');
|
|
|
|
expect(dataHandler?.fetchData).toBeDefined();
|
|
|
|
expect(dataHandler?.hasData).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns data when fetchData is called', async () => {
|
|
|
|
const dataHandler = getDataHandler('infra_logs');
|
|
|
|
const response = await dataHandler?.fetchData(params);
|
|
|
|
expect(response).toEqual({
|
|
|
|
title: 'logs',
|
|
|
|
appLink: '/logs',
|
|
|
|
stats: {
|
|
|
|
foo: {
|
|
|
|
label: 'Foo',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
bar: {
|
|
|
|
label: 'bar',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
series: {
|
|
|
|
foo: {
|
|
|
|
label: 'Foo',
|
|
|
|
coordinates: [{ x: 1 }],
|
|
|
|
},
|
|
|
|
bar: {
|
|
|
|
label: 'Bar',
|
|
|
|
coordinates: [{ x: 1 }],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns true when hasData is called', async () => {
|
|
|
|
const dataHandler = getDataHandler('apm');
|
|
|
|
const hasData = await dataHandler?.hasData();
|
|
|
|
expect(hasData).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('Uptime', () => {
|
|
|
|
registerDataHandler({
|
2021-04-20 22:00:21 +02:00
|
|
|
appName: 'synthetics',
|
2020-06-25 17:19:38 +02:00
|
|
|
fetchData: async () => {
|
|
|
|
return {
|
|
|
|
title: 'uptime',
|
|
|
|
appLink: '/uptime',
|
|
|
|
stats: {
|
|
|
|
monitors: {
|
|
|
|
label: 'Monitors',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
up: {
|
|
|
|
label: 'Up',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
down: {
|
|
|
|
label: 'Down',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
series: {
|
|
|
|
down: {
|
|
|
|
label: 'Down',
|
|
|
|
coordinates: [{ x: 1 }],
|
|
|
|
},
|
|
|
|
up: {
|
|
|
|
label: 'Up',
|
|
|
|
coordinates: [{ x: 1 }],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
2021-04-20 22:00:21 +02:00
|
|
|
hasData: async () => ({ hasData: true, indices: 'heartbeat-*,synthetics-*' }),
|
2020-06-25 17:19:38 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('registered data handler', () => {
|
2021-04-20 22:00:21 +02:00
|
|
|
const dataHandler = getDataHandler('synthetics');
|
2020-06-25 17:19:38 +02:00
|
|
|
expect(dataHandler?.fetchData).toBeDefined();
|
|
|
|
expect(dataHandler?.hasData).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns data when fetchData is called', async () => {
|
2021-04-20 22:00:21 +02:00
|
|
|
const dataHandler = getDataHandler('synthetics');
|
2020-06-25 17:19:38 +02:00
|
|
|
const response = await dataHandler?.fetchData(params);
|
|
|
|
expect(response).toEqual({
|
|
|
|
title: 'uptime',
|
|
|
|
appLink: '/uptime',
|
|
|
|
stats: {
|
|
|
|
monitors: {
|
|
|
|
label: 'Monitors',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
up: {
|
|
|
|
label: 'Up',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
down: {
|
|
|
|
label: 'Down',
|
|
|
|
type: 'number',
|
|
|
|
value: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
series: {
|
|
|
|
down: {
|
|
|
|
label: 'Down',
|
|
|
|
coordinates: [{ x: 1 }],
|
|
|
|
},
|
|
|
|
up: {
|
|
|
|
label: 'Up',
|
|
|
|
coordinates: [{ x: 1 }],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns true when hasData is called', async () => {
|
|
|
|
const dataHandler = getDataHandler('apm');
|
|
|
|
const hasData = await dataHandler?.hasData();
|
|
|
|
expect(hasData).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
2020-10-05 19:15:13 +02:00
|
|
|
describe('Ux', () => {
|
|
|
|
registerDataHandler({
|
|
|
|
appName: 'ux',
|
|
|
|
fetchData: async () => {
|
|
|
|
return {
|
|
|
|
title: 'User Experience',
|
|
|
|
appLink: '/ux',
|
|
|
|
coreWebVitals: {
|
2020-12-23 20:25:34 +01:00
|
|
|
cls: 0.01,
|
2020-10-05 19:15:13 +02:00
|
|
|
fid: 5,
|
|
|
|
lcp: 1464.3333333333333,
|
|
|
|
tbt: 232.92166666666665,
|
|
|
|
fcp: 1154.8,
|
2020-10-28 19:33:30 +01:00
|
|
|
coreVitalPages: 100,
|
2020-10-05 19:15:13 +02:00
|
|
|
lcpRanks: [73, 16, 11],
|
|
|
|
fidRanks: [85, 4, 11],
|
|
|
|
clsRanks: [88, 7, 5],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
2021-04-20 22:00:21 +02:00
|
|
|
hasData: async () => ({
|
|
|
|
hasData: true,
|
|
|
|
serviceName: 'elastic-co-frontend',
|
|
|
|
indices: 'apm-*',
|
|
|
|
}),
|
2020-10-05 19:15:13 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('registered data handler', () => {
|
|
|
|
const dataHandler = getDataHandler('ux');
|
|
|
|
expect(dataHandler?.fetchData).toBeDefined();
|
|
|
|
expect(dataHandler?.hasData).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns data when fetchData is called', async () => {
|
|
|
|
const dataHandler = getDataHandler('ux');
|
|
|
|
const response = await dataHandler?.fetchData(params);
|
|
|
|
expect(response).toEqual({
|
|
|
|
title: 'User Experience',
|
|
|
|
appLink: '/ux',
|
|
|
|
coreWebVitals: {
|
2020-12-23 20:25:34 +01:00
|
|
|
cls: 0.01,
|
2020-10-05 19:15:13 +02:00
|
|
|
fid: 5,
|
|
|
|
lcp: 1464.3333333333333,
|
|
|
|
tbt: 232.92166666666665,
|
|
|
|
fcp: 1154.8,
|
2020-10-28 19:33:30 +01:00
|
|
|
coreVitalPages: 100,
|
2020-10-05 19:15:13 +02:00
|
|
|
lcpRanks: [73, 16, 11],
|
|
|
|
fidRanks: [85, 4, 11],
|
|
|
|
clsRanks: [88, 7, 5],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns true when hasData is called', async () => {
|
|
|
|
const dataHandler = getDataHandler('ux');
|
|
|
|
const hasData = await dataHandler?.hasData();
|
|
|
|
expect(hasData).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-06-25 17:19:38 +02:00
|
|
|
describe('Metrics', () => {
|
2021-04-06 17:38:12 +02:00
|
|
|
const makeRequestResponse = {
|
|
|
|
title: 'metrics',
|
|
|
|
appLink: '/metrics',
|
|
|
|
sort: () => makeRequest(),
|
|
|
|
series: [],
|
|
|
|
};
|
|
|
|
const makeRequest = async () => {
|
|
|
|
return makeRequestResponse;
|
|
|
|
};
|
2020-06-25 17:19:38 +02:00
|
|
|
registerDataHandler({
|
|
|
|
appName: 'infra_metrics',
|
2021-04-06 17:38:12 +02:00
|
|
|
fetchData: makeRequest,
|
2020-06-25 17:19:38 +02:00
|
|
|
hasData: async () => true,
|
|
|
|
});
|
|
|
|
|
|
|
|
it('registered data handler', () => {
|
|
|
|
const dataHandler = getDataHandler('infra_metrics');
|
|
|
|
expect(dataHandler?.fetchData).toBeDefined();
|
|
|
|
expect(dataHandler?.hasData).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns data when fetchData is called', async () => {
|
|
|
|
const dataHandler = getDataHandler('infra_metrics');
|
|
|
|
const response = await dataHandler?.fetchData(params);
|
2021-04-06 17:38:12 +02:00
|
|
|
expect(response).toEqual(makeRequestResponse);
|
2020-06-25 17:19:38 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('returns true when hasData is called', async () => {
|
|
|
|
const dataHandler = getDataHandler('apm');
|
|
|
|
const hasData = await dataHandler?.hasData();
|
|
|
|
expect(hasData).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|