From 6b13064cf6a5f544f558783cda8d3a2b7bc7f7e7 Mon Sep 17 00:00:00 2001 From: ismail simsek Date: Mon, 30 Oct 2023 15:45:20 +0100 Subject: [PATCH] InfluxDB: Fix parsing multiple tags on backend mode (#77340) * Multiple tags separated by comma in the result * A non-flaky unit test --- pkg/tsdb/influxdb/influxql/response_parser.go | 1 + .../influxdb/influxql/response_parser_test.go | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/pkg/tsdb/influxdb/influxql/response_parser.go b/pkg/tsdb/influxdb/influxql/response_parser.go index c8824163823..390008702c7 100644 --- a/pkg/tsdb/influxdb/influxql/response_parser.go +++ b/pkg/tsdb/influxdb/influxql/response_parser.go @@ -258,6 +258,7 @@ func buildFrameNameFromQuery(row models.Row, column string, frameName []byte, re first := true for k, v := range row.Tags { if !first { + frameName = append(frameName, ',') frameName = append(frameName, ' ') } else { first = false diff --git a/pkg/tsdb/influxdb/influxql/response_parser_test.go b/pkg/tsdb/influxdb/influxql/response_parser_test.go index 0b68b619d61..78281e56d76 100644 --- a/pkg/tsdb/influxdb/influxql/response_parser_test.go +++ b/pkg/tsdb/influxdb/influxql/response_parser_test.go @@ -365,6 +365,46 @@ func TestInfluxdbResponseParser(t *testing.T) { assert.Equal(t, "alias logins.count", result.Frames[1].Name) }) + t.Run("Influxdb response parser when multiple measurement in response", func(t *testing.T) { + response := ` + { + "results": [ + { + "series": [ + { + "name": "cpu.upc", + "columns": ["time","mean"], + "tags": { + "datacenter": "America", + "cluster-name": "Cluster" + }, + "values": [ + [111,222] + ] + }, + { + "name": "logins.count", + "columns": ["time","mean"], + "tags": { + "datacenter": "America", + "cluster-name": "Cluster" + }, + "values": [ + [111,222] + ] + } + ] + } + ] + } + ` + + query := models.Query{} + result := ResponseParse(prepare(response), 200, generateQuery(query)) + assert.True(t, strings.Contains(result.Frames[0].Name, ",")) + assert.True(t, strings.Contains(result.Frames[1].Name, ",")) + }) + t.Run("Influxdb response parser with alias", func(t *testing.T) { response := ` {