Skip to content

Commit 2fd214b

Browse files
Merge pull request #658 from PeterYurkovich/multi-namespace-dev
OU-1077: namespace dropdown fixes
2 parents c89fe68 + 69eb8c4 commit 2fd214b

17 files changed

+120
-107
lines changed

web/src/components/MetricsPage.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ const QueryKebab: FC<{ index: number }> = ({ index }) => {
613613

614614
export const QueryTable: FC<QueryTableProps> = ({ index, namespace, customDatasource, units }) => {
615615
const { t } = useTranslation(process.env.I18N_NAMESPACE);
616-
const { plugin } = useMonitoring();
616+
const { plugin, accessCheckLoading, useMetricsTenancy } = useMonitoring();
617617

618618
const [data, setData] = useState<PrometheusData>();
619619
const [error, setError] = useState<PrometheusAPIError>();
@@ -665,7 +665,7 @@ export const QueryTable: FC<QueryTableProps> = ({ index, namespace, customDataso
665665
// If the namespace is defined getPrometheusURL will use
666666
// the PROMETHEUS_TENANCY_BASE_PATH for requests in the developer view
667667
const tick = () => {
668-
if (isEnabled && isExpanded && query) {
668+
if (isEnabled && isExpanded && !accessCheckLoading && query) {
669669
safeFetch<PrometheusResponse>(
670670
buildPrometheusUrl({
671671
prometheusUrlProps: {
@@ -675,7 +675,7 @@ export const QueryTable: FC<QueryTableProps> = ({ index, namespace, customDataso
675675
},
676676
basePath: getPrometheusBasePath({
677677
prometheus: 'cmo',
678-
useTenancyPath: namespace !== ALL_NAMESPACES_KEY,
678+
useTenancyPath: useMetricsTenancy,
679679
basePathOverride: customDatasource?.basePath,
680680
}),
681681
}),
@@ -693,7 +693,16 @@ export const QueryTable: FC<QueryTableProps> = ({ index, namespace, customDataso
693693
}
694694
};
695695

696-
usePoll(tick, pollInterval, namespace, query, span, lastRequestTime);
696+
usePoll(
697+
tick,
698+
pollInterval,
699+
namespace,
700+
query,
701+
span,
702+
lastRequestTime,
703+
useMetricsTenancy,
704+
accessCheckLoading,
705+
);
697706

698707
useEffect(() => {
699708
setData(undefined);
@@ -1047,7 +1056,6 @@ const QueryBrowserWrapper: FC<{
10471056
units: GraphUnits;
10481057
}> = ({ customDataSourceName, customDataSource, customDatasourceError, units }) => {
10491058
const { t } = useTranslation(process.env.I18N_NAMESPACE);
1050-
const [activeNamespace] = useActiveNamespace();
10511059
const { plugin } = useMonitoring();
10521060

10531061
const dispatch = useDispatch();
@@ -1162,7 +1170,6 @@ const QueryBrowserWrapper: FC<{
11621170
units={units}
11631171
showStackedControl
11641172
showDisconnectedControl
1165-
useTenancy={activeNamespace !== ALL_NAMESPACES_KEY}
11661173
/>
11671174
);
11681175
};

web/src/components/alerting/AlertRulesDetailsPage.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ import { MonitoringProvider } from '../../contexts/MonitoringContext';
6868

6969
import { DataTestIDs } from '../data-test';
7070
import { useAlerts } from '../../hooks/useAlerts';
71-
import { useQueryNamespace } from '../hooks/useQueryNamespace';
7271

7372
// Renders Prometheus template text and highlights any {{ ... }} tags that it contains
7473
const PrometheusTemplate = ({ text }) => (
@@ -147,7 +146,6 @@ const AlertRulesDetailsPage_: FC = () => {
147146
const { rules, rulesAlertLoading } = useAlerts();
148147

149148
const { perspective } = usePerspective();
150-
const { namespace } = useQueryNamespace();
151149

152150
const rule = _.find(rules, { id: params.id });
153151

@@ -356,7 +354,6 @@ const AlertRulesDetailsPage_: FC = () => {
356354
{!sourceId || sourceId === 'prometheus' ? (
357355
<Graph
358356
formatSeriesTitle={formatSeriesTitle}
359-
namespace={namespace}
360357
query={rule?.query}
361358
ruleDuration={rule?.duration}
362359
showLegend

web/src/components/alerting/AlertUtils.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ import {
5353
t_global_text_color_disabled,
5454
t_global_text_color_subtle,
5555
} from '@patternfly/react-tokens';
56-
import { ALL_NAMESPACES_KEY } from '../utils';
5756

5857
export const getAdditionalSources = <T extends Alert | Rule>(
5958
data: Array<T>,
@@ -243,7 +242,6 @@ export const PopoverField: FC<{ bodyContent: ReactNode; label: string }> = ({
243242
export const Graph: FC<GraphProps> = ({
244243
filterLabels = undefined,
245244
formatSeriesTitle,
246-
namespace,
247245
query,
248246
ruleDuration,
249247
}) => {
@@ -268,15 +266,13 @@ export const Graph: FC<GraphProps> = ({
268266
GraphLink={GraphLink}
269267
pollInterval={Math.round(timespan / 120)}
270268
queries={[query]}
271-
useTenancy={namespace !== ALL_NAMESPACES_KEY}
272269
/>
273270
);
274271
};
275272

276273
type GraphProps = {
277274
filterLabels?: PrometheusLabels;
278275
formatSeriesTitle?: FormatSeriesTitle;
279-
namespace?: string;
280276
query: string;
281277
ruleDuration: number;
282278
showLegend?: boolean;

web/src/components/alerting/AlertsDetailsPage.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ import {
8989
import { DataTestIDs } from '../data-test';
9090
import { useAlerts } from '../../hooks/useAlerts';
9191
import { useMonitoring } from '../../hooks/useMonitoring';
92-
import { useQueryNamespace } from '../hooks/useQueryNamespace';
9392

9493
const AlertsDetailsPage_: FC = () => {
9594
const { t } = useTranslation(process.env.I18N_NAMESPACE);
@@ -101,8 +100,6 @@ const AlertsDetailsPage_: FC = () => {
101100

102101
const { alerts, rulesAlertLoading, silences } = useAlerts();
103102

104-
const { namespace } = useQueryNamespace();
105-
106103
const hideGraphs = useSelector(
107104
(state: MonitoringState) => !!getObserveState(plugin, state).hideGraphs,
108105
);
@@ -244,12 +241,7 @@ const AlertsDetailsPage_: FC = () => {
244241
<Grid sm={12} md={6} hasGutter>
245242
<GridItem span={12}>
246243
{!sourceId || sourceId === 'prometheus' ? (
247-
<Graph
248-
filterLabels={labels}
249-
namespace={namespace}
250-
query={rule?.query}
251-
ruleDuration={rule?.duration}
252-
/>
244+
<Graph filterLabels={labels} query={rule?.query} ruleDuration={rule?.duration} />
253245
) : AlertsChart && !hideGraphs ? (
254246
<AlertsChart rule={rule} />
255247
) : null}

web/src/components/alerting/SilenceCreatePage.tsx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,42 @@ import { useTranslation } from 'react-i18next';
33
import { getAllQueryArguments } from '../console/utils/router';
44
import { SilenceForm } from './SilenceForm';
55
import { MonitoringProvider } from '../../contexts/MonitoringContext';
6-
import { ALL_NAMESPACES_KEY } from '../utils';
7-
import { useQueryNamespace } from '../hooks/useQueryNamespace';
86
import { useMonitoring } from '../../hooks/useMonitoring';
7+
import { LoadingBox } from '../console/console-shared/src/components/loading/LoadingBox';
8+
import { useQueryNamespace } from '../hooks/useQueryNamespace';
99

10-
const CreateSilencePage = ({ allowNamespace }: { allowNamespace: boolean }) => {
11-
const { namespace } = useQueryNamespace();
12-
const { useAlertsTenancy } = useMonitoring();
10+
const CreateSilencePage = () => {
11+
const { accessCheckLoading, useAlertsTenancy } = useMonitoring();
1312
const { t } = useTranslation(process.env.I18N_NAMESPACE);
1413

14+
// Set the activeNamespace to be the namespace query parameter if it is set
15+
useQueryNamespace();
16+
1517
const matchers = _.map(getAllQueryArguments(), (value, name) => ({
1618
name,
1719
value,
1820
isRegex: false,
1921
}));
2022

21-
const isNamespaced = allowNamespace && useAlertsTenancy && namespace !== ALL_NAMESPACES_KEY;
23+
if (accessCheckLoading) {
24+
return <LoadingBox />;
25+
}
2226

2327
return _.isEmpty(matchers) ? (
24-
<SilenceForm defaults={{}} title={t('Create silence')} isNamespaced={isNamespaced} />
28+
<SilenceForm defaults={{}} title={t('Create silence')} isNamespaced={useAlertsTenancy} />
2529
) : (
26-
<SilenceForm defaults={{ matchers }} title={t('Silence alert')} isNamespaced={isNamespaced} />
30+
<SilenceForm
31+
defaults={{ matchers }}
32+
title={t('Silence alert')}
33+
isNamespaced={useAlertsTenancy}
34+
/>
2735
);
2836
};
2937

3038
export const MpCmoCreateSilencePage = () => {
3139
return (
3240
<MonitoringProvider monitoringContext={{ plugin: 'monitoring-plugin', prometheus: 'cmo' }}>
33-
<CreateSilencePage allowNamespace={true} />
41+
<CreateSilencePage />
3442
</MonitoringProvider>
3543
);
3644
};
@@ -40,7 +48,7 @@ export const McpAcmCreateSilencePage = () => {
4048
<MonitoringProvider
4149
monitoringContext={{ plugin: 'monitoring-console-plugin', prometheus: 'acm' }}
4250
>
43-
<CreateSilencePage allowNamespace={false} />
51+
<CreateSilencePage />
4452
</MonitoringProvider>
4553
);
4654
};

web/src/components/alerting/SilenceEditPage.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { Silence, SilenceStates, useActiveNamespace } from '@openshift-console/dynamic-plugin-sdk';
1+
import { Silence, SilenceStates } from '@openshift-console/dynamic-plugin-sdk';
22
import { Alert } from '@patternfly/react-core';
33
import * as _ from 'lodash-es';
44
import { useTranslation } from 'react-i18next';
55
import { useParams } from 'react-router-dom-v5-compat';
66
import { StatusBox } from '../console/console-shared/src/components/status/StatusBox';
7-
import { ALL_NAMESPACES_KEY, SilenceResource, silenceState } from '../utils';
7+
import { SilenceResource, silenceState } from '../utils';
88
import { SilenceForm } from './SilenceForm';
99
import { MonitoringProvider } from '../../contexts/MonitoringContext';
1010
import { useAlerts } from '../../hooks/useAlerts';
@@ -31,8 +31,7 @@ const EditInfo = () => {
3131

3232
const SilenceEditPage = () => {
3333
const { t } = useTranslation(process.env.I18N_NAMESPACE);
34-
const [namespace] = useActiveNamespace();
35-
const { prometheus } = useMonitoring();
34+
const { accessCheckLoading, useAlertsTenancy } = useMonitoring();
3635
const params = useParams();
3736

3837
const { silences } = useAlerts();
@@ -54,14 +53,14 @@ const SilenceEditPage = () => {
5453
<StatusBox
5554
data={silence}
5655
label={SilenceResource.label}
57-
loaded={silences?.loaded}
56+
loaded={silences?.loaded && !accessCheckLoading}
5857
loadError={silences?.loadError}
5958
>
6059
<SilenceForm
6160
defaults={defaults}
6261
Info={isExpired ? undefined : EditInfo}
6362
title={isExpired ? t('Recreate silence') : t('Edit silence')}
64-
isNamespaced={prometheus === 'cmo' && namespace !== ALL_NAMESPACES_KEY}
63+
isNamespaced={useAlertsTenancy}
6564
/>
6665
</StatusBox>
6766
);

web/src/components/alerting/SilenceForm.tsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
consoleFetchJSON,
33
DocumentTitle,
44
NamespaceBar,
5+
useActiveNamespace,
56
} from '@openshift-console/dynamic-plugin-sdk';
67
import {
78
ActionGroup,
@@ -50,10 +51,9 @@ import { ExternalLink } from '../console/utils/link';
5051
import { useBoolean } from '../hooks/useBoolean';
5152
import { getSilenceAlertUrl, usePerspective } from '../hooks/usePerspective';
5253
import { DataTestIDs } from '../data-test';
53-
import { ALL_NAMESPACES_KEY, getAlertmanagerSilencesUrl } from '../utils';
54+
import { getAlertmanagerSilencesUrl } from '../utils';
5455
import { useAlerts } from '../../hooks/useAlerts';
5556
import { useMonitoring } from '../../hooks/useMonitoring';
56-
import { useQueryNamespace } from '../hooks/useQueryNamespace';
5757

5858
const durationOff = '-';
5959

@@ -133,8 +133,8 @@ const NegativeMatcherHelp = () => {
133133

134134
const SilenceForm_: FC<SilenceFormProps> = ({ defaults, Info, title, isNamespaced }) => {
135135
const { t } = useTranslation(process.env.I18N_NAMESPACE);
136-
const { namespace } = useQueryNamespace();
137-
const { prometheus, useAlertsTenancy } = useMonitoring();
136+
const [namespace] = useActiveNamespace();
137+
const { prometheus } = useMonitoring();
138138
const navigate = useNavigate();
139139

140140
const durations = useMemo(() => {
@@ -151,8 +151,6 @@ const SilenceForm_: FC<SilenceFormProps> = ({ defaults, Info, title, isNamespace
151151
};
152152
}, [t]);
153153

154-
const requireNamespace = isNamespaced && namespace !== ALL_NAMESPACES_KEY;
155-
156154
const now = new Date();
157155

158156
// Default to starting now if we have no default start time or if the default start time is in the
@@ -189,7 +187,7 @@ const SilenceForm_: FC<SilenceFormProps> = ({ defaults, Info, title, isNamespace
189187
// Since the namespace matcher MUST be the same as the namespace the request is being
190188
// made in, we remove the namespace value here and re-add it before sending the request
191189
const [matchers, setMatchers] = useState<Array<Matcher>>(
192-
(requireNamespace
190+
(isNamespaced
193191
? (defaults.matchers as Matcher[])?.filter((matcher) => matcher.name !== 'namespace')
194192
: defaults.matchers) ?? [{ isRegex: false, isEqual: true, name: '', value: '' }],
195193
);
@@ -224,7 +222,7 @@ const SilenceForm_: FC<SilenceFormProps> = ({ defaults, Info, title, isNamespace
224222

225223
const removeMatcher = (i: number): void => {
226224
// If we require the namespace don't allow removing it
227-
if (requireNamespace && i === 0) {
225+
if (isNamespaced && i === 0) {
228226
return;
229227
}
230228

@@ -251,7 +249,7 @@ const SilenceForm_: FC<SilenceFormProps> = ({ defaults, Info, title, isNamespace
251249
const url = getAlertmanagerSilencesUrl({
252250
prometheus,
253251
namespace,
254-
useTenancyPath: useAlertsTenancy,
252+
useTenancyPath: isNamespaced,
255253
});
256254
if (!url) {
257255
setError('Alertmanager URL not set');
@@ -284,7 +282,7 @@ const SilenceForm_: FC<SilenceFormProps> = ({ defaults, Info, title, isNamespace
284282

285283
consoleFetchJSON
286284
.post(
287-
getAlertmanagerSilencesUrl({ prometheus, namespace, useTenancyPath: useAlertsTenancy }),
285+
getAlertmanagerSilencesUrl({ prometheus, namespace, useTenancyPath: isNamespaced }),
288286
body,
289287
)
290288
.then(({ silenceID }) => {
@@ -311,7 +309,7 @@ const SilenceForm_: FC<SilenceFormProps> = ({ defaults, Info, title, isNamespace
311309
return (
312310
<>
313311
<DocumentTitle>{title}</DocumentTitle>
314-
<NamespaceBar />
312+
{isNamespaced && <NamespaceBar />}
315313
<PageSection hasBodyWrapper={false}>
316314
<Title headingLevel="h1">{title}</Title>
317315
<HelperText>
@@ -427,7 +425,7 @@ const SilenceForm_: FC<SilenceFormProps> = ({ defaults, Info, title, isNamespace
427425
</HelperText>
428426
</FormHelperText>
429427

430-
{requireNamespace && (
428+
{isNamespaced && (
431429
<Grid key={'namespace'} sm={12} md={4} hasGutter>
432430
<GridItem>
433431
<FormGroup label={t('Label name')}>

web/src/components/dashboards/legacy/graph.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const Graph: FC<Props> = ({
3535
onDataChange,
3636
}) => {
3737
const dispatch = useDispatch();
38-
const { plugin, useMetricsTenancy } = useMonitoring();
38+
const { plugin } = useMonitoring();
3939
const endTime = useSelector(
4040
(state: MonitoringState) => getObserveState(plugin, state).dashboards.endTime,
4141
);
@@ -67,7 +67,6 @@ const Graph: FC<Props> = ({
6767
timespan={timespan}
6868
units={units as GraphUnits}
6969
onDataChange={onDataChange}
70-
useTenancy={useMetricsTenancy}
7170
isPlain
7271
/>
7372
);

0 commit comments

Comments
 (0)