Skip to content

Commit 3c3fe3b

Browse files
Merge pull request #567 from PeterYurkovich/ou-949
OU-949: add namespace dropdown to dashboards page
2 parents 8298186 + f77b3a6 commit 3c3fe3b

44 files changed

Lines changed: 593 additions & 377 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

web/console-extensions.json

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,6 @@
9999
"insertAfter": "dashboards-virt"
100100
}
101101
},
102-
{
103-
"type": "console.tab",
104-
"properties": {
105-
"contextId": "dev-console-observe",
106-
"name": "%plugin__monitoring-plugin~Dashboards%",
107-
"href": "",
108-
"component": {
109-
"$codeRef": "LegacyDashboardsPage.MpCmoLegacyDashboardsPage"
110-
}
111-
}
112-
},
113102
{
114103
"type": "console.redux-reducer",
115104
"properties": {
@@ -276,5 +265,53 @@
276265
"path": ["/virt-monitoring/alerts/:ruleID"],
277266
"component": { "$codeRef": "AlertsDetailsPage.MpCmoAlertsDetailsPage" }
278267
}
268+
},
269+
{
270+
"type": "console.page/route",
271+
"properties": {
272+
"exact": false,
273+
"path": "/dev-monitoring/ns/:ns/alerts/:ruleID",
274+
"component": { "$codeRef": "DevRedirects.AlertRedirect" }
275+
}
276+
},
277+
{
278+
"type": "console.page/route",
279+
"properties": {
280+
"exact": false,
281+
"path": "/dev-monitoring/ns/:ns/rules/:id",
282+
"component": { "$codeRef": "DevRedirects.RulesRedirect" }
283+
}
284+
},
285+
{
286+
"type": "console.page/route",
287+
"properties": {
288+
"exact": false,
289+
"path": "/dev-monitoring/ns/:ns/silences/:id",
290+
"component": { "$codeRef": "DevRedirects.SilenceRedirect" }
291+
}
292+
},
293+
{
294+
"type": "console.page/route",
295+
"properties": {
296+
"exact": false,
297+
"path": "/dev-monitoring/ns/:ns/silences/:id/edit",
298+
"component": { "$codeRef": "DevRedirects.SilenceEditRedirect" }
299+
}
300+
},
301+
{
302+
"type": "console.page/route",
303+
"properties": {
304+
"exact": false,
305+
"path": "/dev-monitoring/ns/:ns/silences/~new",
306+
"component": { "$codeRef": "DevRedirects.SilenceNewRedirect" }
307+
}
308+
},
309+
{
310+
"type": "console.page/route",
311+
"properties": {
312+
"exact": false,
313+
"path": "/dev-monitoring/ns/:ns/metrics",
314+
"component": { "$codeRef": "DevRedirects.MetricsRedirect" }
315+
}
279316
}
280317
]

web/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@
190190
"MonitoringReducer": "./store/reducers",
191191
"IncidentsPage": "./components/Incidents/IncidentsPage",
192192
"TargetsPage": "./components/targets-page",
193-
"PrometheusRedirectPage": "./components/prometheus-redirect-page",
193+
"PrometheusRedirectPage": "./components/redirects/prometheus-redirect-page",
194+
"DevRedirects": "./components/redirects/dev-redirects",
194195
"MonitoringContext": "./contexts/MonitoringContext"
195196
},
196197
"dependencies": {

web/src/components/Incidents/IncidentsDetailsRowTable.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ interface IncidentsDetailsRowTableProps {
1717
}
1818

1919
const IncidentsDetailsRowTable = ({ alerts }: IncidentsDetailsRowTableProps) => {
20-
const [namespace, setNamespace] = useActiveNamespace();
20+
const [, setNamespace] = useActiveNamespace();
2121
const { perspective } = usePerspective();
2222
const { t } = useTranslation(process.env.I18N_NAMESPACE);
2323

@@ -34,7 +34,7 @@ const IncidentsDetailsRowTable = ({ alerts }: IncidentsDetailsRowTableProps) =>
3434
<Td dataLabel="expanded-details-alertname">
3535
<ResourceIcon kind={RuleResource.kind} />
3636
<Link
37-
to={getRuleUrl(perspective, alertDetails?.rule, namespace)}
37+
to={getRuleUrl(perspective, alertDetails?.rule)}
3838
onClick={() => setNamespace(ALL_NAMESPACES_KEY)}
3939
>
4040
{alertDetails.alertname}
@@ -63,7 +63,7 @@ const IncidentsDetailsRowTable = ({ alerts }: IncidentsDetailsRowTableProps) =>
6363
}
6464

6565
return null;
66-
}, [alerts, perspective, namespace, setNamespace]);
66+
}, [alerts, perspective, setNamespace]);
6767

