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

[Observability] Fixing dynamic return type based on the appName #69894

Merged
merged 2 commits into from
Jun 25, 2020
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
365 changes: 365 additions & 0 deletions x-pack/plugins/observability/public/data_handler.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,365 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { registerDataHandler, getDataHandler } from './data_handler';

const params = {
startTime: '0',
endTime: '1',
bucketSize: '10s',
};

describe('registerDataHandler', () => {
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 }],
},
},
};
},
hasData: async () => true,
});

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({
appName: 'uptime',
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 }],
},
},
};
},
hasData: async () => true,
});

it('registered data handler', () => {
const dataHandler = getDataHandler('uptime');
expect(dataHandler?.fetchData).toBeDefined();
expect(dataHandler?.hasData).toBeDefined();
});

it('returns data when fetchData is called', async () => {
const dataHandler = getDataHandler('uptime');
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();
});
});
describe('Metrics', () => {
registerDataHandler({
appName: 'infra_metrics',
fetchData: async () => {
return {
title: 'metrics',
appLink: '/metrics',
stats: {
hosts: {
label: 'hosts',
type: 'number',
value: 1,
},
cpu: {
label: 'cpu',
type: 'number',
value: 1,
},
memory: {
label: 'memory',
type: 'number',
value: 1,
},
disk: {
label: 'disk',
type: 'number',
value: 1,
},
inboundTraffic: {
label: 'inboundTraffic',
type: 'number',
value: 1,
},
outboundTraffic: {
label: 'outboundTraffic',
type: 'number',
value: 1,
},
},
series: {
inboundTraffic: {
label: 'inbound Traffic',
coordinates: [{ x: 1 }],
},
outboundTraffic: {
label: 'outbound Traffic',
coordinates: [{ x: 1 }],
},
},
};
},
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);
expect(response).toEqual({
title: 'metrics',
appLink: '/metrics',
stats: {
hosts: {
label: 'hosts',
type: 'number',
value: 1,
},
cpu: {
label: 'cpu',
type: 'number',
value: 1,
},
memory: {
label: 'memory',
type: 'number',
value: 1,
},
disk: {
label: 'disk',
type: 'number',
value: 1,
},
inboundTraffic: {
label: 'inboundTraffic',
type: 'number',
value: 1,
},
outboundTraffic: {
label: 'outboundTraffic',
type: 'number',
value: 1,
},
},
series: {
inboundTraffic: {
label: 'inbound Traffic',
coordinates: [{ x: 1 }],
},
outboundTraffic: {
label: 'outbound Traffic',
coordinates: [{ x: 1 }],
},
},
});
});

it('returns true when hasData is called', async () => {
const dataHandler = getDataHandler('apm');
const hasData = await dataHandler?.hasData();
expect(hasData).toBeTruthy();
});
});
});
Loading