Skip to content

[缺陷] DetectMixin._update_monitor_d_checkpoint 存在 checkpoint 回退风险(旧时间戳覆盖新值) #8353

@CosmosNi

Description

@CosmosNi

🐛 Bug Report: DetectMixin._update_monitor_d_checkpoint 可能导致 checkpoint 回退(时间戳被旧数据覆盖)

📦 环境信息 (Environment)

  • 项目: 蓝鲸智云 - 监控平台 (BlueKing - Monitor)
  • 模块: alarm_backends.core.control.DetectMixin
  • Python 版本: 3.x
  • 监控平台版本: (请填写)
  • Redis 版本: (可选)

🧠 问题描述 (Description)

在检测任务执行过程中,DetectMixin._update_monitor_d_checkpoint() 方法负责将检测结果及最后检测点(checkpoint)写入 Redis。
但是当前逻辑存在潜在问题:

在多实例或并发检测场景中,后执行的检测任务可能写入一个比 Redis 中已有 checkpoint 更小的时间戳,从而导致 checkpoint 回退

这会造成:

  • 检测任务重复检测旧数据;
  • 可能漏检测新数据;
  • Redis 中 checkpoint 数据不一致;
  • 性能和检测结果准确性下降。

⚙️ 复现步骤 (Steps to Reproduce)

  1. 启动多个检测任务实例(同一策略、同一 item、同一维度)。
  2. 实例 A 在时间戳 T2(较新) 完成检测并写入 checkpoint。
  3. 实例 B 稍后执行,但检测的是时间戳 T1 < T2 的旧数据。
  4. _update_monitor_d_checkpoint() 未对比旧值,直接覆盖 Redis 中 checkpoint。
  5. 最终 Redis 中的 checkpoint 值从 T2 回退到 T1

🧾 实际结果 (Actual Behavior)

Redis 中的 LAST_CHECKPOINTS_CACHE_KEY 对应字段可能被旧检测任务覆盖,例如:

维度 原值(正确) 被覆盖后 问题
abcd1234 1728640000 1728635000 ❌ 回退(错误)

✅ 期望结果 (Expected Behavior)

  • 更新 checkpoint 前,应先从 Redis 获取当前值;
  • 仅当新 checkpoint 大于旧值 时,才执行更新;
  • 确保 Redis 中 checkpoint 始终保持“最新”时间戳。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions