Skip to content

Commit 3d11da5

Browse files
feature: check user permissions to determine alerting path
1 parent daab768 commit 3d11da5

15 files changed

Lines changed: 106 additions & 35 deletions

web/src/components/Incidents/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ export const fetchDataForIncidentsAndAlerts = (
7777
prometheusUrlProps: {
7878
endpoint: PrometheusEndpoint.QUERY_RANGE,
7979
endTime: range.endTime,
80-
namespace: '',
8180
query: customQuery,
8281
samples,
8382
timespan: range.duration,
8483
},
8584
basePath: getPrometheusBasePath({
8685
prometheus: 'cmo',
86+
useTenancyPath: false,
8787
}),
8888
});
8989

web/src/components/MetricsPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ export const QueryTable: FC<QueryTableProps> = ({ index, namespace, customDataso
675675
},
676676
basePath: getPrometheusBasePath({
677677
prometheus: 'cmo',
678-
namespace,
678+
useTenancyPath: namespace !== ALL_NAMESPACES_KEY,
679679
basePathOverride: customDatasource?.basePath,
680680
}),
681681
}),

web/src/components/alerting/AlertingPage.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const namespacedPages = [
5858
const AlertingPage: FC = () => {
5959
const { t } = useTranslation(process.env.I18N_NAMESPACE);
6060
const dispatch = useDispatch();
61+
const { useAlertsTenancy, accessCheckLoading } = useMonitoring();
6162

6263
const [perspective] = useActivePerspective();
6364
const { setNamespace } = useQueryNamespace();
@@ -100,7 +101,7 @@ const AlertingPage: FC = () => {
100101

101102
return (
102103
<>
103-
{namespacedPages.includes(pathname) && (
104+
{namespacedPages.includes(pathname) && !accessCheckLoading && useAlertsTenancy && (
104105
<NamespaceBar
105106
onNamespaceChange={(namespace) => {
106107
dispatch(alertingClearSelectorData(prometheus, namespace));

web/src/components/alerting/SilenceForm.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { consoleFetchJSON, NamespaceBar } from '@openshift-console/dynamic-plugin-sdk';
1+
import {
2+
consoleFetchJSON,
3+
DocumentTitle,
4+
NamespaceBar,
5+
} from '@openshift-console/dynamic-plugin-sdk';
26
import {
37
ActionGroup,
48
Alert,

web/src/components/alerting/SilencesDetailsPage.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import * as _ from 'lodash-es';
22
import type { FC } from 'react';
33

4-
import { Alert, ResourceIcon, Timestamp } from '@openshift-console/dynamic-plugin-sdk';
4+
import {
5+
Alert,
6+
DocumentTitle,
7+
ResourceIcon,
8+
Timestamp,
9+
} from '@openshift-console/dynamic-plugin-sdk';
510
import {
611
Breadcrumb,
712
BreadcrumbItem,

web/src/components/dashboards/legacy/legacy-variable-dropdowns.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@ const LegacyDashboardsVariableDropdown: FC<VariableDropdownProps> = ({ id, name
144144
if (!customDataSourceName) {
145145
return buildPrometheusUrl({
146146
prometheusUrlProps: prometheusProps,
147-
basePath: getPrometheusBasePath({ prometheus: 'cmo' }),
147+
basePath: getPrometheusBasePath({
148+
prometheus: 'cmo',
149+
useTenancyPath: namespace !== ALL_NAMESPACES_KEY,
150+
}),
148151
});
149152
} else if (extensionsResolved && hasExtensions) {
150153
const extension = extensions.find(
@@ -161,6 +164,7 @@ const LegacyDashboardsVariableDropdown: FC<VariableDropdownProps> = ({ id, name
161164
prometheusUrlProps: prometheusProps,
162165
basePath: getPrometheusBasePath({
163166
prometheus: 'cmo',
167+
useTenancyPath: namespace !== ALL_NAMESPACES_KEY,
164168
basePathOverride: dataSource?.basePath,
165169
}),
166170
});
@@ -171,7 +175,7 @@ const LegacyDashboardsVariableDropdown: FC<VariableDropdownProps> = ({ id, name
171175
setIsError(true);
172176
}
173177
},
174-
[customDataSourceName, extensions, extensionsResolved, hasExtensions],
178+
[customDataSourceName, extensions, extensionsResolved, hasExtensions, namespace],
175179
);
176180

177181
useEffect(() => {

web/src/components/dashboards/legacy/single-stat.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { PrometheusEndpoint, PrometheusResponse } from '@openshift-console/dynam
55
import { Bullseye, Title } from '@patternfly/react-core';
66

77
import ErrorAlert from './error';
8-
import { getPrometheusBasePath, buildPrometheusUrl } from '../../utils';
8+
import { getPrometheusBasePath, buildPrometheusUrl, ALL_NAMESPACES_KEY } from '../../utils';
99
import { usePoll } from '../../console/utils/poll-hook';
1010
import { useSafeFetch } from '../../console/utils/safe-fetch-hook';
1111

@@ -118,10 +118,11 @@ const SingleStat: FC<Props> = ({ customDataSource, namespace, panel, pollInterva
118118
prometheusUrlProps: {
119119
endpoint: PrometheusEndpoint.QUERY,
120120
query,
121-
namespace: namespace,
121+
namespace,
122122
},
123123
basePath: getPrometheusBasePath({
124124
prometheus: 'cmo',
125+
useTenancyPath: namespace !== ALL_NAMESPACES_KEY,
125126
basePathOverride: customDataSource?.basePath,
126127
}),
127128
});

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { useState, useCallback } from 'react';
1818
import { useTranslation } from 'react-i18next';
1919

2020
import ErrorAlert from './error';
21-
import { getPrometheusBasePath, buildPrometheusUrl } from '../../utils';
21+
import { getPrometheusBasePath, buildPrometheusUrl, ALL_NAMESPACES_KEY } from '../../utils';
2222
import { usePoll } from '../../console/utils/poll-hook';
2323
import { useSafeFetch } from '../../console/utils/safe-fetch-hook';
2424

@@ -91,6 +91,7 @@ const Table: FC<Props> = ({ customDataSource, panel, pollInterval, queries, name
9191
},
9292
basePath: getPrometheusBasePath({
9393
prometheus: 'cmo',
94+
useTenancyPath: namespace !== ALL_NAMESPACES_KEY,
9495
basePathOverride: customDataSource?.basePath,
9596
}),
9697
}),

web/src/components/hooks/useQueryNamespace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const useQueryNamespace = () => {
1616
if (!queryNamespace) {
1717
setQueryNamespace(activeNamespace);
1818
}
19-
}, [queryNamespace, activeNamespace, setActiveNamespace]);
19+
}, [queryNamespace, activeNamespace, setActiveNamespace, setQueryNamespace]);
2020

2121
return {
2222
namespace: queryNamespace,

web/src/components/metrics/promql-expression-input.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,10 @@ export const PromQLExpressionInput: FC<PromQLExpressionInputProps> = ({
346346
// If we are using the tenancy path, then add the namespace as a query parameter at the end of
347347
// the url
348348
const namespaceQueryParam = namespace !== ALL_NAMESPACES_KEY ? `?namespace=${namespace}` : '';
349-
const url = `${getPrometheusBasePath({ namespace, prometheus })}/${
350-
PrometheusEndpoint.LABEL
351-
}/__name__/values${namespaceQueryParam}`;
349+
const url = `${getPrometheusBasePath({
350+
useTenancyPath: namespace !== ALL_NAMESPACES_KEY,
351+
prometheus,
352+
})}/${PrometheusEndpoint.LABEL}/__name__/values${namespaceQueryParam}`;
352353
safeFetch<LabelNamesResponse>(url)
353354
.then((response) => {
354355
const metrics = response?.data;

0 commit comments

Comments
 (0)