From 5326f2d23b7dbd13b522456517845c488a7b93bb Mon Sep 17 00:00:00 2001 From: Nityananda Gohain Date: Mon, 29 Apr 2024 22:40:40 +0530 Subject: [PATCH] fix: dont enrich if non empty keys are not same (#4930) * fix: dont enrich if non empty keys are not same * fix: update if any of the type and dataType is empty but other is matching --- pkg/query-service/app/logs/v3/enrich_query.go | 9 ++-- .../app/logs/v3/enrich_query_test.go | 51 +++++++++++++++++++ 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/pkg/query-service/app/logs/v3/enrich_query.go b/pkg/query-service/app/logs/v3/enrich_query.go index 465919360f..8a7bc85970 100644 --- a/pkg/query-service/app/logs/v3/enrich_query.go +++ b/pkg/query-service/app/logs/v3/enrich_query.go @@ -145,12 +145,13 @@ func enrichFieldWithMetadata(field v3.AttributeKey, fields map[string]v3.Attribu // check if the field is present in the fields map if existingField, ok := fields[field.Key]; ok { - if existingField.IsColumn { + // don't update if type is not the same + if (field.Type == "" && field.DataType == "") || + (field.Type == existingField.Type && field.DataType == existingField.DataType) || + (field.Type == "" && field.DataType == existingField.DataType) || + (field.DataType == "" && field.Type == existingField.Type) { return existingField } - field.Type = existingField.Type - field.DataType = existingField.DataType - return field } // enrich with default values if metadata is not found diff --git a/pkg/query-service/app/logs/v3/enrich_query_test.go b/pkg/query-service/app/logs/v3/enrich_query_test.go index 3605fa5408..32d714925c 100644 --- a/pkg/query-service/app/logs/v3/enrich_query_test.go +++ b/pkg/query-service/app/logs/v3/enrich_query_test.go @@ -342,6 +342,57 @@ var testEnrichParamsData = []struct { }, }, }, + { + Name: "Don't enrich if other keys are non empty and not same", + Params: v3.QueryRangeParamsV3{ + CompositeQuery: &v3.CompositeQuery{ + BuilderQueries: map[string]*v3.BuilderQuery{ + "test": { + QueryName: "test", + Expression: "test", + DataSource: v3.DataSourceLogs, + AggregateAttribute: v3.AttributeKey{ + Key: "test", + Type: v3.AttributeKeyTypeResource, + DataType: v3.AttributeKeyDataTypeInt64, + }, + Filters: &v3.FilterSet{Operator: "AND", Items: []v3.FilterItem{ + {Key: v3.AttributeKey{Key: "test", Type: v3.AttributeKeyTypeTag}, Value: "test", Operator: "="}, + {Key: v3.AttributeKey{Key: "test", DataType: v3.AttributeKeyDataTypeString}, Value: "test1", Operator: "="}, + }}, + }, + }, + }, + }, + Fields: map[string]v3.AttributeKey{ + "test": { + Key: "test", + Type: v3.AttributeKeyTypeTag, + DataType: v3.AttributeKeyDataTypeString, + IsColumn: true, + }, + }, + Result: v3.QueryRangeParamsV3{ + CompositeQuery: &v3.CompositeQuery{ + BuilderQueries: map[string]*v3.BuilderQuery{ + "test": { + QueryName: "test", + Expression: "test", + DataSource: v3.DataSourceLogs, + AggregateAttribute: v3.AttributeKey{ + Key: "test", + Type: v3.AttributeKeyTypeResource, + DataType: v3.AttributeKeyDataTypeInt64, + }, + Filters: &v3.FilterSet{Operator: "AND", Items: []v3.FilterItem{ + {Key: v3.AttributeKey{Key: "test", Type: v3.AttributeKeyTypeTag, DataType: v3.AttributeKeyDataTypeString, IsColumn: true}, Value: "test", Operator: "="}, + {Key: v3.AttributeKey{Key: "test", Type: v3.AttributeKeyTypeTag, DataType: v3.AttributeKeyDataTypeString, IsColumn: true}, Value: "test1", Operator: "="}, + }}, + }, + }, + }, + }, + }, } func TestEnrichParams(t *testing.T) {