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)
This commit is contained in:
Galen Kistler 2023-06-08 09:32:09 -05:00 committed by GitHub
parent a02bf1104c
commit 093d0a4c35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 7 deletions

View File

@ -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);

View File

@ -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!');