mirror of
https://github.com/kubernetes-sigs/prometheus-adapter.git
synced 2026-04-07 10:17:51 +00:00
Merge 7a5a0595c4 into 83a7dd5d5e
This commit is contained in:
commit
9ac9a6ba7d
2 changed files with 39 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 {
|
||||||
|
|
|
||||||
|
|
@ -116,6 +116,18 @@ func TestMetricNamerContainerSeries(t *testing.T) {
|
||||||
isContainer: true,
|
isContainer: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
input: prom.Series{
|
||||||
|
Name: "container_some_time_seconds_total{status=\"success\"}",
|
||||||
|
Labels: pmodel.LabelSet{"status": "success", "pod_name": "somepod", "namespace": "somens", "container_name": "somecont"},
|
||||||
|
},
|
||||||
|
outputMetricName: "some_time",
|
||||||
|
outputInfo: seriesInfo{
|
||||||
|
baseSeries: prom.Series{Name: "container_some_time_seconds_total"},
|
||||||
|
kind: SecondsCounterSeries,
|
||||||
|
isContainer: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
@ -207,6 +219,10 @@ func TestSeriesRegistry(t *testing.T) {
|
||||||
Name: "admin_reddit_seconds_total",
|
Name: "admin_reddit_seconds_total",
|
||||||
Labels: pmodel.LabelSet{"kube_admin": "some-admin"},
|
Labels: pmodel.LabelSet{"kube_admin": "some-admin"},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "service_proxy_packets{protocol=\"tcp\"}",
|
||||||
|
Labels: pmodel.LabelSet{"protocol": "tcp", "kube_service": "somesvc", "kube_namespace": "somens"},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// set up the registry
|
// set up the registry
|
||||||
|
|
@ -335,6 +351,15 @@ func TestSeriesRegistry(t *testing.T) {
|
||||||
expectedKind: SecondsCounterSeries,
|
expectedKind: SecondsCounterSeries,
|
||||||
expectedQuery: "node_fan_seconds_total{kube_node=\"somenode\"}",
|
expectedQuery: "node_fan_seconds_total{kube_node=\"somenode\"}",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: "namespaced metrics gauge",
|
||||||
|
info: provider.MetricInfo{schema.GroupResource{Resource: "service"}, true, "service_proxy_packets"},
|
||||||
|
namespace: "somens",
|
||||||
|
resourceNames: []string{"somesvc"},
|
||||||
|
|
||||||
|
expectedKind: GaugeSeries,
|
||||||
|
expectedQuery: "service_proxy_packets{kube_service=\"somesvc\",kube_namespace=\"somens\"}",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
|
|
@ -370,6 +395,8 @@ func TestSeriesRegistry(t *testing.T) {
|
||||||
{schema.GroupResource{Resource: "nodes"}, false, "node_gigawatts"},
|
{schema.GroupResource{Resource: "nodes"}, false, "node_gigawatts"},
|
||||||
{schema.GroupResource{Resource: "persistentvolumes"}, false, "volume_claims"},
|
{schema.GroupResource{Resource: "persistentvolumes"}, false, "volume_claims"},
|
||||||
{schema.GroupResource{Resource: "nodes"}, false, "node_fan"},
|
{schema.GroupResource{Resource: "nodes"}, false, "node_fan"},
|
||||||
|
{schema.GroupResource{Resource: "services"}, true, "service_proxy_packets{protocol=\"tcp\"}"},
|
||||||
|
{schema.GroupResource{Resource: "namespaces"}, false, "service_proxy_packets{protocol=\"tcp\"}"},
|
||||||
}
|
}
|
||||||
|
|
||||||
// sort both for easy comparison
|
// sort both for easy comparison
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue