diff --git a/x-pack/plugins/observability/public/services/get_observability_alerts.test.ts b/x-pack/plugins/observability/public/services/get_observability_alerts.test.ts index 36ef1241983a..2027c9fa4a25 100644 --- a/x-pack/plugins/observability/public/services/get_observability_alerts.test.ts +++ b/x-pack/plugins/observability/public/services/get_observability_alerts.test.ts @@ -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', + }, ]); }); }); diff --git a/x-pack/plugins/observability/public/services/get_observability_alerts.ts b/x-pack/plugins/observability/public/services/get_observability_alerts.ts index 58ff9c92acbf..fe5451597688 100644 --- a/x-pack/plugins/observability/public/services/get_observability_alerts.ts +++ b/x-pack/plugins/observability/public/services/get_observability_alerts.ts @@ -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);