Skip to content

Commit 51e303c

Browse files
committed
feat: re enable dev console views
Signed-off-by: Gabriel Bernal <[email protected]>
1 parent 4b2ccc0 commit 51e303c

9 files changed

Lines changed: 104 additions & 110 deletions

File tree

web/console-extensions.json

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@
355355
"exact": false,
356356
"path": "/dev-monitoring/ns/:ns/alerts/:ruleID",
357357
"component": {
358-
"$codeRef": "DevRedirects.AlertRedirect"
358+
"$codeRef": "AlertsDetailsPage.MpCmoAlertsDetailsPage"
359359
}
360360
}
361361
},
@@ -365,7 +365,7 @@
365365
"exact": false,
366366
"path": "/dev-monitoring/ns/:ns/rules/:id",
367367
"component": {
368-
"$codeRef": "DevRedirects.RulesRedirect"
368+
"$codeRef": "AlertRulesDetailsPage.MpCmoAlertRulesDetailsPage"
369369
}
370370
}
371371
},
@@ -375,7 +375,7 @@
375375
"exact": false,
376376
"path": "/dev-monitoring/ns/:ns/silences/:id",
377377
"component": {
378-
"$codeRef": "DevRedirects.SilenceRedirect"
378+
"$codeRef": "SilencesDetailsPage.MpCmoSilencesDetailsPage"
379379
}
380380
}
381381
},
@@ -385,7 +385,7 @@
385385
"exact": false,
386386
"path": "/dev-monitoring/ns/:ns/silences/:id/edit",
387387
"component": {
388-
"$codeRef": "DevRedirects.SilenceEditRedirect"
388+
"$codeRef": "SilenceEditPage.MpCmoSilenceEditPage"
389389
}
390390
}
391391
},
@@ -395,18 +395,52 @@
395395
"exact": false,
396396
"path": "/dev-monitoring/ns/:ns/silences/~new",
397397
"component": {
398-
"$codeRef": "DevRedirects.SilenceNewRedirect"
398+
"$codeRef": "SilenceCreatePage.MpCmoCreateSilencePage"
399399
}
400400
}
401401
},
402402
{
403-
"type": "console.page/route",
403+
"type": "console.tab",
404404
"properties": {
405-
"exact": false,
406-
"path": "/dev-monitoring/ns/:ns/metrics",
405+
"contextId": "dev-console-observe",
406+
"name": "%plugin__monitoring-plugin~Silences%",
407+
"href": "silences",
408+
"component": {
409+
"$codeRef": "SilencesPage.MpCmoSilencesPage"
410+
}
411+
}
412+
},
413+
{
414+
"type": "console.tab",
415+
"properties": {
416+
"contextId": "dev-console-observe",
417+
"name": "%plugin__monitoring-plugin~Metrics%",
418+
"href": "metrics",
419+
"component": {
420+
"$codeRef": "MetricsPage.MpCmoDevMetricsPage"
421+
}
422+
}
423+
},
424+
{
425+
"type": "console.tab",
426+
"properties": {
427+
"contextId": "dev-console-observe",
428+
"name": "%plugin__monitoring-plugin~Alerts%",
429+
"href": "alerts",
430+
"component": {
431+
"$codeRef": "AlertsPage.MpCmoAlertsPage"
432+
}
433+
}
434+
},
435+
{
436+
"type": "console.tab",
437+
"properties": {
438+
"contextId": "dev-console-observe",
439+
"name": "%plugin__monitoring-plugin~Alerting Rules%",
440+
"href": "rules",
407441
"component": {
408-
"$codeRef": "DevRedirects.MetricsRedirect"
442+
"$codeRef": "AlertRulesPage.MpCmoAlertRulesPage"
409443
}
410444
}
411445
}
412-
]
446+
]