6868
return (
6969
<Table borders={false} variant="compact" data-test={DataTestIDs.IncidentsDetailsTable.Table}>

web/src/components/Incidents/IncidentsPage.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ import IncidentFilterToolbarItem, {
6565
useStateOptions,
6666
} from './ToolbarItemFilter';
6767
import { MonitoringProvider } from '../../contexts/MonitoringContext';
68-
import { ALL_NAMESPACES_KEY } from '../utils';
6968
import { isEmpty } from 'lodash-es';
7069
import { DataTestIDs } from '../data-test';
7170
import { DocumentTitle } from '@openshift-console/dynamic-plugin-sdk';
@@ -75,7 +74,7 @@ const IncidentsPage = () => {
7574
const dispatch = useDispatch();
7675
const location = useLocation();
7776
const urlParams = useMemo(() => parseUrlParams(location.search), [location.search]);
78-
const { rules } = useAlerts({ overrideNamespace: ALL_NAMESPACES_KEY });
77+
const { rules } = useAlerts({ dontUseTenancy: true });
7978
const { theme } = usePatternFlyTheme();
8079
// loading states
8180
const [incidentsAreLoading, setIncidentsAreLoading] = useState(true);

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: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,15 @@ import {
114114
t_global_spacer_sm,
115115
t_global_font_family_mono,
116116
} from '@patternfly/react-tokens';
117-
import { QueryParamProvider, StringParam, useQueryParam } from 'use-query-params';
118-
import { ReactRouter5Adapter } from 'use-query-params/adapters/react-router-5';
117+
import { StringParam, useQueryParam } from 'use-query-params';
119118
import { GraphUnits, isGraphUnit } from './metrics/units';
120119
import { SimpleSelect, SimpleSelectOption } from '@patternfly/react-templates';
121120
import { valueFormatter } from './console/console-shared/src/components/query-browser/QueryBrowserTooltip';
122121
import { ALL_NAMESPACES_KEY } from './utils';
123122
import { MonitoringProvider } from '../contexts/MonitoringContext';
124123
import { DataTestIDs } from './data-test';
125124
import { useMonitoring } from '../hooks/useMonitoring';
125+
import { useQueryNamespace } from './hooks/useQueryNamespace';
126126

127127
// Stores information about the currently focused query input
128128
let focusedQuery;
@@ -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
}),
@@ -1278,14 +1278,7 @@ const GraphUnitsDropDown: FC = () => {
12781278
const MetricsPage_: FC = () => {
12791279
const { t } = useTranslation(process.env.I18N_NAMESPACE);
12801280
const [units, setUnits] = useQueryParam(QueryParams.Units, StringParam);
1281-
const [queryNamespace, setQueryNamespace] = useQueryParam(QueryParams.Namespace, StringParam);
1282-
const [activeNamespace, setActiveNamespace] = useActiveNamespace();
1283-
1284-
useEffect(() => {
1285-
if (queryNamespace && activeNamespace !== queryNamespace) {
1286-
setActiveNamespace(queryNamespace);
1287-
}
1288-
}, [queryNamespace, activeNamespace, setActiveNamespace]);
1281+
const { setNamespace } = useQueryNamespace();
12891282

12901283
const dispatch = useDispatch();
12911284

@@ -1368,7 +1361,7 @@ const MetricsPage_: FC = () => {
13681361
<NamespaceBar
13691362
onNamespaceChange={(namespace) => {
13701363
dispatch(queryBrowserDeleteAllQueries());
1371-
setQueryNamespace(namespace);
1364+
setNamespace(namespace);
13721365
}}
13731366
/>
13741367
<ListPageHeader title={t('Metrics')}>
@@ -1427,9 +1420,7 @@ const MetricsPage = withFallback(MetricsPage_);
14271420
export const MpCmoMetricsPage: React.FC = () => {
14281421
return (
14291422
<MonitoringProvider monitoringContext={{ plugin: 'monitoring-plugin', prometheus: 'cmo' }}>
1430-
<QueryParamProvider adapter={ReactRouter5Adapter}>
1431-
<MetricsPage />
1432-
</QueryParamProvider>
1423+
<MetricsPage />
14331424
</MonitoringProvider>
14341425
);
14351426
};

web/src/components/alerting/AlertDetail/SilencedByTable.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import type { FC, MouseEvent } from 'react';
22
import { useState, useMemo } from 'react';
3-
import {
4-
ResourceIcon,
5-
Silence,
6-
SilenceStates,
7-
useActiveNamespace,
8-
} from '@openshift-console/dynamic-plugin-sdk';
3+
import { ResourceIcon, Silence, SilenceStates } from '@openshift-console/dynamic-plugin-sdk';
94
import { useTranslation } from 'react-i18next';
105
import { useNavigate } from 'react-router-dom-v5-compat';
116
import {
@@ -30,13 +25,12 @@ import { t_global_spacer_xs } from '@patternfly/react-tokens';
3025
export const SilencedByList: FC<{ silences: Silence[] }> = ({ silences }) => {
3126
const { t } = useTranslation(process.env.I18N_NAMESPACE);
3227
const { perspective } = usePerspective();
33-
const [namespace] = useActiveNamespace();
3428
const navigate = useNavigate();
3529
const [isModalOpen, , setModalOpen, setModalClosed] = useBoolean(false);
3630
const [silence, setSilence] = useState<Silence | null>(null);
3731

3832
const editSilence = (event: MouseEvent, rowIndex: number) => {
39-
navigate(getEditSilenceAlertUrl(perspective, silences.at(rowIndex)?.id, namespace));
33+
navigate(getEditSilenceAlertUrl(perspective, silences.at(rowIndex)?.id));
4034
};
4135

4236
const rowActions = (silence: Silence): IAction[] => {
@@ -79,7 +73,7 @@ export const SilencedByList: FC<{ silences: Silence[] }> = ({ silences }) => {
7973
<Link
8074
data-test-id="silence-resource-link"
8175
title={silence.id}
82-
to={getSilenceAlertUrl(perspective, silence.id, namespace)}
76+
to={getSilenceAlertUrl(perspective, silence.id)}
8377
>
8478
{silence.name}
8579
</Link>

web/src/components/alerting/AlertList/AggregateAlertTableRow.tsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import {
2-
Alert,
3-
ResourceIcon,
4-
TableColumn,
5-
useActiveNamespace,
6-
} from '@openshift-console/dynamic-plugin-sdk';
1+
import { Alert, ResourceIcon, TableColumn } from '@openshift-console/dynamic-plugin-sdk';
72
import { ExpandableRowContent, Table, Tbody, Td, Th, Thead, Tr } from '@patternfly/react-table';
83
import type { FC } from 'react';
94
import { useState, useMemo } from 'react';
@@ -33,7 +28,6 @@ const AggregateAlertTableRow: AggregateAlertTableRowProps = ({
3328
const { perspective } = usePerspective();
3429
const title = aggregatedAlert.name;
3530
const isACMPerspective = perspective === 'acm';
36-
const [namespace] = useActiveNamespace();
3731

3832
const filteredAlerts = useMemo(
3933
() => filterAlerts(aggregatedAlert.alerts, selectedFilters),
@@ -99,11 +93,7 @@ const AggregateAlertTableRow: AggregateAlertTableRowProps = ({
9993
</FlexItem>
10094
<FlexItem>
10195
<Link
102-
to={getRuleUrl(
103-
perspective,
104-
firstAlert?.rule,
105-
firstAlert?.labels?.namespace || namespace,
106-
)}
96+
to={getRuleUrl(perspective, firstAlert?.rule)}
10797
data-test-id="alert-resource-link"
10898
data-test={DataTestIDs.AlertingRuleResourceLink}
10999
>

web/src/components/alerting/AlertList/AlertTableRow.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { DropdownItem, Flex, FlexItem } from '@patternfly/react-core';
2121
import KebabDropdown from '../../../components/kebab-dropdown';
2222
import type { FC } from 'react';
2323
import { useTranslation } from 'react-i18next';
24-
import { useNavigate, useParams } from 'react-router-dom-v5-compat';
24+
import { useNavigate } from 'react-router-dom-v5-compat';
2525
import { AlertResource, alertState } from '../../../components/utils';
2626
import {
2727
getAlertUrl,
@@ -35,9 +35,6 @@ const AlertTableRow: FC<{ alert: Alert }> = ({ alert }) => {
3535
const { t } = useTranslation(process.env.I18N_NAMESPACE);
3636
const { perspective } = usePerspective();
3737
const navigate = useNavigate();
38-
const params = useParams<{ ns: string }>();
39-
40-
const namespace = params.ns;
4138

4239
const state = alertState(alert);
4340

@@ -49,7 +46,7 @@ const AlertTableRow: FC<{ alert: Alert }> = ({ alert }) => {
4946
dropdownItems.unshift(
5047
<DropdownItem
5148
key="silence-alert"
52-
onClick={() => navigate(getNewSilenceAlertUrl(perspective, alert, namespace))}
49+
onClick={() => navigate(getNewSilenceAlertUrl(perspective, alert))}
5350
data-test={DataTestIDs.SilenceAlertDropdownItem}
5451
>
5552
{t('Silence alert')}
@@ -86,12 +83,7 @@ const AlertTableRow: FC<{ alert: Alert }> = ({ alert }) => {
8683
</FlexItem>
8784
<FlexItem>
8885
<Link
89-
to={getAlertUrl(
90-
perspective,
91-
alert,
92-
alert?.rule?.id,
93-
alert?.labels?.namespace || namespace,
94-
)}
86+
to={getAlertUrl(perspective, alert, alert?.rule?.id)}
9587
data-test-id="alert-resource-link"
9688
data-test={DataTestIDs.AlertResourceLink}
9789
>

web/src/components/alerting/AlertRulesDetailsPage.tsx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
PrometheusAlert,
77
ResourceIcon,
88
Timestamp,
9-
useActiveNamespace,
109
useResolvedExtensions,
1110
} from '@openshift-console/dynamic-plugin-sdk';
1211
import {
@@ -69,6 +68,7 @@ import { MonitoringProvider } from '../../contexts/MonitoringContext';
6968

7069
import { DataTestIDs } from '../data-test';
7170
import { useAlerts } from '../../hooks/useAlerts';
71+
import { useQueryNamespace } from '../hooks/useQueryNamespace';
7272

7373
// Renders Prometheus template text and highlights any {{ ... }} tags that it contains
7474
const PrometheusTemplate = ({ text }) => (
@@ -83,11 +83,10 @@ const PrometheusTemplate = ({ text }) => (
8383

8484
type ActiveAlertsProps = {
8585
alerts: PrometheusAlert[];
86-
namespace: string;
8786
ruleID: string;
8887
};
8988

90-
export const ActiveAlerts: FC<ActiveAlertsProps> = ({ alerts, namespace, ruleID }) => {
89+
export const ActiveAlerts: FC<ActiveAlertsProps> = ({ alerts, ruleID }) => {
9190
const { t } = useTranslation(process.env.I18N_NAMESPACE);
9291
const { perspective } = usePerspective();
9392
const navigate = useNavigate();
@@ -110,7 +109,7 @@ export const ActiveAlerts: FC<ActiveAlertsProps> = ({ alerts, namespace, ruleID
110109
<Td>
111110
<Link
112111
data-test={DataTestIDs.AlertResourceLink}
113-
to={getAlertUrl(perspective, a, ruleID, namespace)}
112+
to={getAlertUrl(perspective, a, ruleID)}
114113
>
115114
{alertDescription(a)}
116115
</Link>
@@ -148,7 +147,7 @@ const AlertRulesDetailsPage_: FC = () => {
148147
const { rules, rulesAlertLoading } = useAlerts();
149148

150149
const { perspective } = usePerspective();
151-
const [namespace] = useActiveNamespace();
150+
const { namespace } = useQueryNamespace();
152151

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

@@ -187,10 +186,7 @@ const AlertRulesDetailsPage_: FC = () => {
187186
<PageBreadcrumb hasBodyWrapper={false}>
188187
<Breadcrumb>
189188
<BreadcrumbItem>
190-
<Link
191-
to={getAlertRulesUrl(perspective, namespace)}
192-
data-test={DataTestIDs.Breadcrumb}
193-
>
189+
<Link to={getAlertRulesUrl(perspective)} data-test={DataTestIDs.Breadcrumb}>
194190
{t('Alerting rules')}
195191
</Link>
196192
</BreadcrumbItem>
@@ -316,7 +312,6 @@ const AlertRulesDetailsPage_: FC = () => {
316312
to={getQueryBrowserUrl({
317313
perspective: perspective,
318314
query: rule?.query,
319-
namespace: namespace,
320315
})}
321316
>
322317
<CodeBlock>
@@ -372,7 +367,7 @@ const AlertRulesDetailsPage_: FC = () => {
372367
{_.isEmpty(rule?.alerts) ? (
373368
<div>{t('None found')}</div>
374369
) : (
375-
<ActiveAlerts alerts={rule.alerts} ruleID={rule?.id} namespace={namespace} />
370+
<ActiveAlerts alerts={rule.alerts} ruleID={rule?.id} />
376371
)}
377372
</PageSection>
378373
</PageGroup>

0 commit comments

Comments
 (0)