Prometheus: Fix "-Instant" string showing up in prometheus instant query UI (#62265)

Add string constant and make sure to remove from name before outputting to frontend
pull/62267/head
Galen Kistler 2 years ago committed by GitHub
parent c006df375a
commit 5ad7cca9d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      public/app/features/explore/PrometheusListView/ItemLabels.tsx
  2. 4
      public/app/plugins/datasource/prometheus/datasource.tsx

@ -4,6 +4,8 @@ import React from 'react';
import { Field, GrafanaTheme2 } from '@grafana/data/';
import { useStyles2 } from '@grafana/ui/';
import { InstantQueryRefIdIndex } from '../../../plugins/datasource/prometheus/datasource';
import { rawListItemColumnWidth } from './RawListItem';
const getItemLabelsStyles = (theme: GrafanaTheme2, expanded: boolean) => {
@ -22,14 +24,22 @@ const getItemLabelsStyles = (theme: GrafanaTheme2, expanded: boolean) => {
};
};
const formatValueName = (name: string): string => {
if (name.includes(InstantQueryRefIdIndex)) {
return name.replace(InstantQueryRefIdIndex, '');
}
return name;
};
export const ItemLabels = ({ valueLabels, expanded }: { valueLabels: Field[]; expanded: boolean }) => {
const styles = useStyles2((theme) => getItemLabelsStyles(theme, expanded));
return (
<div className={styles.itemLabelsWrap}>
<div className={styles.valueNavigationWrapper}>
{valueLabels.map((value, index) => (
<span className={styles.valueNavigation} key={value.name}>
{value.name}
{formatValueName(value.name)}
</span>
))}
</div>

@ -70,6 +70,8 @@ import { PrometheusVariableSupport } from './variables';
const ANNOTATION_QUERY_STEP_DEFAULT = '60s';
const GET_AND_POST_METADATA_ENDPOINTS = ['api/v1/query', 'api/v1/query_range', 'api/v1/series', 'api/v1/labels'];
export const InstantQueryRefIdIndex = '-Instant';
export class PrometheusDatasource
extends DataSourceWithBackend<PromQuery, PromOptions>
implements DataSourceWithQueryImportSupport<PromQuery>, DataSourceWithQueryExportSupport<PromQuery>
@ -430,7 +432,7 @@ export class PrometheusDatasource
},
{
...processedTarget,
refId: processedTarget.refId + '-Instant',
refId: processedTarget.refId + InstantQueryRefIdIndex,
range: false,
}
);

Loading…
Cancel
Save