@@ -26,23 +26,24 @@ import {
2626 getAdditionalSources ,
2727} from '../components/alerting/AlertUtils' ;
2828import { MonitoringState } from '../store/store' ;
29- import { getObserveState , usePerspective } from '../components/hooks/usePerspective' ;
29+ import { getObserveState } from '../components/hooks/usePerspective' ;
3030
3131const POLLING_INTERVAL_MS = 15 * 1000 ; // 15 seconds
3232
33- export const useAlerts = ( props ?: { overrideNamespace ?: string } ) => {
33+ export const useAlerts = ( props ?: { dontUseTenancy ?: boolean } ) => {
3434 // Retrieve external information which dictates which alerts to load and use
3535 const { plugin } = useMonitoring ( ) ;
3636 const [ namespace ] = useActiveNamespace ( ) ;
37- const { prometheus, useAlertsTenancy } = useMonitoring ( ) ;
38- const { perspective } = usePerspective ( ) ;
39- const overriddenNamespace = props ?. overrideNamespace ? props . overrideNamespace : namespace ;
37+ const { prometheus, useAlertsTenancy, accessCheckLoading } = useMonitoring ( ) ;
38+ const overriddenNamespace =
39+ props ?. dontUseTenancy || ! useAlertsTenancy ? ALL_NAMESPACES_KEY : namespace ;
4040
4141 // Start polling for alerts, rules, and silences
4242 const { trigger } = useAlertsPoller ( {
4343 namespace : overriddenNamespace ,
4444 prometheus,
4545 useAlertsTenancy,
46+ accessCheckLoading,
4647 } ) ;
4748
4849 // Retrieve alerts, rules and silences from the store, which is populated in the poller
@@ -97,16 +98,6 @@ export const useAlerts = (props?: { overrideNamespace?: string }) => {
9798 return clusterArray . sort ( ) ;
9899 } , [ silences ] ) ;
99100
100- // When a user with cluster scoped alerts retrieves alerts from the tenancy API endpoint
101- // the API will still retrun ALL alerts, not just the ones which are available at that tenant
102- // As such we manually filter down the alerts on the frontend
103- const namespacedAlerts = useMemo ( ( ) => {
104- if ( perspective === 'acm' || namespace === ALL_NAMESPACES_KEY ) {
105- return alerts ;
106- }
107- return alerts ?. filter ( ( alert ) => alert . labels ?. namespace === namespace ) ;
108- } , [ alerts , perspective , namespace ] ) ;
109-
110101 return {
111102 trigger,
112103 additionalAlertSourceLabels,
@@ -116,18 +107,20 @@ export const useAlerts = (props?: { overrideNamespace?: string }) => {
116107 rulesAlertLoading,
117108 rules,
118109 silences,
119- alerts : namespacedAlerts ,
110+ alerts,
120111 } ;
121112} ;
122113
123114const useAlertsPoller = ( {
124115 namespace,
125116 prometheus,
126117 useAlertsTenancy,
118+ accessCheckLoading,
127119} : {
128120 namespace ?: string ;
129121 prometheus : Prometheus ;
130122 useAlertsTenancy : boolean ;
123+ accessCheckLoading : boolean ;
131124} ) => {
132125 const dispatch = useDispatch ( ) ;
133126 const [ customExtensions ] =
@@ -148,14 +141,27 @@ const useAlertsPoller = ({
148141 prometheusUrlProps : { endpoint : PrometheusEndpoint . RULES , namespace } ,
149142 basePath : getPrometheusBasePath ( { prometheus, useTenancyPath : useAlertsTenancy } ) ,
150143 } ) ;
151- const silencesUrl = getAlertmanagerSilencesUrl ( { prometheus, namespace } ) ;
144+ const silencesUrl = getAlertmanagerSilencesUrl ( {
145+ prometheus,
146+ namespace,
147+ useTenancyPath : useAlertsTenancy ,
148+ } ) ;
152149
153150 const fetchDispatch = ( ) =>
154- dispatch ( fetchAlertingData ( prometheus , namespace , rulesUrl , alertsSource , silencesUrl ) ) ;
151+ dispatch (
152+ fetchAlertingData (
153+ prometheus ,
154+ namespace ,
155+ rulesUrl ,
156+ alertsSource ,
157+ silencesUrl ,
158+ ! accessCheckLoading , // Wait to poll until we know which endpoint to use
159+ ) ,
160+ ) ;
155161
156162 const dependencies = useMemo (
157- ( ) => [ namespace , rulesUrl , silencesUrl ] ,
158- [ namespace , rulesUrl , silencesUrl ] ,
163+ ( ) => [ namespace , rulesUrl , silencesUrl , useAlertsTenancy , accessCheckLoading ] ,
164+ [ namespace , rulesUrl , silencesUrl , useAlertsTenancy , accessCheckLoading ] ,
159165 ) ;
160166
161167 usePoll ( fetchDispatch , POLLING_INTERVAL_MS , dependencies ) ;
0 commit comments