mirror of
https://github.com/kubernetes-sigs/prometheus-adapter.git
synced 2026-04-07 10:17:51 +00:00
Accept custom label in the metric name
This commit is contained in:
parent
83a7dd5d5e
commit
c040fd431e
1 changed files with 12 additions and 3 deletions
|
|
@ -146,6 +146,12 @@ func (r *basicSeriesRegistry) QueryForMetric(metricInfo provider.MetricInfo, nam
|
||||||
}
|
}
|
||||||
resourceLbl := r.namer.labelPrefix + singularResource
|
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
|
// TODO: support container metrics
|
||||||
if info, found := r.info[metricInfo]; found {
|
if info, found := r.info[metricInfo]; found {
|
||||||
targetValue := resourceNames[0]
|
targetValue := resourceNames[0]
|
||||||
|
|
@ -155,13 +161,12 @@ func (r *basicSeriesRegistry) QueryForMetric(metricInfo provider.MetricInfo, nam
|
||||||
matcher = prom.LabelMatches
|
matcher = prom.LabelMatches
|
||||||
}
|
}
|
||||||
|
|
||||||
var expressions []string
|
|
||||||
if info.isContainer {
|
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"
|
groupBy = "pod_name"
|
||||||
} else {
|
} else {
|
||||||
// TODO: copy base series labels?
|
// TODO: copy base series labels?
|
||||||
expressions = []string{matcher(resourceLbl, targetValue)}
|
expressions = append(expressions, matcher(resourceLbl, targetValue))
|
||||||
groupBy = resourceLbl
|
groupBy = resourceLbl
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -191,6 +196,10 @@ func (r *basicSeriesRegistry) MatchValuesToNames(metricInfo provider.MetricInfo,
|
||||||
}
|
}
|
||||||
resourceLbl := r.namer.labelPrefix + singularResource
|
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 {
|
if info, found := r.info[metricInfo]; found {
|
||||||
res := make(map[string]pmodel.SampleValue, len(values))
|
res := make(map[string]pmodel.SampleValue, len(values))
|
||||||
for _, val := range values {
|
for _, val := range values {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue