Skip to content

Commit

Permalink
alarm support Ding Talk user (#108)
Browse files Browse the repository at this point in the history
* alarm config support new user type

* alarm user support more login type

---------

Co-authored-by: gaoxihui <[email protected]>
  • Loading branch information
gaoxh and gaoxihui authored Oct 30, 2023
1 parent c4d1d98 commit 1c19659
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 55 deletions.
2 changes: 1 addition & 1 deletion ozhera-app/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# ozhear-app
# ozhera-app
Ozhera-app is a microservice that manages the basic data of monitoring applications and is the data service center of the entire ozhera monitoring system.
Provides unified application data for link tracing, logs, and metric monitoring, and manages global configuration information.
2 changes: 1 addition & 1 deletion ozhera-monitor/ozhera-monitor-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<dependency>
<artifactId>mi-tpc-api</artifactId>
<groupId>run.mone</groupId>
<version>1.0.0-SNAPSHOT</version>
<version>1.0.1-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public class UserInfo {
private String cname;
private String email;
private Integer type;
private String showAccount;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.xiaomi.mone.monitor.dao.model.AppMonitor;
import com.xiaomi.mone.monitor.service.model.prometheus.AlarmRuleData;

import java.util.Map;

/**
* @author gaoxihui
* @date 2023/10/6 11:38 上午
Expand All @@ -15,4 +17,6 @@ public interface AlarmExprService {
public String getContainerCpuResourceAlarmExpr(Integer projectId,String projectName,String op,double value,boolean isK8s,AlarmRuleData ruleData);

public String getContainerMemReourceAlarmExpr(Integer projectId,String projectName,String op,double value,boolean isK8s,AlarmRuleData ruleData);

public Map getEnvIpMapping(Integer projectId, String projectName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ public Map getEnvIpMapping(Integer projectId, String projectName){
Set allIps = new HashSet();
for(Metric metric : metrics){

allIps.add(metric.getServerIp());
allIps.add(metric.getPodIp());

if(StringUtils.isBlank(metric.getServerEnv())){
continue;
Expand All @@ -912,20 +912,20 @@ public Map getEnvIpMapping(Integer projectId, String projectName){

stringObjectMap.putIfAbsent("envIps", new HashSet<>());
HashSet ipList = (HashSet<String>)stringObjectMap.get("envIps");
ipList.add(metric.getServerIp());
ipList.add(metric.getPodIp());

if(StringUtils.isNotBlank(metric.getServerZone())){
allZones.putIfAbsent(metric.getServerZone(),new HashSet<String>());
HashSet<String> zoneIps = allZones.get(metric.getServerZone());
zoneIps.add(metric.getServerIp());
zoneIps.add(metric.getPodIp());

stringObjectMap.putIfAbsent("zoneList", new HashMap<>());
HashMap serviceList = (HashMap<String,Set<String>>)stringObjectMap.get("zoneList");

serviceList.putIfAbsent(metric.getServerZone(), new HashSet<String>());
HashSet<String> ips = (HashSet<String>)serviceList.get(metric.getServerZone());

ips.add(metric.getServerIp());
ips.add(metric.getPodIp());
}
}

Expand All @@ -941,7 +941,7 @@ private List<Metric> listInstanceMetric(Integer projectId,String projectName){
projectName = projectName.replaceAll("-","_");

StringBuilder builder = new StringBuilder();
builder.append("process_uptime_seconds{application=\"")
builder.append("container_last_seen{application=\"")
.append(projectId).append("_").append(projectName)
.append("\"").append("}");
Result<PageData> pageDataResult = prometheusService.queryByMetric(builder.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ public Result<PageData<List<UserInfo>>> searchUser(String user, String searchNam

AuthUserVo userVoSearch = UserUtil.parseFullAccount(searchName);
param.setUserAcc(userVoSearch == null ? null : userVoSearch.getAccount());
//暂时只支持邮箱账号
param.setType(UserTypeEnum.EMAIL.getCode());
// param.setType(UserTypeEnum.EMAIL.getCode());
com.xiaomi.youpin.infra.rpc.Result<PageDataVo<UserVo>> userResult = userFacade.list(param);
log.info("userFacade reqeust param:{},result:{}",gson.toJson(param),gson.toJson(userResult));
if (userResult == null || userResult.getData() == null || CollectionUtils.isEmpty(userResult.getData().getList())) {
Expand All @@ -197,6 +196,7 @@ public Result<PageData<List<UserInfo>>> searchUser(String user, String searchNam
StringBuilder cname = new StringBuilder();
cname.append(vo.getAccount()).append("(").append(UserTypeEnum.getEnum(vo.getType()).getDesc()).append(")");
userInfo.setCname(cname.toString());
userInfo.setShowAccount(vo.getShowAccount());
userInfos.add(userInfo);
});
page.setList(userInfos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class Metric implements Serializable {
private String container;//
private String containerName;
private String pod;//
private String podIp;//
private String namespace;//

private String lastCreateTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,52 +111,7 @@ public List<String> getInstanceIpList(Integer projectId, String projectName){
}

public Map getEnvIpMapping(Integer projectId, String projectName){

List<Metric> metrics = listInstanceMetric(projectId, projectName);
if(CollectionUtils.isEmpty(metrics)){
log.error("getEnvIpMapping no data found! projectId :{},projectName:{}",projectId,projectName);
return null;
}


Map result = new HashMap();
Map<String,Map<String,Object>> mapResult = new HashMap<>();
Map<String, HashSet<String>> allZones = new HashMap<>();
Set allIps = new HashSet();
for(Metric metric : metrics){

allIps.add(metric.getServerIp());

if(StringUtils.isBlank(metric.getServerEnv())){
continue;
}
mapResult.putIfAbsent(metric.getServerEnv(),new HashMap<>());
Map<String, Object> stringObjectMap = mapResult.get(metric.getServerEnv());

stringObjectMap.putIfAbsent("envIps", new HashSet<>());
HashSet ipList = (HashSet<String>)stringObjectMap.get("envIps");
ipList.add(metric.getServerIp());

if(StringUtils.isNotBlank(metric.getServerZone())){
allZones.putIfAbsent(metric.getServerZone(),new HashSet<String>());
HashSet<String> zoneIps = allZones.get(metric.getServerZone());
zoneIps.add(metric.getServerIp());

stringObjectMap.putIfAbsent("zoneList", new HashMap<>());
HashMap serviceList = (HashMap<String,Set<String>>)stringObjectMap.get("zoneList");

serviceList.putIfAbsent(metric.getServerZone(), new HashSet<String>());
HashSet<String> ips = (HashSet<String>)serviceList.get(metric.getServerZone());

ips.add(metric.getServerIp());
}
}

result.put("allIps",allIps);
result.put("envIpMapping",mapResult);
result.put("allZones",allZones);

return result;
return alarmExprService.getEnvIpMapping(projectId,projectName);
}


Expand Down

0 comments on commit 1c19659

Please sign in to comment.