Accept custom label in the metric name

This commit is contained in:
bgpat 2018-04-19 10:04:59 +09:00
parent 83a7dd5d5e
commit c040fd431e

View file

@ -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 {