From 6bba8c23e93e09bf338c50f43b1d13ebe6f89af2 Mon Sep 17 00:00:00 2001 From: guoguangwu Date: Fri, 10 Nov 2023 13:48:52 +0800 Subject: [PATCH] chore: slice loop replace --- pkg/prometheus-adapter/expression.go | 8 ++------ pkg/utils/expression_prom_default.go | 4 +--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/pkg/prometheus-adapter/expression.go b/pkg/prometheus-adapter/expression.go index e53355311..b54f6cdac 100644 --- a/pkg/prometheus-adapter/expression.go +++ b/pkg/prometheus-adapter/expression.go @@ -124,9 +124,7 @@ func ParsingExternalRules(mc config.MetricsDiscoveryConfig, mapper meta.RESTMapp // SetExtensionLabels from opts.DataSourcePromConfig.AdapterExtensionLabels func SetExtensionLabels(extensionLabels string) { if extensionLabels != "" { - for _, label := range strings.Split(extensionLabels, ",") { - metricRules.ExtensionLabels = append(metricRules.ExtensionLabels, label) - } + metricRules.ExtensionLabels = append(metricRules.ExtensionLabels, strings.Split(extensionLabels, ",")...) } } @@ -370,9 +368,7 @@ func GetLabelMatchersFromDiscoveryRule(rule config.DiscoveryRule) []string { if len(regLabelMatchers.FindStringSubmatch(rule.SeriesQuery)) > 1 { SeriesMatchers := regLabelMatchers.FindStringSubmatch(rule.SeriesQuery)[1] if SeriesMatchers != "" { - for _, seriesMatcher := range strings.Split(SeriesMatchers, ",") { - labelMatchers = append(labelMatchers, seriesMatcher) - } + labelMatchers = append(labelMatchers, strings.Split(SeriesMatchers, ",")...) } } diff --git a/pkg/utils/expression_prom_default.go b/pkg/utils/expression_prom_default.go index c97faf863..dd8da48a2 100644 --- a/pkg/utils/expression_prom_default.go +++ b/pkg/utils/expression_prom_default.go @@ -58,9 +58,7 @@ var extensionLabelsString string func SetExtensionLabels(extensionLabels string) { if extensionLabels != "" { - for _, label := range strings.Split(extensionLabels, ",") { - ExtensionLabelArray = append(ExtensionLabelArray, label) - } + ExtensionLabelArray = append(ExtensionLabelArray, strings.Split(extensionLabels, ",")...) extensionLabelsString = "," for index, label := range ExtensionLabelArray {