This is an automated email from the ASF dual-hosted git repository.
wangtao29 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozhera.git
The following commit(s) were added to refs/heads/master by this push:
new d576df37 feat: extended business alarm (#582)
d576df37 is described below
commit d576df3767698689ebef03aa165f518219de83d9
Author: gaoxh <[email protected]>
AuthorDate: Mon May 19 14:49:00 2025 +0800
feat: extended business alarm (#582)
---
.../apache/ozhera/monitor/bo/AlarmRuleType.java | 4 +-
.../ozhera/monitor/bo/AlarmStrategyType.java | 2 +
.../service/api/AppAlarmServiceExtension.java | 10 +++++
.../api/impl/AppAlarmServiceExtensionImpl.java | 19 ++++++++
.../service/impl/AlarmStrategyServiceImpl.java | 51 ++++++++++++++++------
.../monitor/service/impl/AppAlarmServiceImpl.java | 36 ++++++++++++---
.../service/model/prometheus/AlarmRuleRequest.java | 1 +
7 files changed, 102 insertions(+), 21 deletions(-)
diff --git
a/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/bo/AlarmRuleType.java
b/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/bo/AlarmRuleType.java
index f7eff598..9dbcfb5d 100644
---
a/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/bo/AlarmRuleType.java
+++
b/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/bo/AlarmRuleType.java
@@ -27,7 +27,9 @@ public enum AlarmRuleType {
template(0,"模版规则"),
- app_config(1,"应用配置规则")
+ app_config(1,"应用配置规则"),
+
+ business_config(2,"业务指标配置规则"),
;
private Integer code;
diff --git
a/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/bo/AlarmStrategyType.java
b/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/bo/AlarmStrategyType.java
index e399479c..70885652 100644
---
a/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/bo/AlarmStrategyType.java
+++
b/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/bo/AlarmStrategyType.java
@@ -31,6 +31,7 @@ public enum AlarmStrategyType {
INTERFACE(1,"接口类监控", "Interface monitoring"),
PAOMQL(2,"自定义PromQL", "Custom PromQL"),
TESLA(3,"TESLA监控", "TESLA Monitoring"),
+ BUSINESS_METRIC(4,"业务指标监控", "BUSINESS_METRIC Monitoring"),
;
private Integer code;
private String label;
@@ -54,6 +55,7 @@ public enum AlarmStrategyType {
list.add(new Triple(AlarmStrategyType.SYSTEM.getCode() + "",
AlarmStrategyType.SYSTEM.getLabel(), AlarmStrategyType.SYSTEM.getLabelEn()));
list.add(new Triple(AlarmStrategyType.INTERFACE.getCode() + "",
AlarmStrategyType.INTERFACE.getLabel(),
AlarmStrategyType.INTERFACE.getLabelEn()));
list.add(new Triple(AlarmStrategyType.PAOMQL.getCode(),
AlarmStrategyType.PAOMQL.getLabel(), AlarmStrategyType.PAOMQL.getLabelEn()));
+ list.add(new Triple(AlarmStrategyType.BUSINESS_METRIC.getCode(),
AlarmStrategyType.BUSINESS_METRIC.getLabel(),
AlarmStrategyType.BUSINESS_METRIC.getLabelEn()));
return list;
}
diff --git
a/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/service/api/AppAlarmServiceExtension.java
b/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/service/api/AppAlarmServiceExtension.java
index 59c369c3..9a5f10d2 100644
---
a/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/service/api/AppAlarmServiceExtension.java
+++
b/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/service/api/AppAlarmServiceExtension.java
@@ -18,7 +18,10 @@
*/
package org.apache.ozhera.monitor.service.api;
+import org.apache.ozhera.monitor.bo.AlarmStrategyParam;
import org.apache.ozhera.monitor.result.Result;
+import org.apache.ozhera.monitor.service.model.prometheus.AlarmRuleData;
+import org.apache.ozhera.monitor.service.model.prometheus.AlarmRuleRequest;
public interface AppAlarmServiceExtension {
Result queryFunctionList(Integer projectId);
@@ -26,4 +29,11 @@ public interface AppAlarmServiceExtension {
Result queryRulesByIamId(Integer iamId, String userName);
Integer getAlarmIdByResult(Result result);
+
+ Result createBusinessAlert(AlarmRuleRequest param);
+
+ Result editBusinessAlert(AlarmRuleRequest param);
+
+ Result editBusinessAlertSingle(AlarmRuleData ruleData, String user);
+
}
diff --git
a/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/service/api/impl/AppAlarmServiceExtensionImpl.java
b/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/service/api/impl/AppAlarmServiceExtensionImpl.java
index e5ef188e..0c41e738 100644
---
a/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/service/api/impl/AppAlarmServiceExtensionImpl.java
+++
b/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/service/api/impl/AppAlarmServiceExtensionImpl.java
@@ -18,8 +18,11 @@
*/
package org.apache.ozhera.monitor.service.api.impl;
+import org.apache.ozhera.monitor.bo.AlarmStrategyParam;
import org.apache.ozhera.monitor.result.Result;
import org.apache.ozhera.monitor.service.api.AppAlarmServiceExtension;
+import org.apache.ozhera.monitor.service.model.prometheus.AlarmRuleData;
+import org.apache.ozhera.monitor.service.model.prometheus.AlarmRuleRequest;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
@@ -46,4 +49,20 @@ public class AppAlarmServiceExtensionImpl implements
AppAlarmServiceExtension {
Double alarmId = (Double) result.getData();
return alarmId == null ? null : alarmId.intValue();
}
+
+ @Override
+ public Result createBusinessAlert(AlarmRuleRequest param) {
+ return null;
+ }
+
+ @Override
+ public Result editBusinessAlert(AlarmRuleRequest param) {
+ return null;
+ }
+
+ @Override
+ public Result editBusinessAlertSingle(AlarmRuleData ruleData, String user)
{
+ return null;
+ }
+
}
diff --git
a/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/service/impl/AlarmStrategyServiceImpl.java
b/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/service/impl/AlarmStrategyServiceImpl.java
index cc7378e0..73227441 100644
---
a/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/service/impl/AlarmStrategyServiceImpl.java
+++
b/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/service/impl/AlarmStrategyServiceImpl.java
@@ -22,6 +22,7 @@ package org.apache.ozhera.monitor.service.impl;
import com.google.common.collect.Lists;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
+import com.xiaomi.mone.tpc.login.util.GsonUtil;
import org.apache.ozhera.monitor.bo.AlarmStrategyInfo;
import org.apache.ozhera.monitor.bo.AlarmStrategyParam;
import org.apache.ozhera.monitor.bo.AlarmStrategyType;
@@ -36,6 +37,7 @@ import org.apache.ozhera.monitor.result.ErrorCode;
import org.apache.ozhera.monitor.result.Result;
import org.apache.ozhera.monitor.service.AlarmStrategyService;
import org.apache.ozhera.monitor.service.AppAlarmService;
+import org.apache.ozhera.monitor.service.api.AppAlarmServiceExtension;
import org.apache.ozhera.monitor.service.model.PageData;
import org.apache.ozhera.monitor.service.model.prometheus.AlarmRuleRequest;
import org.apache.ozhera.monitor.service.prometheus.PrometheusService;
@@ -74,6 +76,9 @@ public class AlarmStrategyServiceImpl implements
AlarmStrategyService {
@Autowired
private PrometheusService prometheusService;
+
+ @Autowired
+ private AppAlarmServiceExtension appAlarmServiceExtension;
private static final List<String> orderSorts = Lists.newArrayList("asc",
"ASC", "desc", "DESC");
@@ -248,26 +253,35 @@ public class AlarmStrategyServiceImpl implements
AlarmStrategyService {
@Override
public Result enabled(String user, AlarmStrategyParam param) {
+
AlarmStrategy strategy = appAlarmStrategyDao.getById(param.getId());
if (strategy == null) {
return Result.fail(ErrorCode.nonExistentStrategy);
}
- AppMonitor app =
-
AlarmStrategyType.TESLA.getCode().equals(strategy.getStrategyType()) ?
appMonitorDao.getByIamTreeId(
- strategy.getIamId())
- : appMonitorDao.getMyApp(strategy.getAppId(),
strategy.getIamId(), user, AppViewType.MyApp);
- if (app == null) {
- return Result.fail(ErrorCode.NoOperPermission);
+
+
if(!AlarmStrategyType.BUSINESS_METRIC.getCode().equals(strategy.getStrategyType())){
+ AppMonitor app =
+
AlarmStrategyType.TESLA.getCode().equals(strategy.getStrategyType()) ?
appMonitorDao.getByIamTreeId(
+ strategy.getIamId())
+ : appMonitorDao.getMyApp(strategy.getAppId(),
strategy.getIamId(), user, AppViewType.MyApp);
+ if (app == null) {
+ return Result.fail(ErrorCode.NoOperPermission);
+ }
}
+
Integer ruleStat = param.getStatus() == 0 ? 1 : 0;
Result result = appAlarmService.enabledRules(strategy.getIamId(),
strategy.getId(), ruleStat, user);
+ log.info("enabled alarm result : {}", GsonUtil.gsonString(result));
if (result.getCode() != ErrorCode.success.getCode()) {
return result;
}
strategy = new AlarmStrategy();
strategy.setId(param.getId());
strategy.setStatus(param.getStatus());
- if (!appAlarmStrategyDao.updateById(strategy)) {
+ boolean updateDb = appAlarmStrategyDao.updateById(strategy);
+ log.info("enabled updateDb : {}", updateDb);
+ if (!updateDb) {
+ log.info("enabled alarm result : {}", GsonUtil.gsonString(result));
return Result.fail(ErrorCode.unknownError);
}
log.info("enabled规则策略成功:strategy={}", strategy);
@@ -307,12 +321,15 @@ public class AlarmStrategyServiceImpl implements
AlarmStrategyService {
return Result.fail(ErrorCode.nonExistentStrategy);
}
log.info("AlarmStrategyService.deleteById strategy : {}", new
Gson().toJson(strategy));
- AppMonitor app =
-
AlarmStrategyType.TESLA.getCode().equals(strategy.getStrategyType()) ?
appMonitorDao.getByIamTreeId(
- strategy.getIamId())
- : appMonitorDao.getMyApp(strategy.getAppId(),
strategy.getIamId(), user, AppViewType.MyApp);
- if (app == null) {
- return Result.fail(ErrorCode.NoOperPermission);
+
+
if(!AlarmStrategyType.BUSINESS_METRIC.getCode().equals(strategy.getStrategyType())){
+ AppMonitor app =
+
AlarmStrategyType.TESLA.getCode().equals(strategy.getStrategyType()) ?
appMonitorDao.getByIamTreeId(
+ strategy.getIamId())
+ : appMonitorDao.getMyApp(strategy.getAppId(),
strategy.getIamId(), user, AppViewType.MyApp);
+ if (app == null) {
+ return Result.fail(ErrorCode.NoOperPermission);
+ }
}
Result result =
appAlarmService.deleteRulesByIamId(strategy.getIamId(), strategyId, user);
if (result.getCode() != ErrorCode.success.getCode()) {
@@ -389,6 +406,14 @@ public class AlarmStrategyServiceImpl implements
AlarmStrategyService {
if (deptMap.containsKey(5)) {
strategy.setGroup5(deptMap.get(5).getDeptName());
}
+
+
if(AlarmStrategyType.BUSINESS_METRIC.getCode().equals(param.getStrategyType())){
+ PageData<List<AlarmStrategyInfo>> pageData =
appAlarmStrategyDao.searchByCondNoUser(strategy,
+ param.getPage(), param.getPageSize(), param.getSortBy(),
param.getSortOrder());
+ ruleDataHandler(pageData.getList());
+ return Result.success(pageData);
+ }
+
PageData<List<AlarmStrategyInfo>> pageData =
appAlarmStrategyDao.searchByCond(user, param.isOwner(), strategy,
param.getPage(), param.getPageSize(), param.getSortBy(),
param.getSortOrder());
ruleDataHandler(pageData.getList());
diff --git
a/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/service/impl/AppAlarmServiceImpl.java
b/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/service/impl/AppAlarmServiceImpl.java
index 1e278344..b7bfc865 100644
---
a/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/service/impl/AppAlarmServiceImpl.java
+++
b/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/service/impl/AppAlarmServiceImpl.java
@@ -24,6 +24,7 @@ import com.google.common.collect.Lists;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
+import com.xiaomi.mone.tpc.login.util.GsonUtil;
import org.apache.ozhera.monitor.bo.AlarmCheckDataCount;
import org.apache.ozhera.monitor.bo.AlarmRuleMetricType;
import org.apache.ozhera.monitor.bo.AlarmRuleTemplateType;
@@ -106,7 +107,7 @@ public class AppAlarmServiceImpl implements AppAlarmService
{
@NacosValue("${rule.evaluation.interval:20}")
private Integer evaluationInterval;
-
+
@NacosValue("${rule.evaluation.unit:s}")
private String evaluationUnit;
@@ -322,9 +323,12 @@ public class AppAlarmServiceImpl implements
AppAlarmService {
* 校验当前操作人是否具有权限
*/
AppMonitor app = null;
- if (param.getStrategyType().equals(AlarmStrategyType.TESLA.getCode()))
{
+
if(param.getStrategyType().equals(AlarmStrategyType.BUSINESS_METRIC.getCode())){
+ return appAlarmServiceExtension.createBusinessAlert(param);
+
+ }else if
(param.getStrategyType().equals(AlarmStrategyType.TESLA.getCode())) {
app = appMonitorDao.getByIamTreeId(param.getIamId());
- } else {
+ }else {
app = appMonitorDao.getMyApp(param.getProjectId(),
param.getIamId(), param.getUser(), AppViewType.MyApp);
}
@@ -353,6 +357,10 @@ public class AppAlarmServiceImpl implements
AppAlarmService {
@Override
public Result batchAddRulesWithStrategy(AlarmRuleRequest param) {
+
+
if(param.getStrategyType().equals(AlarmStrategyType.BUSINESS_METRIC.getCode())){
+ return appAlarmServiceExtension.createBusinessAlert(param);
+ }
List<ProjectAlarmInfo> projectsAlarmInfo =
param.getProjectsAlarmInfo();
if (projectsAlarmInfo == null) {
@@ -601,6 +609,11 @@ public class AppAlarmServiceImpl implements
AppAlarmService {
log.error("editAlarmRuleSingle strategy is not exist!ruleData:{}",
ruleData);
return Result.fail(ErrorCode.nonExistentStrategy);
}
+
+
+
if(alarmStrategy.getStrategyType().equals(AlarmStrategyType.BUSINESS_METRIC.getCode())){
+ return
appAlarmServiceExtension.editBusinessAlertSingle(ruleData,user);
+ }
/**
* 校验当前操作人是否具有权限
@@ -637,6 +650,10 @@ public class AppAlarmServiceImpl implements
AppAlarmService {
log.error("editRules no rule data found!param:{}", param);
return Result.fail(ErrorCode.invalidParamError);
}
+
+
if(param.getStrategyType().equals(AlarmStrategyType.BUSINESS_METRIC.getCode())){
+ return appAlarmServiceExtension.editBusinessAlert(param);
+ }
/**
* 校验当前操作人是否具有权限
@@ -874,15 +891,20 @@ public class AppAlarmServiceImpl implements
AppAlarmService {
* 同时暂停远程接口的数据,和本地数据
*/
for (AppAlarmRule rule : delRules) {
+
+ if(rule.getStatus() != 0){
+ log.info("enabledRules the rule is invalid status! it has been
deleted! rule : {}", GsonUtil.gsonString(rule));
+ continue;
+ }
Result result = alarmService.enabledRule(rule.getAlarmId(),
pauseStatus, iamId, user);
if (result.getCode() == 0) {
- AppAlarmRule condition = new AppAlarmRule();
- condition.setIamId(rule.getIamId());
- condition.setStatus(0);
AppAlarmRule value = new AppAlarmRule();
+ value.setId(rule.getId());
value.setRuleStatus(pauseStatus);
+ value.setUpdateTime(new Date());
try {
- int update = appAlarmRuleDao.update(condition, value);
+ int update = appAlarmRuleDao.updateByIdSelective(value);
+ log.info("enabledRules in db, update result : {} ,rule :
{}", update, GsonUtil.gsonString(value));
if (update < 1) {
log.info("AppAlarmService.enabledRules update data
failed!");
return Result.fail(ErrorCode.unknownError);
diff --git
a/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/service/model/prometheus/AlarmRuleRequest.java
b/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/service/model/prometheus/AlarmRuleRequest.java
index c9253e52..2c5aa501 100644
---
a/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/service/model/prometheus/AlarmRuleRequest.java
+++
b/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/service/model/prometheus/AlarmRuleRequest.java
@@ -38,6 +38,7 @@ public class AlarmRuleRequest implements Serializable {
private Integer iamId;
private Integer iamType;
private Integer projectId;
+ private String projectName;
private Integer ruleTemplateId;
private List<ProjectAlarmInfo> projectsAlarmInfo;
@Deprecated
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]