Skip to content

Commit

Permalink
addressing pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes committed Jun 25, 2020
1 parent 33374c3 commit 0c2e6be
Show file tree
Hide file tree
Showing 4 changed files with 370 additions and 7 deletions.
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();
});
});
});
2 changes: 1 addition & 1 deletion x-pack/plugins/observability/public/data_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ interface DataHandler<T extends ObservabilityApp = ObservabilityApp> {

const dataHandlers: Partial<Record<ObservabilityApp, DataHandler>> = {};

export function registerDataHandler<T extends ObservabilityApp = ObservabilityApp>({
export function registerDataHandler<T extends ObservabilityApp>({
appName,
fetchData,
hasData,
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/observability/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
*/

import { PluginInitializerContext, PluginInitializer } from 'kibana/public';
import { Plugin, ObservabilityPluginSetup, ObservabilityPluginStart } from './plugin';
import { Plugin, ObservabilityPluginSetup } from './plugin';

export const plugin: PluginInitializer<ObservabilityPluginSetup, ObservabilityPluginStart> = (
export const plugin: PluginInitializer<ObservabilityPluginSetup, void> = (
context: PluginInitializerContext
) => {
return new Plugin(context);
};

export { ObservabilityPluginSetup, ObservabilityPluginStart };
export { ObservabilityPluginSetup };

export * from './components/action_menu';

Expand Down
Loading

0 comments on commit 0c2e6be

Please sign in to comment.