From dccca0729f9bfae7b4de2bd6dd0055fcb4998f8f Mon Sep 17 00:00:00 2001 From: Matias Chomicki Date: Tue, 21 Jan 2025 19:02:07 +0000 Subject: [PATCH] Logs Volume: Do not throw when fields are missing (#99318) * Logs Volume: Do not throw when fields are missing * Add removed line back * Prevent permanent mutations * Decrease nesting * Move conditional up * Update public/app/features/logs/utils.ts Co-authored-by: Galen Kistler <109082771+gtk-grafana@users.noreply.github.com> * Use dataframe length and remove from function * Use getFieldDisplayName * Keep original dependency array * Keep original dependency array --------- Co-authored-by: Galen Kistler <109082771+gtk-grafana@users.noreply.github.com> --- public/app/features/explore/Logs/Logs.tsx | 2 +- public/app/features/logs/utils.ts | 28 ++++++++++++++--------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/public/app/features/explore/Logs/Logs.tsx b/public/app/features/explore/Logs/Logs.tsx index 57a69022712..2ed3584119d 100644 --- a/public/app/features/explore/Logs/Logs.tsx +++ b/public/app/features/explore/Logs/Logs.tsx @@ -266,7 +266,7 @@ const UnthemedLogs: React.FunctionComponent = (props: Props) => { // check if we have dataFrames that return the same level const logLevelsArray: Array<{ levelStr: string; logLevel: LogLevel }> = []; logVolumeDataFrames.forEach((dataFrame) => { - const { level } = getLogLevelInfo(dataFrame); + const { level } = getLogLevelInfo(dataFrame, logsVolumeData?.data ?? []); logLevelsArray.push({ levelStr: level, logLevel: getLogLevel(level) }); }); diff --git a/public/app/features/logs/utils.ts b/public/app/features/logs/utils.ts index a96a1d2c6b7..c4a19c0aa6c 100644 --- a/public/app/features/logs/utils.ts +++ b/public/app/features/logs/utils.ts @@ -14,6 +14,7 @@ import { QueryResultMeta, LogsVolumeType, NumericLogLevel, + getFieldDisplayName, } from '@grafana/data'; import { getDataframeFields } from './components/logParser'; @@ -216,22 +217,28 @@ export const mergeLogsVolumeDataFrames = (dataFrames: DataFrame[]): { dataFrames // collect and aggregate into aggregated object dataFrames.forEach((dataFrame) => { - const { level, valueField, timeField, length } = getLogLevelInfo(dataFrame); + const { level, valueField, timeField } = getLogLevelInfo(dataFrame, dataFrames); + + if (!timeField || !valueField) { + return; + } configs[level] = { meta: dataFrame.meta, - valueFieldConfig: valueField.config, - timeFieldConfig: timeField.config, + valueFieldConfig: valueField?.config ?? {}, + timeFieldConfig: timeField?.config ?? {}, }; - for (let pointIndex = 0; pointIndex < length; pointIndex++) { + for (let pointIndex = 0; pointIndex < dataFrame.length; pointIndex++) { const time: number = timeField.values[pointIndex]; const value: number = valueField.values[pointIndex]; aggregated[level] ??= {}; aggregated[level][time] = (aggregated[level][time] || 0) + value; totals[time] = (totals[time] || 0) + value; - maximumValue = Math.max(totals[time], maximumValue); + if (totals[time] > maximumValue) { + maximumValue = totals[time]; + } } }); @@ -296,21 +303,20 @@ export const copyText = async (text: string, buttonRef: React.MutableRefObject