mirror of
https://github.com/grafana/grafana.git
synced 2024-11-26 02:40:26 -06:00
Alerting: Update logic for checking if contact point is being used (#81713)
Don't count autorgenerated policy in receiver level when checking if contact point is used
This commit is contained in:
parent
3251b2e9b7
commit
cd0f299297
@ -1,10 +1,12 @@
|
||||
import { countBy, split, trim, upperFirst } from 'lodash';
|
||||
import { ReactNode } from 'react';
|
||||
|
||||
import { config } from '@grafana/runtime';
|
||||
import {
|
||||
AlertManagerCortexConfig,
|
||||
GrafanaManagedContactPoint,
|
||||
GrafanaManagedReceiverConfig,
|
||||
MatcherOperator,
|
||||
Route,
|
||||
} from 'app/plugins/datasource/alertmanager/types';
|
||||
import { NotifierDTO, NotifierStatus, ReceiversStateDTO } from 'app/types';
|
||||
@ -17,6 +19,8 @@ import { getOnCallMetadata, ReceiverPluginMetadata } from '../receivers/grafanaA
|
||||
|
||||
import { RECEIVER_META_KEY, RECEIVER_PLUGIN_META_KEY, RECEIVER_STATUS_KEY } from './useContactPoints';
|
||||
|
||||
const AUTOGENERATED_RECEIVER_POLICY_MATCHER_KEY = '__grafana_receiver__';
|
||||
|
||||
export function isProvisioned(contactPoint: GrafanaManagedContactPoint) {
|
||||
// for some reason the provenance is on the receiver and not the entire contact point
|
||||
const provenance = contactPoint.grafana_managed_receiver_configs?.find((receiver) => receiver.provenance)?.provenance;
|
||||
@ -126,10 +130,27 @@ export function enhanceContactPointsWithMetadata(
|
||||
};
|
||||
});
|
||||
}
|
||||
export function isAutoGeneratedPolicy(route: Route) {
|
||||
const simplifiedRoutingToggleEnabled = config.featureToggles.alertingSimplifiedRouting ?? false;
|
||||
if (!simplifiedRoutingToggleEnabled) {
|
||||
return false;
|
||||
}
|
||||
if (!route.object_matchers) {
|
||||
return false;
|
||||
}
|
||||
return (
|
||||
route.object_matchers.some((objectMatcher) => {
|
||||
return (
|
||||
objectMatcher[0] === AUTOGENERATED_RECEIVER_POLICY_MATCHER_KEY && objectMatcher[1] === MatcherOperator.equal
|
||||
);
|
||||
}) ?? false
|
||||
);
|
||||
}
|
||||
|
||||
export function getUsedContactPoints(route: Route): string[] {
|
||||
const childrenContactPoints = route.routes?.flatMap((route) => getUsedContactPoints(route)) ?? [];
|
||||
if (route.receiver) {
|
||||
// we don't want to count the autogenerated policy for receiver level, for checking if a contact point is used
|
||||
if (route.receiver && !isAutoGeneratedPolicy(route)) {
|
||||
return [route.receiver, ...childrenContactPoints];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user