Skip to content

Commit ce623f0

Browse files
fix: allow tenancy access to metrics tags
1 parent 345d64d commit ce623f0

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

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,
@@ -50,7 +50,7 @@ import { useTranslation } from 'react-i18next';
5050

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

53-
import { PROMETHEUS_BASE_PATH } from '../console/graphs/helpers';
53+
import { PROMETHEUS_BASE_PATH, PROMETHEUS_TENANCY_BASE_PATH } from '../console/graphs/helpers';
5454
import { LabelNamesResponse } from '@perses-dev/prometheus-plugin';
5555
import {
5656
t_global_color_status_custom_default,
@@ -69,6 +69,7 @@ import {
6969
t_global_color_nonstatus_purple_default,
7070
} from '@patternfly/react-tokens';
7171
import { usePatternFlyTheme } from '../hooks/usePatternflyTheme';
72+
import { usePerspective } from '../hooks/usePerspective';
7273

7374
const box_shadow = `
7475
var(--pf-t--global--box-shadow--X--md--default)
@@ -332,16 +333,21 @@ export const PromQLExpressionInput: React.FC<PromQLExpressionInputProps> = ({
332333
const viewRef = React.useRef<EditorView | null>(null);
333334
const [metricNames, setMetricNames] = React.useState<Array<string>>([]);
334335
const [errorMessage, setErrorMessage] = React.useState<string | undefined>();
336+
const { perspective } = usePerspective();
337+
const [namespace] = useActiveNamespace();
335338

336339
const placeholder = t('Expression (press Shift+Enter for newlines)');
337340

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

341344
React.useEffect(() => {
342-
safeFetch<LabelNamesResponse>(
343-
`${PROMETHEUS_BASE_PATH}/${PrometheusEndpoint.LABEL}/__name__/values`,
344-
)
345+
let url = `${PROMETHEUS_BASE_PATH}/${PrometheusEndpoint.LABEL}/__name__/values`;
346+
if (perspective === 'dev') {
347+
// eslint-disable-next-line max-len
348+
url = `${PROMETHEUS_TENANCY_BASE_PATH}/${PrometheusEndpoint.LABEL}/__name__/values?namespace=${namespace}`;
349+
}
350+
safeFetch<LabelNamesResponse>(url)
345351
.then((response) => {
346352
const metrics = response?.data;
347353
setMetricNames(metrics);
@@ -355,7 +361,7 @@ export const PromQLExpressionInput: React.FC<PromQLExpressionInputProps> = ({
355361
setErrorMessage(message);
356362
}
357363
});
358-
}, [safeFetch, t]);
364+
}, [safeFetch, t, namespace, perspective]);
359365

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

0 commit comments

Comments
 (0)