From c2a9d48dd6243bfea01badf570f5ec8b97b3e520 Mon Sep 17 00:00:00 2001 From: Kristina Date: Wed, 31 May 2023 08:46:33 -0500 Subject: [PATCH] Correlations: Show labels fields that have links (#69120) * Show labels fields that have links * Fix test * Do not safestringify strings and numbers --- public/app/features/logs/components/logParser.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/public/app/features/logs/components/logParser.ts b/public/app/features/logs/components/logParser.ts index 5950bb14c2e..25f8c8a72a0 100644 --- a/public/app/features/logs/components/logParser.ts +++ b/public/app/features/logs/components/logParser.ts @@ -1,6 +1,7 @@ import memoizeOne from 'memoize-one'; import { DataFrame, Field, FieldType, LinkModel, LogRowModel } from '@grafana/data'; +import { safeStringifyValue } from 'app/core/utils/explore'; import { ExploreFieldLinkModel } from 'app/features/explore/utils/links'; export type FieldDef = { @@ -69,9 +70,14 @@ export const getDataframeFields = memoizeOne( .filter((field, index) => !shouldRemoveField(field, index, row)) .map((field) => { const links = getFieldLinks ? getFieldLinks(field, row.rowIndex, row.dataFrame) : []; + const fieldVal = field.values[row.rowIndex]; + const outputVal = + typeof fieldVal === 'string' || typeof fieldVal === 'number' + ? fieldVal.toString() + : safeStringifyValue(fieldVal); return { keys: [field.name], - values: [field.values[row.rowIndex].toString()], + values: [outputVal], links: links, fieldIndex: field.index, }; @@ -82,7 +88,7 @@ export const getDataframeFields = memoizeOne( function shouldRemoveField(field: Field, index: number, row: LogRowModel) { // Remove field if it is: // "labels" field that is in Loki used to store all labels - if (field.name === 'labels' && field.type === FieldType.other) { + if (field.name === 'labels' && field.type === FieldType.other && (field.config.links?.length || 0) === 0) { return true; } // id and tsNs are arbitrary added fields in the backend and should be hidden in the UI