From 093d0a4c35f9cbd913a36bd71d64384094dd54bd Mon Sep 17 00:00:00 2001 From: Galen Kistler <109082771+gtk-grafana@users.noreply.github.com> Date: Thu, 8 Jun 2023 09:32:09 -0500 Subject: [PATCH] Prometheus: Fix numeric values in raw prometheus view which are being formatted as text (#69737) * output numeric if exists * fix bug where copying to clipboard was excluding quantile label (le) --- .../explore/PrometheusListView/RawListItem.tsx | 4 ++-- .../getRawPrometheusListItemsFromDataFrame.ts | 16 +++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/public/app/features/explore/PrometheusListView/RawListItem.tsx b/public/app/features/explore/PrometheusListView/RawListItem.tsx index 42d3337423b..44d4f791f31 100644 --- a/public/app/features/explore/PrometheusListView/RawListItem.tsx +++ b/public/app/features/explore/PrometheusListView/RawListItem.tsx @@ -108,7 +108,7 @@ const RawListItem = ({ listItemData, listKey, totalNumberOfValues, valueLabels, * Transform the symbols in the dataFrame to uniform strings */ const transformCopyValue = (value: string): string => { - if (value === '∞') { + if (value === '∞' || value === 'Infinity') { return '+Inf'; } return value; @@ -117,7 +117,7 @@ const RawListItem = ({ listItemData, listKey, totalNumberOfValues, valueLabels, // Convert the object back into a string const stringRep = `${__name__}{${attributeValues.map((value) => { // For histograms the string representation currently in this object is not directly queryable in all situations, leading to broken copied queries. Omitting the attribute from the copied result gives a query which returns all le values, which I assume to be a more common use case. - return value.key !== 'le' ? `${value.key}="${transformCopyValue(value.value)}"` : ''; + return `${value.key}="${transformCopyValue(value.value)}"`; })}}`; const hideFieldsWithoutValues = Boolean(valueLabels && valueLabels?.length); diff --git a/public/app/features/explore/utils/getRawPrometheusListItemsFromDataFrame.ts b/public/app/features/explore/utils/getRawPrometheusListItemsFromDataFrame.ts index 8d70d0c2c79..79a015182f7 100644 --- a/public/app/features/explore/utils/getRawPrometheusListItemsFromDataFrame.ts +++ b/public/app/features/explore/utils/getRawPrometheusListItemsFromDataFrame.ts @@ -38,11 +38,17 @@ export const getRawPrometheusListItemsFromDataFrame = (dataFrame: DataFrame): in if (label !== 'Time') { // Initialize the objects if (typeof field?.display === 'function') { - const stringValue = formattedValueToString(field?.display(field.values[i])); - if (stringValue) { - formattedMetric[label] = stringValue; - } else if (label.includes('Value #')) { - formattedMetric[label] = RawPrometheusListItemEmptyValue; + const value = field?.display(field.values[i]); + if (!isNaN(value.numeric)) { + formattedMetric[label] = value.numeric.toString(10); + } else { + const stringValue = formattedValueToString(value); + + if (stringValue) { + formattedMetric[label] = stringValue; + } else if (label.includes('Value #')) { + formattedMetric[label] = RawPrometheusListItemEmptyValue; + } } } else { console.warn('Field display method is missing!');