Skip to content

Commit

Permalink
[alert] bugfix: the alert global preset config do not take effect (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsun28 committed Sep 4, 2022
1 parent 7efbf10 commit 1039267
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 11 additions & 1 deletion alerter/src/main/java/com/usthe/alert/dao/AlertDefineDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,24 @@ public interface AlertDefineDao extends JpaRepository<AlertDefine, Long>, JpaSpe
*/
void deleteAlertDefinesByIdIn(Set<Long> alertDefineIds);

/**
* 根据监控指标类型查询对应默认告警定义阈值
* @param app 监控类型
* @param metric 指标集合类型
* @return 告警定义
*/
List<AlertDefine> queryAlertDefinesByAppAndMetricAndPresetTrueAndEnableTrue(String app, String metric);

/**
* 根据监控ID查询与之关联的告警定义列表
* @param monitorId 监控ID
* @param app 监控类型
* @param metrics 指标组
* @return 告警定义列表
*/
@Query("select define from AlertDefine define join AlertDefineMonitorBind bind on bind.alertDefineId = define.id " +
"where bind.monitorId = :monitorId and define.metric = :metrics and define.enable = true")
"where bind.monitorId = :monitorId and define.app = :app and define.metric = :metrics and define.enable = true and define.preset = false")
List<AlertDefine> queryAlertDefinesByMonitor(@Param(value = "monitorId") Long monitorId,
@Param(value = "app") String app,
@Param(value = "metrics") String metrics);
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ public void applyBindAlertDefineMonitors(Long alertId, List<AlertDefineMonitorBi

@Override
public Map<String, List<AlertDefine>> getMonitorBindAlertDefines(long monitorId, String app, String metrics) {
List<AlertDefine> defines = alertDefineDao.queryAlertDefinesByMonitor(monitorId, metrics);
if (defines == null || defines.isEmpty()) {
List<AlertDefine> defines = alertDefineDao.queryAlertDefinesByMonitor(monitorId, app, metrics);
List<AlertDefine> defaultDefines = alertDefineDao.queryAlertDefinesByAppAndMetricAndPresetTrueAndEnableTrue(app, metrics);
defines.addAll(defaultDefines);
if (defines.isEmpty()) {
return null;
}
// 将告警阈值定义从告警级别0-3数字升序排序,数字越小告警基本越高,即从最高的告警阈值开始匹配计算
Expand Down

0 comments on commit 1039267

Please sign in to comment.