From 150778df1a638c45f7e63f80af04bf3b48695988 Mon Sep 17 00:00:00 2001 From: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com> Date: Tue, 4 Aug 2020 14:37:07 +0200 Subject: [PATCH] Explore/Loki: Remove regex parsing errors for huge logs (#26405) * Remove hihglihting for logs with more than 5000 characters * Update limitt, include also parsing for details * Update --- packages/grafana-ui/src/components/Logs/LogDetails.tsx | 4 ++++ .../grafana-ui/src/components/Logs/LogRowMessage.tsx | 5 ++++- public/app/features/explore/Logs.tsx | 9 +++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/grafana-ui/src/components/Logs/LogDetails.tsx b/packages/grafana-ui/src/components/Logs/LogDetails.tsx index cb53084b3e2..9d77a159a5d 100644 --- a/packages/grafana-ui/src/components/Logs/LogDetails.tsx +++ b/packages/grafana-ui/src/components/Logs/LogDetails.tsx @@ -20,6 +20,7 @@ import { selectThemeVariant } from '../../themes/selectThemeVariant'; //Components import { LogDetailsRow } from './LogDetailsRow'; +import { MAX_CHARACTERS } from './LogRowMessage'; type FieldDef = { key: string; @@ -64,6 +65,9 @@ class UnThemedLogDetails extends PureComponent { getParser = memoizeOne(getParser); parseMessage = memoizeOne((rowEntry): FieldDef[] => { + if (rowEntry.length > MAX_CHARACTERS) { + return []; + } const parser = this.getParser(rowEntry); if (!parser) { return []; diff --git a/packages/grafana-ui/src/components/Logs/LogRowMessage.tsx b/packages/grafana-ui/src/components/Logs/LogRowMessage.tsx index dafc8505964..b37280525b1 100644 --- a/packages/grafana-ui/src/components/Logs/LogRowMessage.tsx +++ b/packages/grafana-ui/src/components/Logs/LogRowMessage.tsx @@ -17,6 +17,8 @@ import { stylesFactory } from '../../themes/stylesFactory'; import { LogRowContext } from './LogRowContext'; import { LogMessageAnsi } from './LogMessageAnsi'; +export const MAX_CHARACTERS = 100000; + interface Props extends Themeable { row: LogRowModel; hasMoreContextRows?: HasMoreContextRows; @@ -86,7 +88,8 @@ class UnThemedLogRowMessage extends PureComponent { const previewHighlights = highlighterExpressions && !_.isEqual(highlighterExpressions, row.searchWords); const highlights = previewHighlights ? highlighterExpressions : row.searchWords; - const needsHighlighter = highlights && highlights.length > 0 && highlights[0] && highlights[0].length > 0; + const needsHighlighter = + highlights && highlights.length > 0 && highlights[0] && highlights[0].length > 0 && entry.length < MAX_CHARACTERS; const highlightClassName = previewHighlights ? cx([style.logsRowMatchHighLight, style.logsRowMatchHighLightPreview]) : cx([style.logsRowMatchHighLight]); diff --git a/public/app/features/explore/Logs.tsx b/public/app/features/explore/Logs.tsx index 7d4b907ab92..a82fe031e18 100644 --- a/public/app/features/explore/Logs.tsx +++ b/public/app/features/explore/Logs.tsx @@ -22,6 +22,7 @@ import store from 'app/core/store'; import { ExploreGraphPanel } from './ExploreGraphPanel'; import { MetaInfoText } from './MetaInfoText'; import { RowContextOptions } from '@grafana/ui/src/components/Logs/LogRowContextProvider'; +import { MAX_CHARACTERS } from '@grafana/ui/src/components/Logs/LogRowMessage'; const SETTINGS_KEYS = { showLabels: 'grafana.explore.logs.showLabels', @@ -181,6 +182,14 @@ export class Logs extends PureComponent { }); } + if (logRows.some(r => r.entry.length > MAX_CHARACTERS)) { + meta.push({ + label: 'Info', + value: 'Logs with more than 100,000 characters could not be parsed and highlighted', + kind: LogsMetaKind.String, + }); + } + const scanText = scanRange ? `Scanning ${rangeUtil.describeTimeRange(scanRange)}` : 'Scanning...'; const series = logsSeries ? logsSeries : [];