Skip to content

Commit

Permalink
refactor: always report oom events (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
xzchaoo authored Oct 24, 2023
1 parent 75fb2bc commit bcd122a
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions pkg/cri/impl/engine/docker_oom_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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",
Expand All @@ -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()
Expand Down

0 comments on commit bcd122a

Please sign in to comment.