gocrane / crane

Crane is a FinOps Platform for Cloud Resource Analytics and Economics in Kubernetes clusters. The goal is not only to help users to manage cloud cost easier but also ensure the quality of applications.
https://gocrane.io
Apache License 2.0
1.87k stars 382 forks source link

pkg/oom/recorder.go cleanOOMRecord函数保留的record问题 #844

Closed Zz-zheng-Zz closed 7 months ago

Zz-zheng-Zz commented 1 year ago
func (r *PodOOMRecorder) cleanOOMRecords(oomRecords []OOMRecord) []OOMRecord {
    r.mu.Lock()
    defer r.mu.Unlock()

    if len(oomRecords) > r.OOMRecordMaxNumber {
        records := oomRecords
        sort.Slice(records, func(i, j int) bool {
            return records[i].OOMAt.Before(records[j].OOMAt)
        })

        records = records[0:r.OOMRecordMaxNumber]
        oomRecords = records
    }

    return oomRecords
}

Describe the bug

您好,想请教一下,这段代码用于清理超过默认保留数量的OOM历史数据,但是看起来排序后,将时间久远的数据排列在数组前面,然后保留了数组前默认条数的数据,也就是说保留了旧数据,而删除了新数据,这样做的考量是什么呢 Reproduce steps

Expected behavior

Screenshots

Environment (please complete the following information):

qmhu commented 1 year ago

I think this is a bug, would you like to fix it ?

Zz-zheng-Zz commented 1 year ago

Sure, but I’m not sure how to request permission to submit code and initiate a PR. emmmm0.0

qmhu commented 1 year ago

Sure, but I’m not sure how to request permission to submit code and initiate a PR. emmmm0.0

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork