diff --git a/web/src/components/metrics/promql-expression-input.tsx b/web/src/components/metrics/promql-expression-input.tsx index 543abf7d..65974962 100644 --- a/web/src/components/metrics/promql-expression-input.tsx +++ b/web/src/components/metrics/promql-expression-input.tsx @@ -31,7 +31,7 @@ import { ViewPlugin, ViewUpdate, } from '@codemirror/view'; -import { PrometheusEndpoint } from '@openshift-console/dynamic-plugin-sdk'; +import { PrometheusEndpoint, useActiveNamespace } from '@openshift-console/dynamic-plugin-sdk'; import { Button, Form, @@ -51,7 +51,7 @@ import { useTranslation } from 'react-i18next'; import { useSafeFetch } from '../console/utils/safe-fetch-hook'; -import { PROMETHEUS_BASE_PATH } from '../utils'; +import { ALL_NAMESPACES_KEY, getPrometheusBasePath, PROMETHEUS_BASE_PATH } from '../utils'; import { LabelNamesResponse } from '@perses-dev/prometheus-plugin'; import { t_global_color_status_custom_default, @@ -70,6 +70,7 @@ import { t_global_color_nonstatus_purple_default, } from '@patternfly/react-tokens'; import { usePatternFlyTheme } from '../hooks/usePatternflyTheme'; +import { useMonitoring } from '../../hooks/useMonitoring'; const box_shadow = ` var(--pf-t--global--box-shadow--X--md--default) @@ -327,6 +328,8 @@ export const PromQLExpressionInput: FC = ({ onSelectionChange, }) => { const { t } = useTranslation(process.env.I18N_NAMESPACE); + const [namespace] = useActiveNamespace(); + const { prometheus } = useMonitoring(); const { theme: pfTheme } = usePatternFlyTheme(); const containerRef = useRef(null); @@ -340,9 +343,13 @@ export const PromQLExpressionInput: FC = ({ const safeFetch = useCallback(useSafeFetch(), []); useEffect(() => { - safeFetch( - `${PROMETHEUS_BASE_PATH}/${PrometheusEndpoint.LABEL}/__name__/values`, - ) + // If we are using the tenancy path, then add the namespace as a query parameter at the end of + // the url + const namespaceQueryParam = namespace !== ALL_NAMESPACES_KEY ? `?namespace=${namespace}` : ''; + const url = `${getPrometheusBasePath({ namespace, prometheus })}/${ + PrometheusEndpoint.LABEL + }/__name__/values${namespaceQueryParam}`; + safeFetch(url) .then((response) => { const metrics = response?.data; setMetricNames(metrics); @@ -356,7 +363,7 @@ export const PromQLExpressionInput: FC = ({ setErrorMessage(message); } }); - }, [safeFetch, t]); + }, [safeFetch, t, namespace, prometheus]); const onClear = () => { if (viewRef.current !== null) {