From 53bf67ce40fe6564efd15f25cd6da0249f360a12 Mon Sep 17 00:00:00 2001 From: Tetiana Kravchenko Date: Tue, 2 Jul 2024 00:20:01 +0200 Subject: [PATCH] [metricbeat/kubernetes] Remove fallback to the Node's limit for the pod 'usage.limit.pct' metrics (#40029) * Remove fallback to the node limit for the usage.limit.pct metrics calculation Signed-off-by: Tetiana Kravchenko * remove debug files Signed-off-by: Tetiana Kravchenko * fix the fields description Signed-off-by: Tetiana Kravchenko * Update metricbeat/docs/fields.asciidoc Co-authored-by: Andrew Gizas * Update metricbeat/docs/fields.asciidoc Co-authored-by: Andrew Gizas * Update metricbeat/docs/fields.asciidoc Co-authored-by: Andrew Gizas * update fields description Signed-off-by: Tetiana Kravchenko --------- Signed-off-by: Tetiana Kravchenko Co-authored-by: Andrew Gizas --- CHANGELOG.next.asciidoc | 1 + metricbeat/docs/fields.asciidoc | 6 +-- metricbeat/module/kubernetes/fields.go | 2 +- .../module/kubernetes/pod/_meta/fields.yml | 6 +-- metricbeat/module/kubernetes/pod/data.go | 52 +++++++------------ metricbeat/module/kubernetes/pod/pod_test.go | 31 +++++++---- 6 files changed, 46 insertions(+), 52 deletions(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 1b0751dda0e..fe38da3768f 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -52,6 +52,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff] - Setting period for counter cache for Prometheus remote_write at least to 60sec {pull}38553[38553] - Add support of Graphite series 1.1.0+ tagging extension for statsd module. {pull}39619[39619] +- Remove fallback to the node limit for the `kubernetes.pod.cpu.usage.limit.pct` and `kubernetes.pod.memory.usage.limit.pct` metrics calculation *Osquerybeat* diff --git a/metricbeat/docs/fields.asciidoc b/metricbeat/docs/fields.asciidoc index 92af8d33410..75ac7364e74 100644 --- a/metricbeat/docs/fields.asciidoc +++ b/metricbeat/docs/fields.asciidoc @@ -45158,7 +45158,7 @@ format: percent *`kubernetes.pod.cpu.usage.limit.pct`*:: + -- -CPU usage as a percentage of the defined limit for the pod containers (or total node CPU if one or more containers of the pod are unlimited). If one or more containers of the pod is unlimited and the `node` and `state_node` metricsets are both disabled on that node, this metric will be missing entirely. +CPU usage as a percentage of the defined cpu limits sum of the pod containers. If any container is missing a limit the metric is not emitted. type: scaled_float @@ -45196,7 +45196,7 @@ format: percent *`kubernetes.pod.memory.usage.limit.pct`*:: + -- -Memory usage as a percentage of the defined limit for the pod containers (or total node allocatable memory if unlimited). If one or more containers of the pod is unlimited and the `node` and `state_node` metricsets are both disabled on that node, this metric will be missing entirely. +Memory usage as a percentage of the defined memory limits sum of the pod containers. If any container is missing a limit the metric is not emitted. type: scaled_float @@ -45234,7 +45234,7 @@ format: bytes *`kubernetes.pod.memory.working_set.limit.pct`*:: + -- -Working set memory usage as a percentage of the defined limit for the pod containers (or total node allocatable memory if unlimited) +Working set memory usage as a percentage of the defined limits sum of the pod containers. If any container is missing a limit the metric is not emitted. type: scaled_float diff --git a/metricbeat/module/kubernetes/fields.go b/metricbeat/module/kubernetes/fields.go index 36d93f81a8e..4bbdcdf334d 100644 --- a/metricbeat/module/kubernetes/fields.go +++ b/metricbeat/module/kubernetes/fields.go @@ -32,5 +32,5 @@ func init() { // AssetKubernetes returns asset data. // This is the base64 encoded zlib format compressed contents of module/kubernetes. func AssetKubernetes() string { - return "eJzsfU9z2ziT9z2fAuXLm7zlUe05tfVUZZxndrzJZLx2MnPY2lIgEpIwpgAOANrRU/vht/CXIAmQlAjKTiwdpia21f1Do9HobjQaP4F7tH8L7qsVYgQJxF8BILAo0Ftw8cH98OIVADniGcOlwJS8Bf94BQAA9R+AHRIMZ/LbDBUIcvQWbOArADgSApMNfwv++4Lz4uISXGyFKC/+R/5uS5lYZpSs8eYtWMOCo1cArDEqcv5WMfgJELhDLXjyI/al5MBoVZqfBODJzzVZU7aD8scAkhxwAQXmAmcc0DUoac7BDhK4QTlY7T0+C0PBonEELSRYYo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H/BK1NMvqbRfvyPjenilWQHhlmCTSh7qlkpRh1A13QulisfNQeAJJ/cwSXiUB5S0DY3u5iuouNSA4w6A1HejZjoEqI9qY5A0WA85THyIgc8k8FJfm000yW8/IzYd+5HSvqIMGZETSKJPGzZQQkJjlXojgY4EqdUB5RGWM5XszadEsdI2ME5qQxVyYLxkddNkUyoXHrDb4TpH++CFCeP27m6cKB4pu8dkwwOu4suSyB96oCY8HyGZEm60rxDXlSnHk167cWmpIpycPYB/UnYyRIpbEFfTNUvkqTQLDp/MQe9KxSs1DHJbJ3xKMFRqOES0jzB4lqvwH7hAxjFVBbwDNc3goGPkFyqiunJ9UEaB/lXgpYtHeVNRyfiDKIOvGtRD4BksUL6M3SzxB1IilnXfIzxwKDeaiDSzdA1MgYWKFqMTjAnNe+4hTJniiO6ApO7vVz1ZkUF4lpWh/tgkBZh/MITGgIm9u5AWjfZfR8D5AdTYjOL/AgAA//+vcV5m" } diff --git a/metricbeat/module/kubernetes/pod/_meta/fields.yml b/metricbeat/module/kubernetes/pod/_meta/fields.yml index 89ef634c660..08cefde98d5 100644 --- a/metricbeat/module/kubernetes/pod/_meta/fields.yml +++ b/metricbeat/module/kubernetes/pod/_meta/fields.yml @@ -56,7 +56,7 @@ type: scaled_float format: percent description: > - CPU usage as a percentage of the defined limit for the pod containers (or total node CPU if one or more containers of the pod are unlimited). If one or more containers of the pod is unlimited and the `node` and `state_node` metricsets are both disabled on that node, this metric will be missing entirely. + CPU usage as a percentage of the defined cpu limits sum of the pod containers. If any container is missing a limit the metric is not emitted. - name: memory type: group fields: @@ -77,7 +77,7 @@ type: scaled_float format: percent description: > - Memory usage as a percentage of the defined limit for the pod containers (or total node allocatable memory if unlimited). If one or more containers of the pod is unlimited and the `node` and `state_node` metricsets are both disabled on that node, this metric will be missing entirely. + Memory usage as a percentage of the defined memory limits sum of the pod containers. If any container is missing a limit the metric is not emitted. - name: available type: group fields: @@ -98,7 +98,7 @@ type: scaled_float format: percent description: > - Working set memory usage as a percentage of the defined limit for the pod containers (or total node allocatable memory if unlimited) + Working set memory usage as a percentage of the defined limits sum of the pod containers. If any container is missing a limit the metric is not emitted. - name: rss type: group fields: diff --git a/metricbeat/module/kubernetes/pod/data.go b/metricbeat/module/kubernetes/pod/data.go index fdabbfab640..c06cbb4860a 100644 --- a/metricbeat/module/kubernetes/pod/data.go +++ b/metricbeat/module/kubernetes/pod/data.go @@ -58,6 +58,9 @@ func eventMapping(content []byte, metricsRepo *util.MetricsRepo, logger *logp.Lo podId := util.NewPodId(pod.PodRef.Namespace, pod.PodRef.Name) podStore := nodeStore.GetPodStore(podId) + allContainersCPULimitsDefined := true + allContainersMemoryLimitsDefined := true + for _, container := range pod.Containers { usageNanoCores += container.CPU.UsageNanoCores usageMem += container.Memory.UsageBytes @@ -70,17 +73,22 @@ func eventMapping(content []byte, metricsRepo *util.MetricsRepo, logger *logp.Lo containerStore := podStore.GetContainerStore(container.Name) containerMetrics := containerStore.GetContainerMetrics() - containerCoresLimit := nodeCores - if containerMetrics.CoresLimit != nil { - containerCoresLimit = containerMetrics.CoresLimit.Value + // podCoreLimit and podMemLimit are defined only if all of Pod containers have a limit defined, otherwise the limit will be set to 0 + if allContainersCPULimitsDefined && containerMetrics.CoresLimit == nil { + allContainersCPULimitsDefined = false + podCoreLimit = 0.0 + } + if allContainersCPULimitsDefined { + podCoreLimit += containerMetrics.CoresLimit.Value } - containerMemLimit := nodeMem - if containerMetrics.MemoryLimit != nil { - containerMemLimit = containerMetrics.MemoryLimit.Value + if allContainersMemoryLimitsDefined && containerMetrics.MemoryLimit == nil { + allContainersMemoryLimitsDefined = false + podMemLimit = 0.0 + } + if allContainersMemoryLimitsDefined { + podMemLimit += containerMetrics.MemoryLimit.Value } - podCoreLimit += containerCoresLimit - podMemLimit += containerMemLimit } podEvent := mapstr.M{ @@ -132,32 +140,7 @@ func eventMapping(content []byte, metricsRepo *util.MetricsRepo, logger *logp.Lo kubernetes2.ShouldPut(podEvent, "start_time", pod.StartTime, logger) } - // NOTE: - // - `podCoreLimit > `nodeCores` is possible if a pod has more than one container - // and at least one of them doesn't have a limit set. The container without limits - // inherit a limit = `nodeCores` and the sum of all limits for all the - // containers will be > `nodeCores`. In this case we want to cap the - // value of `podCoreLimit` to `nodeCores`. - // - `nodeCores` can be 0 if `state_node` and/or `node` metricsets are disabled. - // - if `nodeCores` == 0 and podCoreLimit > 0` we need to avoid that `podCoreLimit` is - // incorrectly overridden to 0. That's why we check for `nodeCores > 0`. - if nodeCores > 0 && podCoreLimit > nodeCores { - podCoreLimit = nodeCores - } - - // NOTE: - // - `podMemLimit > `nodeMem` is possible if a pod has more than one container - // and at least one of them doesn't have a limit set. The container without limits - // inherit a limit = `nodeMem` and the sum of all limits for all the - // containers will be > `nodeMem`. In this case we want to cap the - // value of `podMemLimit` to `nodeMem`. - // - `nodeMem` can be 0 if `state_node` and/or `node` metricsets are disabled. - // - if `nodeMem` == 0 and podMemLimit > 0` we need to avoid that `podMemLimit` is - // incorrectly overridden to 0. That's why we check for `nodeMem > 0`. - if nodeMem > 0 && podMemLimit > nodeMem { - podMemLimit = nodeMem - } - + // `nodeCores` can be 0 if `state_node` and/or `node` metricsets are disabled if nodeCores > 0 { kubernetes2.ShouldPut(podEvent, "cpu.usage.node.pct", float64(usageNanoCores)/1e9/nodeCores, logger) } @@ -167,6 +150,7 @@ func eventMapping(content []byte, metricsRepo *util.MetricsRepo, logger *logp.Lo } if usageMem > 0 { + // `nodeMem` can be 0 if `state_node` and/or `node` metricsets are disabled if nodeMem > 0 { kubernetes2.ShouldPut(podEvent, "memory.usage.node.pct", float64(usageMem)/nodeMem, logger) } diff --git a/metricbeat/module/kubernetes/pod/pod_test.go b/metricbeat/module/kubernetes/pod/pod_test.go index e4aaca06f2b..7b46e5a272b 100644 --- a/metricbeat/module/kubernetes/pod/pod_test.go +++ b/metricbeat/module/kubernetes/pod/pod_test.go @@ -20,7 +20,7 @@ package pod import ( - "io/ioutil" + "io" "os" "testing" @@ -67,6 +67,7 @@ func (s *PodTestSuite) SetupTest() { s.NodeMetrics.MemoryAllocatable = util.NewFloat64Metric(146227200) s.ContainerMetrics = util.NewContainerMetrics() + s.ContainerMetrics.CoresLimit = util.NewFloat64Metric(0.5) s.ContainerMetrics.MemoryLimit = util.NewFloat64Metric(14622720) s.AnotherContainerMetrics = util.NewContainerMetrics() @@ -77,7 +78,7 @@ func (s *PodTestSuite) ReadTestFile(testFile string) []byte { f, err := os.Open(testFile) s.NoError(err, "cannot open test file "+testFile) - body, err := ioutil.ReadAll(f) + body, err := io.ReadAll(f) s.NoError(err, "cannot read test file "+testFile) return body @@ -98,7 +99,7 @@ func (s *PodTestSuite) TestEventMapping() { // calculated pct fields: "cpu.usage.nanocores": 11263994, "cpu.usage.node.pct": 0.005631997, - "cpu.usage.limit.pct": 0.005631997, + "cpu.usage.limit.pct": 0.022527988, "memory.usage.bytes": 1462272, "memory.usage.node.pct": 0.01, @@ -124,8 +125,10 @@ func (s *PodTestSuite) TestEventMappingWithZeroNodeMetrics() { cpuMemoryTestCases := map[string]interface{}{ "cpu.usage.nanocores": 11263994, + "cpu.usage.limit.pct": 0.022527988, "memory.usage.bytes": 1462272, + "memory.usage.limit.pct": 0.1, "memory.working_set.limit.pct": 0.09943977591036414, } @@ -144,6 +147,7 @@ func (s *PodTestSuite) TestEventMappingWithNoNodeMetrics() { cpuMemoryTestCases := map[string]interface{}{ "cpu.usage.nanocores": 11263994, + "cpu.usage.limit.pct": 0.022527988, "memory.usage.bytes": 1462272, "memory.usage.limit.pct": 0.1, @@ -153,7 +157,7 @@ func (s *PodTestSuite) TestEventMappingWithNoNodeMetrics() { s.RunMetricsTests(events[0], cpuMemoryTestCases) } -func (s *PodTestSuite) TestEventMappingWithMultipleContainers() { +func (s *PodTestSuite) TestEventMappingWithMultipleContainers_NodeAndOneContainerLimits() { s.MetricsRepo.DeleteAllNodeStore() s.addNodeMetric(s.NodeMetrics) @@ -168,18 +172,23 @@ func (s *PodTestSuite) TestEventMappingWithMultipleContainers() { // Following comments explain what is the difference with the test `TestEventMapping` "cpu.usage.nanocores": 22527988, // 2x usage since 2 container "cpu.usage.node.pct": 0.011263994, // 2x usage since 2 container - "cpu.usage.limit.pct": 0.011263994, // same value as `cpu.usage.node.pct` since `podCoreLimit` = 2x nodeCores = `nodeCores` (capped value) + // "cpu.usage.limit.pct" is not reported, since AnotherCntainer does not contain CoresLimit - "memory.usage.bytes": 2924544, // 2x since 2 containers - "memory.usage.node.pct": 0.02, // 2x usage since 2 containers - "memory.usage.limit.pct": 0.02, // same value as `cpu.usage.node.pct` since 2 containers but only 1 with limit, podMemLimit = containerMemLimit + nodeLimit > nodeLimit = nodeLimit (capped value) - "memory.working_set.limit.pct": 0.019887955182072828, // similar concept to `memory.usage.limit.pct`. 2x usage but denominator 10x since nodeLimit = 10x containerMemLimit + "memory.usage.bytes": 2924544, // 2x since 2 containers + "memory.usage.node.pct": 0.02, // 2x usage since 2 containers + // "memory.usage.limit.pct" is not reported, since AnotherContainer metrics were not added + // "memory.working_set.limit.pct" is not reported, since AnotherContainer metrics were not added } s.RunMetricsTests(events[0], cpuMemoryTestCases) } -func (s *PodTestSuite) TestEventMappingWithMultipleContainersWithAllMemLimits() { +// Scenario: +// Node metrics are defined, +// Pod contains 2 containers: +// - nginx with both cpu and memore limits defined +// - sidecar with memory limit defined +func (s *PodTestSuite) TestEventMappingWithMultipleContainers_AllMemLimits() { s.MetricsRepo.DeleteAllNodeStore() s.addNodeMetric(s.NodeMetrics) @@ -195,7 +204,7 @@ func (s *PodTestSuite) TestEventMappingWithMultipleContainersWithAllMemLimits() // Following comments explain what is the difference with the test `TestEventMapping "cpu.usage.nanocores": 22527988, // 2x usage since 2 container "cpu.usage.node.pct": 0.011263994, // 2x usage since 2 container - "cpu.usage.limit.pct": 0.011263994, // same value as `cpu.usage.node.pct` since `podCoreLimit` = 2x nodeCores = `nodeCores` (capped value) + // "cpu.usage.limit.pct" is not reported, since AnotherCntainer does not contain CoresLimit "memory.usage.bytes": 2924544, // 2x since 2 containers "memory.usage.node.pct": 0.02, // 2x usage since 2 containers