Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions web/src/components/metrics/promql-expression-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -327,6 +328,8 @@ export const PromQLExpressionInput: FC<PromQLExpressionInputProps> = ({
onSelectionChange,
}) => {
const { t } = useTranslation(process.env.I18N_NAMESPACE);
const [namespace] = useActiveNamespace();
const { prometheus } = useMonitoring();
const { theme: pfTheme } = usePatternFlyTheme();

const containerRef = useRef<HTMLDivElement | null>(null);
Expand All @@ -340,9 +343,13 @@ export const PromQLExpressionInput: FC<PromQLExpressionInputProps> = ({
const safeFetch = useCallback(useSafeFetch(), []);

useEffect(() => {
safeFetch<LabelNamesResponse>(
`${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<LabelNamesResponse>(url)
.then((response) => {
const metrics = response?.data;
setMetricNames(metrics);
Expand All @@ -356,7 +363,7 @@ export const PromQLExpressionInput: FC<PromQLExpressionInputProps> = ({
setErrorMessage(message);
}
});
}, [safeFetch, t]);
}, [safeFetch, t, namespace, prometheus]);

const onClear = () => {
if (viewRef.current !== null) {
Expand Down