@@ -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' ;
3535import {
3636 Button ,
3737 Form ,
@@ -50,7 +50,7 @@ import { useTranslation } from 'react-i18next';
5050
5151import { 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' ;
5454import { LabelNamesResponse } from '@perses-dev/prometheus-plugin' ;
5555import {
5656 t_global_color_status_custom_default ,
@@ -69,6 +69,7 @@ import {
6969 t_global_color_nonstatus_purple_default ,
7070} from '@patternfly/react-tokens' ;
7171import { usePatternFlyTheme } from '../hooks/usePatternflyTheme' ;
72+ import { usePerspective } from '../hooks/usePerspective' ;
7273
7374const 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