Skip to content

Commit

Permalink
feat: 采集器修复 k8sevent 采集问题 --story=119116744 (#483)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiandongx authored Aug 9, 2024
1 parent 8a276f2 commit e0caf97
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/bkmonitorbeat/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v3.43.x
v3.44.x
26 changes: 20 additions & 6 deletions pkg/bkmonitorbeat/tasks/kubeevent/gather.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (r *recorder) loopSent() {
// 表示这段时间内没有产生事件
if cnt <= 0 {
if cnt < 0 {
logger.Errorf("get negative counter, event:%+v", cloned)
logger.Errorf("get negative counter, event: %+v", cloned)
}
continue
}
Expand Down Expand Up @@ -127,13 +127,27 @@ func (r *recorder) Recv(event k8sEvent) {
h := event.Hash()
if _, ok := r.set[h]; !ok {
r.set[h] = &event
// 如果事件的第一次发生时间是在采集器启动后 那就是按原始的次数来计算了
if event.GetFirstTime() > r.started {
switch {
case event.GetFirstTime() > r.started:
// 事件第一次发生时间在采集器启动后
// 按原始的次数计算
r.set[h].windowL = 0
} else {
r.set[h].windowL = event.GetCount()
r.set[h].windowR = event.GetCount()

case event.GetLastTime() > r.started:
// 事件在采集器启动前就已发送过
// 最近一次发生的时间在采集器启动后(可能是缓存进行了清理)
// 次数记录为 1
r.set[h].windowL = event.GetCount() - 1
r.set[h].windowR = event.GetCount()

default:
// 事件第一次发生时间在采集器启动前
// 事件最近一次发生时间也在采集器启动前
// 次数为 0 且下个周期不发送
r.set[h].windowL = 0
r.set[h].windowR = 0
}
r.set[h].windowR = event.GetCount()
logger.Infof("receive set event first: %+v", r.set[h])
return
}
Expand Down

0 comments on commit e0caf97

Please sign in to comment.