From d85f03ec26661ccde94d5d745b44a9fef68b5a86 Mon Sep 17 00:00:00 2001 From: Matias Chomicki Date: Tue, 21 Nov 2023 14:37:05 +0100 Subject: [PATCH] Loki: Fix conditional for derived fields using regex type (#78464) Derived fields: fix conditional for regex fields --- public/app/plugins/datasource/loki/getDerivedFields.test.ts | 6 ++++++ public/app/plugins/datasource/loki/getDerivedFields.ts | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/public/app/plugins/datasource/loki/getDerivedFields.test.ts b/public/app/plugins/datasource/loki/getDerivedFields.test.ts index ba8a513d6bc..880db4a88ac 100644 --- a/public/app/plugins/datasource/loki/getDerivedFields.test.ts +++ b/public/app/plugins/datasource/loki/getDerivedFields.test.ts @@ -26,17 +26,20 @@ describe('getDerivedFields', () => { const newFields = getDerivedFields(df, [ { matcherRegex: 'trace1=(\\w+)', + matcherType: 'regex', name: 'trace1', url: 'http://localhost/${__value.raw}', }, { matcherRegex: 'trace2=(\\w+)', + matcherType: 'regex', name: 'trace2', url: 'test', datasourceUid: 'uid', }, { matcherRegex: 'trace2=(\\w+)', + matcherType: 'regex', name: 'trace2', url: 'test', datasourceUid: 'uid2', @@ -44,6 +47,7 @@ describe('getDerivedFields', () => { }, { matcherRegex: 'trace=(\\w+)', + matcherType: 'regex', name: 'tempoTraceId', url: 'test', datasourceUid: 'tempo-datasource-uid', @@ -51,6 +55,7 @@ describe('getDerivedFields', () => { }, { matcherRegex: 'trace=(\\w+)', + matcherType: 'regex', name: 'xrayTraceId', url: 'test', datasourceUid: 'xray-datasource-uid', @@ -115,6 +120,7 @@ describe('getDerivedFields', () => { const newFields = getDerivedFields(df, [ { matcherRegex: 'trace1=(\\w+)', + matcherType: 'regex', name: 'trace1', url: 'http://localhost/${__value.raw}', }, diff --git a/public/app/plugins/datasource/loki/getDerivedFields.ts b/public/app/plugins/datasource/loki/getDerivedFields.ts index 7f094dd624c..24b3b9f1c46 100644 --- a/public/app/plugins/datasource/loki/getDerivedFields.ts +++ b/public/app/plugins/datasource/loki/getDerivedFields.ts @@ -41,7 +41,7 @@ export function getDerivedFields(dataFrame: DataFrame, derivedFieldConfigs: Deri } } field.values.push(null); - } else if (derivedFieldsGrouped[field.name][0].matcherType !== 'regex') { + } else if (derivedFieldsGrouped[field.name][0].matcherType === 'regex') { // `matcherRegex` will actually be used as a RegExp here const line = lineField.values[i]; const logMatch = line.match(derivedFieldsGrouped[field.name][0].matcherRegex);