From ead401b51127d4bb29979404b532db19a178caad Mon Sep 17 00:00:00 2001 From: Muhammad Shahzeb Date: Fri, 23 Aug 2024 03:19:53 +0500 Subject: [PATCH 1/5] Adds root cgroup filter to filter out root cgroup stats --- docker-mixin/config.libsonnet | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-mixin/config.libsonnet b/docker-mixin/config.libsonnet index 8801524ae..12b43dbfd 100644 --- a/docker-mixin/config.libsonnet +++ b/docker-mixin/config.libsonnet @@ -9,7 +9,7 @@ //prefix uid: 'integration-docker', // ignore k8s nodes by default - filteringSelector: 'job!="kubelet"', + filteringSelector: 'job!="kubelet", name!=""', //signals related From af4878f045e6283cbd566fb1b818be3858f098a5 Mon Sep 17 00:00:00 2001 From: Muhammad Shahzeb Date: Mon, 26 Aug 2024 12:47:43 +0500 Subject: [PATCH 2/5] Fix machine level selectors --- docker-mixin/config.libsonnet | 4 ++-- docker-mixin/signals/machine.libsonnet | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docker-mixin/config.libsonnet b/docker-mixin/config.libsonnet index 12b43dbfd..1451c6576 100644 --- a/docker-mixin/config.libsonnet +++ b/docker-mixin/config.libsonnet @@ -9,8 +9,8 @@ //prefix uid: 'integration-docker', // ignore k8s nodes by default - filteringSelector: 'job!="kubelet", name!=""', - + filteringSelector: 'job!="kubelet", id=~"/system.slice/docker.+", name!=""', + machineSelector: 'job!="kubelet"', //signals related groupLabels: ['job'], diff --git a/docker-mixin/signals/machine.libsonnet b/docker-mixin/signals/machine.libsonnet index 8adaf2862..da48c1b0f 100644 --- a/docker-mixin/signals/machine.libsonnet +++ b/docker-mixin/signals/machine.libsonnet @@ -46,7 +46,7 @@ function(this) ) / avg( - machine_memory_bytes{%(queriesSelector)s} + machine_memory_bytes{%(machineSelector)s} ) * 100 |||, }, @@ -63,7 +63,7 @@ function(this) avg( sum by (instance) (container_memory_usage_bytes{%(queriesSelector)s}) / - avg by (instance) (machine_memory_bytes{%(queriesSelector)s}) + avg by (instance) (machine_memory_bytes{%(machineSelector)s}) ) * 100 |||, }, From 048ba1209ee4fd65a5a2ba58799c78c91c856d21 Mon Sep 17 00:00:00 2001 From: Muhammad Shahzeb Date: Mon, 26 Aug 2024 20:08:43 +0500 Subject: [PATCH 3/5] Add container selector on top of queries selector --- docker-mixin/config.libsonnet | 4 ++-- docker-mixin/signals/container.libsonnet | 2 +- docker-mixin/signals/machine.libsonnet | 18 +++++++++--------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/docker-mixin/config.libsonnet b/docker-mixin/config.libsonnet index 1451c6576..a3d358a1b 100644 --- a/docker-mixin/config.libsonnet +++ b/docker-mixin/config.libsonnet @@ -9,8 +9,8 @@ //prefix uid: 'integration-docker', // ignore k8s nodes by default - filteringSelector: 'job!="kubelet", id=~"/system.slice/docker.+", name!=""', - machineSelector: 'job!="kubelet"', + filteringSelector: 'job!="kubelet"', + containerSelector: 'id=~"/system.slice/docker.+", name!=""', //signals related groupLabels: ['job'], diff --git a/docker-mixin/signals/container.libsonnet b/docker-mixin/signals/container.libsonnet index ffab55307..195d31a6c 100644 --- a/docker-mixin/signals/container.libsonnet +++ b/docker-mixin/signals/container.libsonnet @@ -2,7 +2,7 @@ local commonlib = import './common-lib/common/main.libsonnet'; function(this) { local s = self, - filteringSelector: this.filteringSelector, + filteringSelector: this.filteringSelector + ', ' + this.containerSelector, groupLabels: this.groupLabels, instanceLabels: this.instanceLabels + s.legendLabels, legendLabels: ['name'], diff --git a/docker-mixin/signals/machine.libsonnet b/docker-mixin/signals/machine.libsonnet index da48c1b0f..bc499b8f8 100644 --- a/docker-mixin/signals/machine.libsonnet +++ b/docker-mixin/signals/machine.libsonnet @@ -18,7 +18,7 @@ function(this) type: 'raw', sources: { cadvisor: { - expr: 'count(container_last_seen{%(queriesSelector)s})', + expr: 'count(container_last_seen{%%(queriesSelector)s, %(containerSelector)s})' % {containerSelector: this.containerSelector}, }, }, }, @@ -28,7 +28,7 @@ function(this) type: 'raw', sources: { cadvisor: { - expr: 'count (sum by (image) (container_last_seen{%(queriesSelector)s}))', + expr: 'count (sum by (image) (container_last_seen{%%(queriesSelector)s, %(containerSelector)s}))' % {containerSelector: this.containerSelector}, }, }, }, @@ -42,13 +42,13 @@ function(this) cadvisor: { expr: ||| sum( - container_spec_memory_reservation_limit_bytes{%(queriesSelector)s} + container_spec_memory_reservation_limit_bytes{%%(queriesSelector)s, %(containerSelector)s} ) / avg( - machine_memory_bytes{%(machineSelector)s} + machine_memory_bytes{%%(queriesSelector)s} ) * 100 - |||, + ||| % {containerSelector: this.containerSelector}, }, }, }, @@ -61,11 +61,11 @@ function(this) cadvisor: { expr: ||| avg( - sum by (instance) (container_memory_usage_bytes{%(queriesSelector)s}) + sum by (instance) (container_memory_usage_bytes{%%(queriesSelector)s, %(containerSelector)s}) / - avg by (instance) (machine_memory_bytes{%(machineSelector)s}) + avg by (instance) (machine_memory_bytes{%%(queriesSelector)s}) ) * 100 - |||, + ||| % {containerSelector: this.containerSelector}, }, }, }, @@ -76,7 +76,7 @@ function(this) unit: 'percent', sources: { cadvisor: { - expr: 'avg by (%(agg)s, name) (rate(container_cpu_usage_seconds_total{%(queriesSelector)s}[$__rate_interval])) * 100', + expr: 'avg by (%%(agg)s, name) (rate(container_cpu_usage_seconds_total{%%(queriesSelector)s, %(containerSelector)s}[$__rate_interval])) * 100' % {containerSelector: this.containerSelector}, legendCustomTemplate: commonlib.utils.labelsToPanelLegend(this.instanceLabels), }, }, From 0c94eceea2be0cb5b5cc25d55a31dac962b1cab3 Mon Sep 17 00:00:00 2001 From: Muhammad Shahzeb Date: Mon, 26 Aug 2024 20:10:06 +0500 Subject: [PATCH 4/5] Remove un-needed newline --- docker-mixin/config.libsonnet | 1 - 1 file changed, 1 deletion(-) diff --git a/docker-mixin/config.libsonnet b/docker-mixin/config.libsonnet index a3d358a1b..137dd381a 100644 --- a/docker-mixin/config.libsonnet +++ b/docker-mixin/config.libsonnet @@ -11,7 +11,6 @@ // ignore k8s nodes by default filteringSelector: 'job!="kubelet"', containerSelector: 'id=~"/system.slice/docker.+", name!=""', - //signals related groupLabels: ['job'], // host level From 1b2fe3d74d21939610e3fdac5812cf422d401f34 Mon Sep 17 00:00:00 2001 From: Muhammad Shahzeb Date: Mon, 26 Aug 2024 20:36:31 +0500 Subject: [PATCH 5/5] Fix fmt --- docker-mixin/signals/machine.libsonnet | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docker-mixin/signals/machine.libsonnet b/docker-mixin/signals/machine.libsonnet index bc499b8f8..a84aa565a 100644 --- a/docker-mixin/signals/machine.libsonnet +++ b/docker-mixin/signals/machine.libsonnet @@ -18,7 +18,7 @@ function(this) type: 'raw', sources: { cadvisor: { - expr: 'count(container_last_seen{%%(queriesSelector)s, %(containerSelector)s})' % {containerSelector: this.containerSelector}, + expr: 'count(container_last_seen{%%(queriesSelector)s, %(containerSelector)s})' % { containerSelector: this.containerSelector }, }, }, }, @@ -28,7 +28,7 @@ function(this) type: 'raw', sources: { cadvisor: { - expr: 'count (sum by (image) (container_last_seen{%%(queriesSelector)s, %(containerSelector)s}))' % {containerSelector: this.containerSelector}, + expr: 'count (sum by (image) (container_last_seen{%%(queriesSelector)s, %(containerSelector)s}))' % { containerSelector: this.containerSelector }, }, }, }, @@ -48,7 +48,7 @@ function(this) avg( machine_memory_bytes{%%(queriesSelector)s} ) * 100 - ||| % {containerSelector: this.containerSelector}, + ||| % { containerSelector: this.containerSelector }, }, }, }, @@ -65,7 +65,7 @@ function(this) / avg by (instance) (machine_memory_bytes{%%(queriesSelector)s}) ) * 100 - ||| % {containerSelector: this.containerSelector}, + ||| % { containerSelector: this.containerSelector }, }, }, }, @@ -76,7 +76,7 @@ function(this) unit: 'percent', sources: { cadvisor: { - expr: 'avg by (%%(agg)s, name) (rate(container_cpu_usage_seconds_total{%%(queriesSelector)s, %(containerSelector)s}[$__rate_interval])) * 100' % {containerSelector: this.containerSelector}, + expr: 'avg by (%%(agg)s, name) (rate(container_cpu_usage_seconds_total{%%(queriesSelector)s, %(containerSelector)s}[$__rate_interval])) * 100' % { containerSelector: this.containerSelector }, legendCustomTemplate: commonlib.utils.labelsToPanelLegend(this.instanceLabels), }, },