From 3c1de8750c724a34e5839b348b9b524df6960c47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Farkas?= Date: Tue, 4 Oct 2022 11:25:22 +0200 Subject: [PATCH] GrafanaData: Deprecate the LogsParser type (#56242) * added copy of code to main-grafana * grafana-data: add depreceted-notice --- packages/grafana-data/src/types/logs.ts | 1 + public/app/features/logs/utils.ts | 29 ++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/packages/grafana-data/src/types/logs.ts b/packages/grafana-data/src/types/logs.ts index 553be92b9e0..b6b2531ea2e 100644 --- a/packages/grafana-data/src/types/logs.ts +++ b/packages/grafana-data/src/types/logs.ts @@ -110,6 +110,7 @@ export enum LogsDedupStrategy { signature = 'signature', } +/** @deprecated will be removed in the next major version */ export interface LogsParser { /** * Value-agnostic matcher for a field label. diff --git a/public/app/features/logs/utils.ts b/public/app/features/logs/utils.ts index 29439ed26be..63cdacd1279 100644 --- a/public/app/features/logs/utils.ts +++ b/public/app/features/logs/utils.ts @@ -7,7 +7,6 @@ import { LogLevel, LogRowModel, LogLabelStatsModel, - LogsParser, LogsModel, LogsSortOrder, } from '@grafana/data'; @@ -76,6 +75,34 @@ export function addLogLevelToSeries(series: DataFrame, lineIndex: number): DataF }; } +interface LogsParser { + /** + * Value-agnostic matcher for a field label. + * Used to filter rows, and first capture group contains the value. + */ + buildMatcher: (label: string) => RegExp; + + /** + * Returns all parsable substrings from a line, used for highlighting + */ + getFields: (line: string) => string[]; + + /** + * Gets the label name from a parsable substring of a line + */ + getLabelFromField: (field: string) => string; + + /** + * Gets the label value from a parsable substring of a line + */ + getValueFromField: (field: string) => string; + /** + * Function to verify if this is a valid parser for the given line. + * The parser accepts the line if it returns true. + */ + test: (line: string) => boolean; +} + export const LogsParsers: { [name: string]: LogsParser } = { JSON: { buildMatcher: (label) => new RegExp(`(?:{|,)\\s*"${label}"\\s*:\\s*"?([\\d\\.]+|[^"]*)"?`),