mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-28 01:31:17 +00:00
Update PromQL queries for pod_name label change
Around Kubernetes 1.16 the label name for `pod` changed to `pod_name` so we need to change the PromQL queries used when optional links are enabled.
This commit is contained in:
@@ -47,7 +47,7 @@ var (
|
||||
|
||||
// Queries on pod names of the format `name-<id>-<hash>`
|
||||
// See also: https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#pod-template-hash-label
|
||||
podIDHashQueries = formatMetricQueries(`pod_name=~"^{{label}}-[^-]+-[^-]+$",namespace="{{namespace}}"`, []string{docker.MemoryUsage, docker.CPUTotalUsage})
|
||||
podIDHashQueries = formatMetricQueries(`pod=~"^{{label}}-[^-]+-[^-]+$",namespace="{{namespace}}"`, []string{docker.MemoryUsage, docker.CPUTotalUsage})
|
||||
|
||||
// Prometheus queries for topologies
|
||||
topologyQueries = map[string]map[string]string{
|
||||
@@ -59,16 +59,16 @@ var (
|
||||
// Kubernetes topologies
|
||||
|
||||
report.Pod: formatMetricQueries(
|
||||
`pod_name="{{label}}",namespace="{{namespace}}"`,
|
||||
`pod="{{label}}",namespace="{{namespace}}"`,
|
||||
[]string{docker.MemoryUsage, docker.CPUTotalUsage},
|
||||
),
|
||||
report.DaemonSet: formatMetricQueries(`pod_name=~"^{{label}}-[^-]+$",namespace="{{namespace}}"`, []string{docker.MemoryUsage, docker.CPUTotalUsage}),
|
||||
report.DaemonSet: formatMetricQueries(`pod=~"^{{label}}-[^-]+$",namespace="{{namespace}}"`, []string{docker.MemoryUsage, docker.CPUTotalUsage}),
|
||||
report.Deployment: podIDHashQueries,
|
||||
report.StatefulSet: podIDHashQueries,
|
||||
report.CronJob: podIDHashQueries,
|
||||
report.Service: {
|
||||
docker.CPUTotalUsage: `sum(rate(container_cpu_usage_seconds_total{image!="",namespace="{{namespace}}",_weave_pod_name="{{label}}",job="cadvisor",container_name!="POD"}[5m]))`,
|
||||
docker.MemoryUsage: `sum(rate(container_memory_usage_bytes{image!="",namespace="{{namespace}}",_weave_pod_name="{{label}}",job="cadvisor",container_name!="POD"}[5m]))`,
|
||||
docker.CPUTotalUsage: `sum(rate(container_cpu_usage_seconds_total{image!="",namespace="{{namespace}}",_weave_service="{{label}}"}[5m]))`,
|
||||
docker.MemoryUsage: `sum(rate(container_memory_usage_bytes{image!="",namespace="{{namespace}}",_weave_service="{{label}}"}[5m]))`,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
@@ -61,9 +61,9 @@ func TestRenderMetricURLs_Pod(t *testing.T) {
|
||||
result := detailed.RenderMetricURLs(s, samplePodNode, report.MakeReport(), sampleMetricsGraphURL)
|
||||
|
||||
checkURL(t, result.Metrics[0].URL, sampleMetricsGraphURL,
|
||||
[]string{"container_memory_usage_bytes", `pod_name=\"foo\"`, `namespace=\"noospace\"`})
|
||||
[]string{"container_memory_usage_bytes", `pod=\"foo\"`, `namespace=\"noospace\"`})
|
||||
checkURL(t, result.Metrics[1].URL, sampleMetricsGraphURL,
|
||||
[]string{"container_cpu_usage_seconds", `pod_name=\"foo\"`, `namespace=\"noospace\"`})
|
||||
[]string{"container_cpu_usage_seconds", `pod=\"foo\"`, `namespace=\"noospace\"`})
|
||||
}
|
||||
|
||||
func TestRenderMetricURLs_Container(t *testing.T) {
|
||||
@@ -109,9 +109,9 @@ func TestRenderMetricURLs_QueryReplacement(t *testing.T) {
|
||||
result := detailed.RenderMetricURLs(s, samplePodNode, report.MakeReport(), "http://example.test/?q=:query")
|
||||
|
||||
checkURL(t, result.Metrics[0].URL, "http://example.test/?q=",
|
||||
[]string{"container_memory_usage_bytes", `pod_name="foo"`, `namespace="noospace"`})
|
||||
[]string{"container_memory_usage_bytes", `pod="foo"`, `namespace="noospace"`})
|
||||
checkURL(t, result.Metrics[1].URL, "http://example.test/?q=",
|
||||
[]string{"container_cpu_usage_seconds", `pod_name="foo"`, `namespace="noospace"`})
|
||||
[]string{"container_cpu_usage_seconds", `pod="foo"`, `namespace="noospace"`})
|
||||
}
|
||||
|
||||
func checkURL(t *testing.T, u string, prefix string, contains []string) {
|
||||
|
||||
Reference in New Issue
Block a user