From 16c25102bcffe5fbf5b37001b94619a09b833e52 Mon Sep 17 00:00:00 2001 From: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com> Date: Wed, 10 Feb 2021 14:01:59 +0100 Subject: [PATCH] LogsPanel: Add deduplication option for logs (#31019) * WIP: Add dedup functionality to logs panel * Simplify, clean up * Change ordering of customizations based on how it is in Explore * Update public/app/plugins/panel/logs/LogsPanel.tsx Co-authored-by: Giordano Ricci * Update public/app/plugins/panel/logs/LogsPanel.tsx Co-authored-by: Giordano Ricci Co-authored-by: Giordano Ricci --- public/app/plugins/panel/logs/LogsPanel.tsx | 14 ++++++----- public/app/plugins/panel/logs/module.tsx | 28 ++++++++++++++++++++- public/app/plugins/panel/logs/types.ts | 3 ++- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/public/app/plugins/panel/logs/LogsPanel.tsx b/public/app/plugins/panel/logs/LogsPanel.tsx index a2a12786748..0476ba1933e 100644 --- a/public/app/plugins/panel/logs/LogsPanel.tsx +++ b/public/app/plugins/panel/logs/LogsPanel.tsx @@ -1,16 +1,15 @@ import React from 'react'; import { LogRows, CustomScrollbar } from '@grafana/ui'; -import { LogsDedupStrategy, PanelProps } from '@grafana/data'; +import { PanelProps } from '@grafana/data'; import { Options } from './types'; -import { dataFrameToLogsModel } from 'app/core/logs_model'; +import { dataFrameToLogsModel, dedupLogRows } from 'app/core/logs_model'; interface LogsPanelProps extends PanelProps {} export const LogsPanel: React.FunctionComponent = ({ data, timeZone, - options: { showLabels, showTime, wrapLogMessage, sortOrder }, - width, + options: { showLabels, showTime, wrapLogMessage, sortOrder, dedupStrategy }, }) => { if (!data) { return ( @@ -21,12 +20,15 @@ export const LogsPanel: React.FunctionComponent = ({ } const newResults = data ? dataFrameToLogsModel(data.series, data.request?.intervalMs, timeZone) : null; + const logRows = newResults?.rows || []; + const deduplicatedRows = dedupLogRows(logRows, dedupStrategy); return ( (LogsPanel).setPanelOptions((build description: '', defaultValue: false, }) + .addRadio({ + path: 'dedupStrategy', + name: 'Deduplication', + description: '', + settings: { + options: [ + { value: LogsDedupStrategy.none, label: 'None', description: LogsDedupDescription[LogsDedupStrategy.none] }, + { + value: LogsDedupStrategy.exact, + label: 'Exact', + description: LogsDedupDescription[LogsDedupStrategy.exact], + }, + { + value: LogsDedupStrategy.numbers, + label: 'Numbers', + description: LogsDedupDescription[LogsDedupStrategy.numbers], + }, + { + value: LogsDedupStrategy.signature, + label: 'Signature', + description: LogsDedupDescription[LogsDedupStrategy.signature], + }, + ], + }, + defaultValue: LogsDedupStrategy.none, + }) .addRadio({ path: 'sortOrder', name: 'Order', diff --git a/public/app/plugins/panel/logs/types.ts b/public/app/plugins/panel/logs/types.ts index abb76a3fe30..c910730a51c 100644 --- a/public/app/plugins/panel/logs/types.ts +++ b/public/app/plugins/panel/logs/types.ts @@ -1,8 +1,9 @@ -import { LogsSortOrder } from '@grafana/data'; +import { LogsSortOrder, LogsDedupStrategy } from '@grafana/data'; export interface Options { showLabels: boolean; showTime: boolean; wrapLogMessage: boolean; sortOrder: LogsSortOrder; + dedupStrategy: LogsDedupStrategy; }