Skip to content

Commit

Permalink
showing alerts created in the management page (#72031)
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes authored Jul 16, 2020
1 parent 22365de commit fbf54f0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,43 @@ describe('getObservabilityAlerts', () => {
expect(alerts).toEqual([]);
});

it('Shows alerts from Observability', async () => {
it('Returns empty array when alerts are not allowed based on consumer type', async () => {
const core = ({
http: {
get: async () => {
return {
data: [
{
id: 1,
consumer: 'siem',
},
{
id: 2,
consumer: 'kibana',
},
{
id: 3,
consumer: 'index',
},
{
id: 4,
consumer: 'foo',
},
{
id: 5,
consumer: 'bar',
},
],
};
},
basePath,
},
} as unknown) as AppMountContext['core'];
const alerts = await getObservabilityAlerts({ core });
expect(alerts).toEqual([]);
});

it('Shows alerts from Observability and Alerts', async () => {
const core = ({
http: {
get: async () => {
Expand All @@ -66,6 +102,10 @@ describe('getObservabilityAlerts', () => {
id: 5,
consumer: 'metrics',
},
{
id: 6,
consumer: 'alerts',
},
],
};
},
Expand All @@ -91,6 +131,10 @@ describe('getObservabilityAlerts', () => {
id: 5,
consumer: 'metrics',
},
{
id: 6,
consumer: 'alerts',
},
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import { AppMountContext } from 'kibana/public';
import { Alert } from '../../../alerts/common';

const allowedConsumers = ['apm', 'uptime', 'logs', 'metrics', 'alerts'];

export async function getObservabilityAlerts({ core }: { core: AppMountContext['core'] }) {
try {
const { data = [] }: { data: Alert[] } = await core.http.get(
Expand All @@ -19,11 +21,7 @@ export async function getObservabilityAlerts({ core }: { core: AppMountContext['
}
);

return data.filter(({ consumer }) => {
return (
consumer === 'apm' || consumer === 'uptime' || consumer === 'logs' || consumer === 'metrics'
);
});
return data.filter(({ consumer }) => allowedConsumers.includes(consumer));
} catch (e) {
// eslint-disable-next-line no-console
console.error('Error while fetching alerts', e);
Expand Down

0 comments on commit fbf54f0

Please sign in to comment.