showing alerts created in the management page (#72031)

This commit is contained in:
Cauê Marcondes 2020-07-16 14:03:50 +01:00 committed by GitHub
parent 22365de6ed
commit fbf54f0023
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 6 deletions

View file

@ -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 () => {
@ -66,6 +102,10 @@ describe('getObservabilityAlerts', () => {
id: 5,
consumer: 'metrics',
},
{
id: 6,
consumer: 'alerts',
},
],
};
},
@ -91,6 +131,10 @@ describe('getObservabilityAlerts', () => {
id: 5,
consumer: 'metrics',
},
{
id: 6,
consumer: 'alerts',
},
]);
});
});

View file

@ -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(
@ -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);