Skip to content

Commit c6a042a

Browse files
Merge pull request #617 from PeterYurkovich/OCPBUGS-63440
[release-4.20] OCPBUGS-63440: fetch metric labels with tenancy
2 parents 736cb48 + 91876c5 commit c6a042a

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

web/src/components/console/graphs/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from '@openshift-console/dynamic-plugin-sdk/lib/extensions/console-types';
88

99
export const PROMETHEUS_BASE_PATH = window.SERVER_FLAGS.prometheusBaseURL;
10-
const PROMETHEUS_TENANCY_BASE_PATH = window.SERVER_FLAGS.prometheusTenancyBaseURL;
10+
export const PROMETHEUS_TENANCY_BASE_PATH = window.SERVER_FLAGS.prometheusTenancyBaseURL;
1111
const PROMETHEUS_PROXY_PATH = '/api/proxy/plugin/monitoring-console-plugin/thanos-proxy';
1212

1313
export const ALERTMANAGER_BASE_PATH = window.SERVER_FLAGS.alertManagerBaseURL;

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
ViewPlugin,
3232
ViewUpdate,
3333
} from '@codemirror/view';
34-
import { PrometheusEndpoint } from '@openshift-console/dynamic-plugin-sdk';
34+
import { PrometheusEndpoint, useActiveNamespace } from '@openshift-console/dynamic-plugin-sdk';
3535
import {
3636
Button,
3737
Form,
@@ -51,7 +51,7 @@ import { useTranslation } from 'react-i18next';
5151

5252
import { useSafeFetch } from '../console/utils/safe-fetch-hook';
5353

54-
import { PROMETHEUS_BASE_PATH } from '../console/graphs/helpers';
54+
import { PROMETHEUS_BASE_PATH, PROMETHEUS_TENANCY_BASE_PATH } from '../console/graphs/helpers';
5555
import { LabelNamesResponse } from '@perses-dev/prometheus-plugin';
5656
import {
5757
t_global_color_status_custom_default,
@@ -70,6 +70,7 @@ import {
7070
t_global_color_nonstatus_purple_default,
7171
} from '@patternfly/react-tokens';
7272
import { usePatternFlyTheme } from '../hooks/usePatternflyTheme';
73+
import { usePerspective } from '../hooks/usePerspective';
7374

7475
const box_shadow = `
7576
var(--pf-t--global--box-shadow--X--md--default)
@@ -334,15 +335,20 @@ export const PromQLExpressionInput: FC<PromQLExpressionInputProps> = ({
334335
const [metricNames, setMetricNames] = useState<Array<string>>([]);
335336
const [errorMessage, setErrorMessage] = useState<string | undefined>();
336337

338+
const { perspective } = usePerspective();
337339
const placeholder = t('Expression (press Shift+Enter for newlines)');
340+
const [namespace] = useActiveNamespace();
338341

339342
// eslint-disable-next-line react-hooks/exhaustive-deps
340343
const safeFetch = useCallback(useSafeFetch(), []);
341344

342345
useEffect(() => {
343-
safeFetch<LabelNamesResponse>(
344-
`${PROMETHEUS_BASE_PATH}/${PrometheusEndpoint.LABEL}/__name__/values`,
345-
)
346+
let url = `${PROMETHEUS_BASE_PATH}/${PrometheusEndpoint.LABEL}/__name__/values`;
347+
if (perspective === 'dev') {
348+
// eslint-disable-next-line max-len
349+
url = `${PROMETHEUS_TENANCY_BASE_PATH}/${PrometheusEndpoint.LABEL}/__name__/values?namespace=${namespace}`;
350+
}
351+
safeFetch<LabelNamesResponse>(url)
346352
.then((response) => {
347353
const metrics = response?.data;
348354
setMetricNames(metrics);
@@ -356,7 +362,7 @@ export const PromQLExpressionInput: FC<PromQLExpressionInputProps> = ({
356362
setErrorMessage(message);
357363
}
358364
});
359-
}, [safeFetch, t]);
365+
}, [safeFetch, t, namespace, perspective]);
360366

361367
const onClear = () => {
362368
if (viewRef.current !== null) {

0 commit comments

Comments
 (0)