Skip to content

[BUG] <Duplicate alarms exist for deleted monitoring resources> #2402

Open

Description

@PollosD

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

No response

Expected Behavior

No response

Steps To Reproduce

1.新增一个website监控并且配置企业微信告警
2.删除该website监控资源后,企业微信会收到监控不可用的告警,告警内容只会显示监控ID,数据库里面查不到该ID,并且会重复发送,但是实际上已经不需要这个告警了

Environment

HertzBeat version(s):1.6

Debug logs

No response

Anything else?

以下为企业微信告警截图
image

Activity

  1. added
    bug
    on Jul 29, 2024
  2. changed the title [-][BUG] <已删除的监控资源存在重复告警>[/-] [+][BUG] <Duplicate alarms exist for deleted monitoring resources>[/+] on Jul 29, 2024
  3. thefullgc commented on Jul 29, 2024

    @thefullgc
    Member

    Maybe it is a bug, i guess due the monitoring info is deleted, but the metrics collection task is still being executed.

  4. Doyle-net commented on Jan 14, 2026

    @Doyle-net

    This issue still exists in version 1.7.3.

  5. RohanExploit commented on Aug 19, 2026

    @RohanExploit

    I dug into this on current master (67c861a). The bug still reproduces, but the cause suggested in 2024 no longer matches the code, so here is what I found.

    MonitorServiceImpl.deleteMonitors does cancel the job now:

    collectorMonitorBindDao.deleteCollectorMonitorBindsByMonitorId(monitor.getId());
    collectJobScheduling.cancelAsyncCollectJob(monitor.getJobId());
    applicationContext.publishEvent(new MonitorDeletedEvent(applicationContext, monitor.getId()));

    So collection really does stop. The repeated alerts are not new collections, they are one alert that can never leave the firing state:

    1. Any alert already firing for that monitor lives in AlarmCacheManager.firingAlertMap and in single_alert with status FIRING.
    2. The only thing that clears it is handleRecoveredAlert(...) in MetricsRealTimeAlertCalculator, which is driven by incoming MetricsData.
    3. The job is cancelled, so no MetricsData ever arrives for that monitor again, and the alert can never recover.
    4. AlarmGroupReduce re-sends firing groups on a fixed timer (scheduleAtFixedRate(this::dispatchCheckAndSendGroups, 10000, CHECK_INTERVAL) at line 130), throttled per group by repeatInterval (default 4h). That is the "重复发送" part, and it is timer driven, so it keeps going with no further input.
    5. AlarmCacheManager's constructor reloads every FIRING row from singleAlertDao.querySingleAlertsByStatus(...), so a restart does not clear it either.

    The alert shows only the raw ID because the monitor row is gone, so nothing can resolve it to a name.

    There is already an event meant for exactly this cleanup, but nothing consumes it. Grepping the whole tree for MonitorDeletedEvent returns only four hits: the class itself, the import, and the two publishEvent calls (MonitorServiceImpl lines 504 and 713). There is no @EventListener for it anywhere.

    One thing that makes the fix a design decision rather than a one liner: the alert fingerprint labels do not carry the monitor id. MetricsRealTimeAlertCalculator builds them as

    commonFingerPrints.put(CommonConstants.LABEL_DEFINE_ID, String.valueOf(define.getId()));
    commonFingerPrints.put(CommonConstants.LABEL_ALERT_NAME, define.getName());
    commonFingerPrints.put(CommonConstants.LABEL_INSTANCE_NAME, instanceName);
    commonFingerPrints.put(CommonConstants.LABEL_INSTANCE, instanceHost);

    LABEL_INSTANCE is the monitor's instance field (host:port), not its id. The monitor id is only put into commonContext under __instance__ for expression evaluation, and never reaches the stored labels. So a listener cannot currently select "all firing alerts for monitor 123" without either matching on host, which is ambiguous when two monitors share a host, or adding a monitor id label.

    Two directions I can see:

    • Add a monitor id label to the fingerprint in the calculator, then add a MonitorDeletedEvent listener that resolves the matching firing alerts in both AlarmCacheManager and single_alert. Cleanest to target, but it changes fingerprints, so existing firing alerts would need a migration or would be orphaned once.
    • Keep fingerprints as they are and have the listener resolve by the deleted monitor's instance plus instancename labels. Smaller blast radius, but ambiguous when several monitors share a host.

    I would rather not guess which tradeoff you want. If a maintainer picks a direction I am happy to implement it with tests. @tomsun28 since you triaged this originally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions