From bcd122ab49937dc14a3b876f9e4a3c9855b4db4d Mon Sep 17 00:00:00 2001 From: xzchaoo Date: Tue, 24 Oct 2023 17:44:01 +0800 Subject: [PATCH] refactor: always report oom events (#78) --- pkg/cri/impl/engine/docker_oom_manager.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/pkg/cri/impl/engine/docker_oom_manager.go b/pkg/cri/impl/engine/docker_oom_manager.go index 81a51f3..3684f2d 100644 --- a/pkg/cri/impl/engine/docker_oom_manager.go +++ b/pkg/cri/impl/engine/docker_oom_manager.go @@ -18,6 +18,7 @@ import ( "github.com/traas-stack/holoinsight-agent/pkg/plugin/output/gateway" "github.com/traas-stack/holoinsight-agent/pkg/util" "go.uber.org/zap" + k8stypes "k8s.io/apimachinery/pkg/types" "time" ) @@ -135,14 +136,14 @@ func (m *OOMManager) emitLoop() { func (m *OOMManager) emitOOMMetrics(emitTime time.Time) { record := m.oomRecoder.getAndClear() - if len(record) == 0 { - return - } // k8s_pod_oom var metrics []*model.Metric + + processed := make(map[k8stypes.UID]struct{}) for _, item := range record { tags := meta.ExtractContainerCommonTags(item.container) + processed[item.container.Pod.UID] = struct{}{} metrics = append(metrics, &model.Metric{ Name: "k8s_pod_oom", @@ -151,6 +152,21 @@ func (m *OOMManager) emitOOMMetrics(emitTime time.Time) { Value: float64(item.count), }) } + pods := m.CRI.GetAllPods() + for _, pod := range pods { + if _, ok := processed[pod.UID]; ok { + continue + } + processed[pod.UID] = struct{}{} + tags := meta.ExtractPodCommonTags(pod.Pod) + tags["container"] = "-" + metrics = append(metrics, &model.Metric{ + Name: "k8s_pod_oom", + Tags: tags, + Timestamp: emitTime.UnixMilli(), + Value: float64(0), + }) + } // TODO Decoupling data production and consumption begin := time.Now()