From 35ef6b92651b4132b5b497fb740b691c3c08c66d Mon Sep 17 00:00:00 2001 From: Ulric Qin Date: Fri, 8 Jul 2022 12:02:57 +0800 Subject: [PATCH] duplicate label key checker --- src/server/common/label_append.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/server/common/label_append.go b/src/server/common/label_append.go index d1574315..bdce9fd7 100644 --- a/src/server/common/label_append.go +++ b/src/server/common/label_append.go @@ -12,13 +12,27 @@ func AppendLabels(pt *prompb.TimeSeries, target *models.Target) { return } + labelKeys := make(map[string]struct{}) + for j := 0; j < len(pt.Labels); j++ { + labelKeys[pt.Labels[j].Name] = struct{}{} + } + for key, value := range target.TagsMap { + if _, has := labelKeys[key]; has { + continue + } + pt.Labels = append(pt.Labels, &prompb.Label{ Name: key, Value: value, }) } + // e.g. busigroup=cloud + if _, has := labelKeys[config.C.BusiGroupLabelKey]; has { + return + } + if target.GroupId > 0 && len(config.C.BusiGroupLabelKey) > 0 { bg := memsto.BusiGroupCache.GetByBusiGroupId(target.GroupId) if bg == nil {