From 5096806eab893d7250ff4a481bfb76e74a7197de Mon Sep 17 00:00:00 2001 From: ismail simsek Date: Thu, 16 Nov 2023 09:39:15 +0100 Subject: [PATCH] InfluxDB: Don't sort retention policies on the backend (#78252) don't sort retention policies --- pkg/tsdb/influxdb/influxql/response_parser.go | 38 ++----------------- .../influxdb/influxql/response_parser_test.go | 2 +- 2 files changed, 4 insertions(+), 36 deletions(-) diff --git a/pkg/tsdb/influxdb/influxql/response_parser.go b/pkg/tsdb/influxdb/influxql/response_parser.go index bfd2a0e79a9..d4116b147d8 100644 --- a/pkg/tsdb/influxdb/influxql/response_parser.go +++ b/pkg/tsdb/influxdb/influxql/response_parser.go @@ -83,9 +83,6 @@ func transformRows(rows []models.Row, query models.Query) data.Frames { // It's sized for a reasonably-large name, but will grow if needed. frameName := make([]byte, 0, 128) - retentionPolicyQuery := isRetentionPolicyQuery(query) - tagValuesQuery := isTagValuesQuery(query) - for _, row := range rows { var hasTimeCol = false @@ -96,7 +93,7 @@ func transformRows(rows []models.Row, query models.Query) data.Frames { } if !hasTimeCol { - newFrame := newFrameWithoutTimeField(row, retentionPolicyQuery, tagValuesQuery) + newFrame := newFrameWithoutTimeField(row, query) frames = append(frames, newFrame) } else { for colIndex, column := range row.Columns { @@ -170,35 +167,14 @@ func newFrameWithTimeField(row models.Row, column string, colIndex int, query mo return newDataFrame(name, query.RawQuery, timeField, valueField, getVisType(query.ResultFormat)) } -func newFrameWithoutTimeField(row models.Row, retentionPolicyQuery bool, tagValuesQuery bool) *data.Frame { +func newFrameWithoutTimeField(row models.Row, query models.Query) *data.Frame { var values []string - if retentionPolicyQuery { - values = make([]string, 1, len(row.Values)) - } else { - values = make([]string, 0, len(row.Values)) - } - for _, valuePair := range row.Values { - if tagValuesQuery { + if strings.Contains(strings.ToLower(query.RawQuery), strings.ToLower("SHOW TAG VALUES")) { if len(valuePair) >= 2 { values = append(values, valuePair[1].(string)) } - } else if retentionPolicyQuery { - // We want to know whether the given retention policy is the default one or not. - // If it is default policy then we should add it to the beginning. - // The index 4 gives us if that policy is default or not. - // https://docs.influxdata.com/influxdb/v1.8/query_language/explore-schema/#show-retention-policies - // Only difference is v0.9. In that version we don't receive shardGroupDuration value. - // https://archive.docs.influxdata.com/influxdb/v0.9/query_language/schema_exploration/#show-retention-policies - // Since it is always the last value we will check that last value always. - if len(valuePair) >= 1 { - if valuePair[len(row.Columns)-1].(bool) { - values[0] = valuePair[0].(string) - } else { - values = append(values, valuePair[0].(string)) - } - } } else { if len(valuePair) >= 1 { values = append(values, valuePair[0].(string)) @@ -349,11 +325,3 @@ func getVisType(resFormat string) data.VisType { return graphVisType } } - -func isTagValuesQuery(query models.Query) bool { - return strings.Contains(strings.ToLower(query.RawQuery), strings.ToLower("SHOW TAG VALUES")) -} - -func isRetentionPolicyQuery(query models.Query) bool { - return strings.Contains(strings.ToLower(query.RawQuery), strings.ToLower("SHOW RETENTION POLICIES")) -} diff --git a/pkg/tsdb/influxdb/influxql/response_parser_test.go b/pkg/tsdb/influxdb/influxql/response_parser_test.go index 012b3a040c0..a71071bcf26 100644 --- a/pkg/tsdb/influxdb/influxql/response_parser_test.go +++ b/pkg/tsdb/influxdb/influxql/response_parser_test.go @@ -798,7 +798,7 @@ func TestResponseParser_Parse_RetentionPolicy(t *testing.T) { query := models.Query{RefID: "metricFindQuery", RawQuery: "SHOW RETENTION POLICIES"} policyFrame := data.NewFrame("", data.NewField("Value", nil, []string{ - "bar", "autogen", "5m_avg", "1m_avg", + "autogen", "bar", "5m_avg", "1m_avg", }), )