From 836c5e3e28ff22c554efa23eb96fec6b9b025f63 Mon Sep 17 00:00:00 2001 From: Chris Cowan Date: Mon, 2 Mar 2020 13:02:00 -0700 Subject: [PATCH] [Metrics UI] Use CPU Usage limits for Kubernetes pods when available (#58424) (#58906) Co-authored-by: Elastic Machine Co-authored-by: Elastic Machine --- .../pod/metrics/snapshot/cpu.ts | 20 ++++++++++++++++++- .../pod/metrics/tsvb/pod_cpu_usage.ts | 16 ++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/infra/common/inventory_models/pod/metrics/snapshot/cpu.ts b/x-pack/plugins/infra/common/inventory_models/pod/metrics/snapshot/cpu.ts index f25dd8179aa1a..d5979d455f0bf 100644 --- a/x-pack/plugins/infra/common/inventory_models/pod/metrics/snapshot/cpu.ts +++ b/x-pack/plugins/infra/common/inventory_models/pod/metrics/snapshot/cpu.ts @@ -7,9 +7,27 @@ import { SnapshotModel } from '../../../types'; export const cpu: SnapshotModel = { - cpu: { + cpu_with_limit: { + avg: { + field: 'kubernetes.pod.cpu.usage.limit.pct', + }, + }, + cpu_without_limit: { avg: { field: 'kubernetes.pod.cpu.usage.node.pct', }, }, + cpu: { + bucket_script: { + buckets_path: { + with_limit: 'cpu_with_limit', + without_limit: 'cpu_without_limit', + }, + script: { + source: 'params.with_limit > 0.0 ? params.with_limit : params.without_limit', + lang: 'painless', + }, + gap_policy: 'skip', + }, + }, }; diff --git a/x-pack/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_cpu_usage.ts b/x-pack/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_cpu_usage.ts index 1d778d11e0725..52d48c6329e51 100644 --- a/x-pack/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_cpu_usage.ts +++ b/x-pack/plugins/infra/common/inventory_models/pod/metrics/tsvb/pod_cpu_usage.ts @@ -24,9 +24,23 @@ export const podCpuUsage: TSVBMetricModelCreator = ( metrics: [ { field: 'kubernetes.pod.cpu.usage.node.pct', - id: 'avg-cpu-usage', + id: 'avg-cpu-without', type: 'avg', }, + { + field: 'kubernetes.pod.cpu.usage.limit.pct', + id: 'avg-cpu-with', + type: 'avg', + }, + { + id: 'cpu-usage', + type: 'calculation', + variables: [ + { id: 'cpu_with', name: 'with_limit', field: 'avg-cpu-with' }, + { id: 'cpu_without', name: 'without_limit', field: 'avg-cpu-without' }, + ], + script: 'params.with_limit > 0.0 ? params.with_limit : params.without_limit', + }, ], }, ],