From db2295bea2b824c89e670049b34b31a4f9e75b1c Mon Sep 17 00:00:00 2001 From: Virginia Cepeda Date: Thu, 14 Sep 2023 11:43:46 -0300 Subject: [PATCH] Alerting: Prevent showing "Permissions denied" alert when not accurate (#74887) * Change way of obtaining external datasources info * Remove unneeded import * Create function to getExternalDsAlertManagers in datasource srv * Remove unused import --- .../useGetAlertManagersSourceNamesAndImage.tsx | 10 +++++----- .../app/features/alerting/unified/utils/datasource.ts | 4 ++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/useGetAlertManagersSourceNamesAndImage.tsx b/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/useGetAlertManagersSourceNamesAndImage.tsx index d858c55b237..289da5be638 100644 --- a/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/useGetAlertManagersSourceNamesAndImage.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/notificaton-preview/useGetAlertManagersSourceNamesAndImage.tsx @@ -1,7 +1,6 @@ import { AlertmanagerChoice } from '../../../../../../plugins/datasource/alertmanager/types'; import { alertmanagerApi } from '../../../api/alertmanagerApi'; -import { useExternalDataSourceAlertmanagers } from '../../../hooks/useExternalAmSelector'; -import { GRAFANA_RULES_SOURCE_NAME } from '../../../utils/datasource'; +import { getExternalDsAlertManagers, GRAFANA_RULES_SOURCE_NAME } from '../../../utils/datasource'; export interface AlertManagerNameWithImage { name: string; @@ -12,10 +11,11 @@ export const useGetAlertManagersSourceNamesAndImage = () => { //get current alerting config const { currentData: amConfigStatus } = alertmanagerApi.useGetAlertmanagerChoiceStatusQuery(undefined); - const externalDsAlertManagers: AlertManagerNameWithImage[] = useExternalDataSourceAlertmanagers().map((ds) => ({ - name: ds.dataSource.name, - img: ds.dataSource.meta.info.logos.small, + const externalDsAlertManagers = getExternalDsAlertManagers().map((ds) => ({ + name: ds.name, + img: ds.meta.info.logos.small, })); + const alertmanagerChoice = amConfigStatus?.alertmanagersChoice; const alertManagerSourceNamesWithImage: AlertManagerNameWithImage[] = alertmanagerChoice === AlertmanagerChoice.Internal diff --git a/public/app/features/alerting/unified/utils/datasource.ts b/public/app/features/alerting/unified/utils/datasource.ts index d57ee10db1d..eb40660e36b 100644 --- a/public/app/features/alerting/unified/utils/datasource.ts +++ b/public/app/features/alerting/unified/utils/datasource.ts @@ -47,6 +47,10 @@ export function getAlertManagerDataSources() { .sort((a, b) => a.name.localeCompare(b.name)); } +export function getExternalDsAlertManagers() { + return getAlertManagerDataSources().filter((ds) => ds.jsonData.handleGrafanaManagedAlerts); +} + const grafanaAlertManagerDataSource: AlertManagerDataSource = { name: GRAFANA_RULES_SOURCE_NAME, imgUrl: 'public/img/grafana_icon.svg',