From c040fd431e60d6aeda84f604fa98092cdd1814a6 Mon Sep 17 00:00:00 2001 From: bgpat Date: Thu, 19 Apr 2018 10:04:59 +0900 Subject: [PATCH] Accept custom label in the metric name --- pkg/custom-provider/metric_namer.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pkg/custom-provider/metric_namer.go b/pkg/custom-provider/metric_namer.go index 90d7cdd5..cda8673e 100644 --- a/pkg/custom-provider/metric_namer.go +++ b/pkg/custom-provider/metric_namer.go @@ -146,6 +146,12 @@ func (r *basicSeriesRegistry) QueryForMetric(metricInfo provider.MetricInfo, nam } resourceLbl := r.namer.labelPrefix + singularResource + var expressions []string + if i := strings.Index(metricInfo.Metric, "{"); i > 1 && metricInfo.Metric[len(metricInfo.Metric)-1] == '}' { + expressions = append(expressions, metricInfo.Metric[i+1:len(metricInfo.Metric)-1]) + metricInfo.Metric = metricInfo.Metric[:i] + } + // TODO: support container metrics if info, found := r.info[metricInfo]; found { targetValue := resourceNames[0] @@ -155,13 +161,12 @@ func (r *basicSeriesRegistry) QueryForMetric(metricInfo provider.MetricInfo, nam matcher = prom.LabelMatches } - var expressions []string if info.isContainer { - expressions = []string{matcher("pod_name", targetValue), prom.LabelNeq("container_name", "POD")} + expressions = append(expressions, matcher("pod_name", targetValue), prom.LabelNeq("container_name", "POD")) groupBy = "pod_name" } else { // TODO: copy base series labels? - expressions = []string{matcher(resourceLbl, targetValue)} + expressions = append(expressions, matcher(resourceLbl, targetValue)) groupBy = resourceLbl } @@ -191,6 +196,10 @@ func (r *basicSeriesRegistry) MatchValuesToNames(metricInfo provider.MetricInfo, } resourceLbl := r.namer.labelPrefix + singularResource + if i := strings.Index(metricInfo.Metric, "{"); i > 1 { + metricInfo.Metric = metricInfo.Metric[:i] + } + if info, found := r.info[metricInfo]; found { res := make(map[string]pmodel.SampleValue, len(values)) for _, val := range values {