web/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@
182182
"IncidentsPage": "./components/Incidents/IncidentsPage",
183183
"TargetsPage": "./components/targets-page",
184184
"PrometheusRedirectPage": "./components/redirects/prometheus-redirect-page",
185-
"DevRedirects": "./components/redirects/dev-redirects",
186185
"MonitoringContext": "./contexts/MonitoringContext"
187186
},
188187
"dependencies": {

web/src/components/MetricsPage.tsx

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,6 +1324,7 @@ const MetricsPage_: FC = () => {
13241324
const { t } = useTranslation(process.env.I18N_NAMESPACE);
13251325
const [units, setUnits] = useQueryParam(QueryParams.Units, StringParam);
13261326
const { setNamespace } = useQueryNamespace();
1327+
const { displayNamespaceSelector } = useMonitoring();
13271328

13281329
const dispatch = useDispatch();
13291330

@@ -1402,14 +1403,18 @@ const MetricsPage_: FC = () => {
14021403

14031404
return (
14041405
<>
1405-
<DocumentTitle>{t('Metrics')}</DocumentTitle>
1406-
<NamespaceBar
1407-
onNamespaceChange={(namespace) => {
1408-
dispatch(queryBrowserDeleteAllQueries());
1409-
setNamespace(namespace);
1410-
}}
1411-
/>
1412-
<ListPageHeader title={t('Metrics')}>
1406+
{displayNamespaceSelector && (
1407+
<>
1408+
<DocumentTitle>{t('Metrics')}</DocumentTitle>
1409+
<NamespaceBar
1410+
onNamespaceChange={(namespace) => {
1411+
dispatch(queryBrowserDeleteAllQueries());
1412+
setNamespace(namespace);
1413+
}}
1414+
/>
1415+
</>
1416+
)}
1417+
<ListPageHeader title={displayNamespaceSelector ? t('Metrics') : ' '}>
14131418
<Split hasGutter>
14141419
<SplitItem data-test={DataTestIDs.MetricGraphUnitsDropDown}>
14151420
<Tooltip content={<>{t('This dropdown only formats results.')}</>}>
@@ -1470,6 +1475,20 @@ export const MpCmoMetricsPage: React.FC = () => {
14701475
);
14711476
};
14721477

1478+
export const MpCmoDevMetricsPage: React.FC = () => {
1479+
return (
1480+
<MonitoringProvider
1481+
monitoringContext={{
1482+
plugin: 'monitoring-plugin',
1483+
prometheus: 'cmo',
1484+
displayNamespaceSelector: false,
1485+
}}
1486+
>
1487+
<MetricsPage />
1488+
</MonitoringProvider>
1489+
);
1490+
};
1491+
14731492
type QueryTableProps = {
14741493
index: number;
14751494
namespace?: string;

web/src/components/alerting/AlertingPage.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ const namespacedPages = [
5858
const AlertingPage: FC = () => {
5959
const { t } = useTranslation(process.env.I18N_NAMESPACE);
6060
const dispatch = useDispatch();
61-
const { useAlertsTenancy, accessCheckLoading } = useMonitoring();
62-
6361
const [perspective] = useActivePerspective();
6462
const { setNamespace } = useQueryNamespace();
6563

@@ -97,7 +95,7 @@ const AlertingPage: FC = () => {
9795

9896
return (
9997
<>
100-
{namespacedPages.includes(pathname) && !accessCheckLoading && useAlertsTenancy && (
98+
{namespacedPages.includes(pathname) && (
10199
<NamespaceBar
102100
onNamespaceChange={(namespace) => {
103101
dispatch(alertingClearSelectorData(prometheus, namespace));

web/src/components/alerting/AlertsPage.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,20 @@ const AlertsPage_: FC = () => {
110110
rowFilters = rowFilters.filter((filter) => filter.type !== 'alert-source');
111111
}
112112

113-
const [staticData, filteredData, onFilterChange] = useListPageFilter(alerts, rowFilters);
113+
/**
114+
* Filters alerts based on tenancy:
115+
* - with tenancy: alerts are automatically pre-filtered.
116+
* - without tenancy (admin): filters by selected namespace for UX consistency.
117+
* - "All Projects": returns all alerts, including those without a namespace label.
118+
*/
119+
const namespacedAlerts =
120+
useAlertsTenancy || ALL_NAMESPACES_KEY === namespace
121+
? alerts
122+
: alerts.filter((a) => a.labels.namespace === namespace);
123+
const [staticData, filteredData, onFilterChange] = useListPageFilter(
124+
namespacedAlerts,
125+
rowFilters,
126+
);
114127

115128
const columns = useAggregateAlertColumns();
116129
const selectedFilters = useSelectedFilters();

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ export const PromQLExpressionInput: FC<PromQLExpressionInputProps> = ({
358358
.then((response) => {
359359
const metrics = response?.data;
360360
setMetricNames(metrics);
361+
setErrorMessage(undefined);
361362
})
362363
.catch((err) => {
363364
if (err.name !== 'AbortError') {

web/src/components/redirects/dev-redirects.tsx

Lines changed: 0 additions & 85 deletions
This file was deleted.

web/src/contexts/MonitoringContext.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ type MonitoringContextType = {
1919
useMetricsTenancy: boolean;
2020
/** Dictates if the users access is being loaded. */
2121
accessCheckLoading: boolean;
22+
/**
23+
* Dictates if the namespace selector is shown inside the view,
24+
* in some perspectives the selector already exist outside monitoring components scope
25+
*/
26+
displayNamespaceSelector: boolean;
2227
};
2328

2429
export const MonitoringContext = React.createContext<MonitoringContextType>({
@@ -27,12 +32,14 @@ export const MonitoringContext = React.createContext<MonitoringContextType>({
2732
useAlertsTenancy: false,
2833
useMetricsTenancy: false,
2934
accessCheckLoading: true,
35+
displayNamespaceSelector: true,
3036
});
3137

3238
export const MonitoringProvider: React.FC<{
3339
monitoringContext: {
3440
plugin: MonitoringPlugins;
3541
prometheus: Prometheus;
42+
displayNamespaceSelector?: boolean;
3643
};
3744
}> = ({ children, monitoringContext }) => {
3845
const [allNamespaceAlertsTenancy, alertAccessCheckLoading] = useAccessReview({
@@ -56,6 +63,7 @@ export const MonitoringProvider: React.FC<{
5663
useAlertsTenancy: monitoringContext.prometheus === 'cmo' && !allNamespaceAlertsTenancy,
5764
useMetricsTenancy: monitoringContext.prometheus === 'cmo' && !allNamespaceMeticsTenancy,
5865
accessCheckLoading: alertAccessCheckLoading || metricsAccessCheckLoading,
66+
displayNamespaceSelector: monitoringContext.displayNamespaceSelector ?? true,
5967
};
6068
}, [
6169
monitoringContext,

web/src/hooks/useMonitoring.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@ import { useContext } from 'react';
22
import { MonitoringContext } from '../contexts/MonitoringContext';
33

44
export const useMonitoring = () => {
5-
const { prometheus, plugin, useAlertsTenancy, useMetricsTenancy, accessCheckLoading } =
6-
useContext(MonitoringContext);
5+
const {
6+
prometheus,
7+
plugin,
8+
useAlertsTenancy,
9+
useMetricsTenancy,
10+
accessCheckLoading,
11+
displayNamespaceSelector,
12+
} = useContext(MonitoringContext);
713
return {
814
prometheus,
915
plugin,
1016
useAlertsTenancy,
1117
useMetricsTenancy,
1218
accessCheckLoading,
19+
displayNamespaceSelector,
1320
};
1421
};

0 commit comments

Comments
 (0)