Skip to content

Commit

Permalink
Merge branch 'main' into feat/support_sofatracer1
Browse files Browse the repository at this point in the history
  • Loading branch information
sw1136562366 authored Jul 21, 2023
2 parents f9f7a32 + dd07d8f commit 554ed05
Show file tree
Hide file tree
Showing 22 changed files with 182 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ public interface MetricInfoService extends IService<MetricInfo> {

Map<String, QueryRequest> querySpmList();

List<MetricInfoDTO> getListByKeyword(String keyword, String tenant, String workspace);

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package io.holoinsight.server.common.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.holoinsight.server.common.dao.converter.MetricInfoConverter;
import io.holoinsight.server.common.dao.entity.MetricInfo;
Expand Down Expand Up @@ -148,4 +149,19 @@ public Map<String, QueryRequest> querySpmList() {
});
return map;
}

@Override
public List<MetricInfoDTO> getListByKeyword(String keyword, String tenant, String workspace) {
QueryWrapper<MetricInfo> wrapper = new QueryWrapper<>();
if (StringUtils.isNotBlank(tenant) || "-".equalsIgnoreCase(tenant)) {
wrapper.eq("tenant", tenant);
}
if (StringUtils.isNotBlank(workspace) || "-".equalsIgnoreCase(workspace)) {
wrapper.eq("workspace", workspace);
}

wrapper.like("metric_table", keyword);
wrapper.last("LIMIT 10");
return metricInfoConverter.dosToDTOs(baseMapper.selectList(wrapper));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.holoinsight.server.home.alert.model.event.WebhookInfo;
import io.holoinsight.server.home.alert.service.converter.DoConvert;
import io.holoinsight.server.home.alert.service.event.AlertHandlerExecutor;
import io.holoinsight.server.home.common.service.RequestContextAdapter;
import io.holoinsight.server.home.dal.mapper.AlarmBlockMapper;
import io.holoinsight.server.home.dal.mapper.AlarmDingDingRobotMapper;
import io.holoinsight.server.home.dal.mapper.AlarmGroupMapper;
Expand All @@ -27,6 +28,7 @@
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

Expand All @@ -39,7 +41,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -71,6 +72,9 @@ public class GetSubscriptionHandler implements AlertHandlerExecutor {
@Resource
private AlarmBlockMapper alarmBlockDOMapper;

@Autowired
private RequestContextAdapter requestContextAdapter;

@Override
public void handle(List<AlertNotify> alertNotifies) {
try {
Expand Down Expand Up @@ -147,7 +151,8 @@ public void handle(List<AlertNotify> alertNotifies) {
QueryWrapper<AlarmSubscribe> alertSubscribeQueryWrapper = new QueryWrapper<>();
alertSubscribeQueryWrapper.eq("unique_id", alertNotify.getUniqueId());
alertSubscribeQueryWrapper.eq("status", (byte) 1);
alertSubscribeQueryWrapper.eq("tenant", alertNotify.getTenant());
requestContextAdapter.queryWrapperTenantAdapt(alertSubscribeQueryWrapper, null,
alertNotify.getWorkspace());
addGlobalWebhook(alertNotify, alertWebhookMap);
List<AlarmSubscribe> alertSubscribeList =
alarmSubscribeDOMapper.selectList(alertSubscribeQueryWrapper);
Expand Down Expand Up @@ -175,7 +180,6 @@ public void handle(List<AlertNotify> alertNotifies) {
if (isNotifyGroup(alertSubscribe.getGroupId())) {
QueryWrapper<AlarmGroup> wrapper = new QueryWrapper<>();
wrapper.eq("id", alertSubscribe.getGroupId());
wrapper.eq("tenant", alertNotify.getTenant());
AlarmGroup alarmGroup = alarmGroupDOMapper.selectOne(wrapper);
Map<String, List<String>> map =
G.get().fromJson(alarmGroup.getGroupInfo(), Map.class);
Expand All @@ -197,7 +201,6 @@ public void handle(List<AlertNotify> alertNotifies) {
if (isNotifyGroup(alertSubscribe.getGroupId())) {
QueryWrapper<AlarmGroup> wrapper = new QueryWrapper<>();
wrapper.eq("id", alertSubscribe.getGroupId());
wrapper.eq("tenant", alertNotify.getTenant());
AlarmGroup alarmGroup = alarmGroupDOMapper.selectOne(wrapper);
if (StringUtils.isNotBlank(alarmGroup.getGroupInfo())) {
Map<String, List<String>> map =
Expand Down Expand Up @@ -235,7 +238,6 @@ public void handle(List<AlertNotify> alertNotifies) {
if (!CollectionUtils.isEmpty(dingDingGroupIdList)) {
QueryWrapper<AlarmDingDingRobot> wrapper = new QueryWrapper<>();
wrapper.in("id", new ArrayList<>(dingDingGroupIdList));
wrapper.eq("tenant", alertNotify.getTenant());
List<AlarmDingDingRobot> alertDingDingRobotList =
alarmDingDingRobotDOMapper.selectList(wrapper);
List<WebhookInfo> dingdingUrls = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ protected TriggerResult doInvoke(DataResult dataResult, FunctionConfigParam func

long delta = getDelta(functionConfigParam.getPeriodType());
Map<Long, Double> points = dataResult.getPoints();
result.setCurrentValue(points.get(functionConfigParam.getPeriod()));
Double currentValue = points.get(functionConfigParam.getPeriod());
if (currentValue == null && functionConfigParam.isZeroFill()) {
currentValue = 0d;
}
result.setCurrentValue(currentValue);
long duration = functionConfigParam.getDuration();
for (long i = 0; i < duration; i++) {
long time = functionConfigParam.getPeriod() - i * 60000L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public interface RequestContextAdapter {

QueryProto.PqlRangeRequest requestAdapte(QueryProto.PqlRangeRequest request);

<T> void queryWrapperTenantAdapte(QueryWrapper<T> queryWrapper, String tenant, String workspace);
<T> void queryWrapperTenantAdapt(QueryWrapper<T> queryWrapper, String tenant, String workspace);

String getWorkspace(boolean cross);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
package io.holoinsight.server.home.common.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.holoinsight.server.home.common.util.scope.MonitorCookieUtil;
import io.holoinsight.server.home.common.util.scope.MonitorScope;
import io.holoinsight.server.home.common.util.scope.RequestContext;
import io.holoinsight.server.query.grpc.QueryProto;
import org.apache.commons.lang3.StringUtils;

Expand All @@ -25,7 +28,7 @@ public QueryProto.PqlRangeRequest requestAdapte(QueryProto.PqlRangeRequest reque
}

@Override
public <T> void queryWrapperTenantAdapte(QueryWrapper<T> queryWrapper, String tenant,
public <T> void queryWrapperTenantAdapt(QueryWrapper<T> queryWrapper, String tenant,
String workspace) {
if (queryWrapper != null) {
if (StringUtils.isNotBlank(tenant)) {
Expand All @@ -36,4 +39,10 @@ public <T> void queryWrapperTenantAdapte(QueryWrapper<T> queryWrapper, String te
}
}
}

@Override
public String getWorkspace(boolean cross) {
MonitorScope ms = RequestContext.getContext().ms;
return ms.getWorkspace();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
package io.holoinsight.server.home.biz.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import io.holoinsight.server.home.dal.model.AlarmSubscribe;
import io.holoinsight.server.home.dal.model.dto.AlarmSubscribeDTO;
Expand All @@ -21,9 +22,9 @@ public interface AlertSubscribeService extends IService<AlarmSubscribe> {
Boolean saveDataBatch(AlarmSubscribeDTO alarmSubscribeDTO, String creator, String tenant,
String workspace);

AlarmSubscribeDTO queryByUniqueId(Map<String, Object> columnMap);
AlarmSubscribeDTO queryByUniqueId(QueryWrapper<AlarmSubscribe> queryWrapper, String uniqueId);

List<AlarmSubscribeInfo> queryByMap(Map<String, Object> columnMap);
List<AlarmSubscribeInfo> queryByMap(QueryWrapper<AlarmSubscribe> queryWrapper);

Long save(AlarmSubscribeInfo alarmSubscribeInfo);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public MonitorPageResult<AlarmHistoryDetailDTO> getListByPage(
wrapper.eq("alarm_time", alarmHistoryDetail.getAlarmTime());
}

this.requestContextAdapter.queryWrapperTenantAdapte(wrapper,
this.requestContextAdapter.queryWrapperTenantAdapt(wrapper,
alarmHistoryDetail.getTenant().trim(), alarmHistoryDetail.getWorkspace());

if (null != pageRequest.getFrom()) {
Expand Down Expand Up @@ -105,7 +105,7 @@ public List<Map<String, Object>> count(MonitorPageRequest<AlarmHistoryDetailDTO>
if (StringUtils.isNotBlank(target.getUniqueId())) {
queryWrapper.eq("unique_id", target.getUniqueId());
}
this.requestContextAdapter.queryWrapperTenantAdapte(queryWrapper, target.getTenant(),
this.requestContextAdapter.queryWrapperTenantAdapt(queryWrapper, target.getTenant(),
target.getWorkspace());

queryWrapper.between("gmt_create",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
Expand All @@ -38,7 +37,7 @@ public class AlarmHistoryServiceImpl extends ServiceImpl<AlarmHistoryMapper, Ala
public AlarmHistoryDTO queryById(Long id, String tenant, String workspace) {

QueryWrapper<AlarmHistory> wrapper = new QueryWrapper<>();
this.requestContextAdapter.queryWrapperTenantAdapte(wrapper, tenant, workspace);
this.requestContextAdapter.queryWrapperTenantAdapt(wrapper, tenant, workspace);

wrapper.eq("id", id);
wrapper.last("LIMIT 1");
Expand All @@ -61,7 +60,7 @@ public MonitorPageResult<AlarmHistoryDTO> getListByPage(
wrapper.eq("id", alarmHistory.getId());
}

this.requestContextAdapter.queryWrapperTenantAdapte(wrapper, alarmHistory.getTenant(),
this.requestContextAdapter.queryWrapperTenantAdapt(wrapper, alarmHistory.getTenant(),
alarmHistory.getWorkspace());

if (null != alarmHistory.getUniqueId()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.holoinsight.server.home.biz.service.AlertDingDingRobotService;
import io.holoinsight.server.home.common.service.RequestContextAdapter;
import io.holoinsight.server.home.common.util.StringUtil;
import io.holoinsight.server.home.dal.converter.AlarmDingDingRobotConverter;
import io.holoinsight.server.home.dal.mapper.AlarmDingDingRobotMapper;
import io.holoinsight.server.home.dal.model.AlarmDingDingRobot;
import io.holoinsight.server.home.dal.model.dto.AlarmDingDingRobotDTO;
import io.holoinsight.server.home.facade.page.MonitorPageRequest;
import io.holoinsight.server.home.facade.page.MonitorPageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
Expand All @@ -31,6 +33,9 @@ public class AlertDingDingRobotServiceImpl extends
@Resource
private AlarmDingDingRobotConverter alarmDingDingRobotConverter;

@Autowired
private RequestContextAdapter requestContextAdapter;

@Override
public Long save(AlarmDingDingRobotDTO alarmDingDingRobotDTO) {
AlarmDingDingRobot alarmDingDingRobot =
Expand All @@ -49,7 +54,8 @@ public Boolean updateById(AlarmDingDingRobotDTO alarmDingDingRobotDTO) {
@Override
public AlarmDingDingRobotDTO queryById(Long id, String tenant) {
QueryWrapper<AlarmDingDingRobot> wrapper = new QueryWrapper<>();
wrapper.eq("tenant", tenant);
requestContextAdapter.queryWrapperTenantAdapt(wrapper, tenant,
requestContextAdapter.getWorkspace(true));
wrapper.eq("id", id);
wrapper.last("LIMIT 1");
AlarmDingDingRobot alarmDingDingRobot = this.getOne(wrapper);
Expand All @@ -68,14 +74,13 @@ public MonitorPageResult<AlarmDingDingRobotDTO> getListByPage(
AlarmDingDingRobot alarmDingDingRobot =
alarmDingDingRobotConverter.dtoToDO(pageRequest.getTarget());

this.requestContextAdapter.queryWrapperTenantAdapt(wrapper, alarmDingDingRobot.getTenant(),
alarmDingDingRobot.getWorkspace());

if (null != alarmDingDingRobot.getId()) {
wrapper.eq("id", alarmDingDingRobot.getId());
}

if (StringUtil.isNotBlank(alarmDingDingRobot.getTenant())) {
wrapper.eq("tenant", alarmDingDingRobot.getTenant().trim());
}

if (StringUtil.isNotBlank(alarmDingDingRobot.getGroupName())) {
wrapper.like("group_name", alarmDingDingRobot.getGroupName().trim());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.holoinsight.server.home.biz.service.AlertGroupService;
import io.holoinsight.server.home.common.service.RequestContextAdapter;
import io.holoinsight.server.home.dal.converter.AlarmGroupConverter;
import io.holoinsight.server.home.dal.mapper.AlarmGroupMapper;
import io.holoinsight.server.home.dal.model.AlarmGroup;
import io.holoinsight.server.home.dal.model.dto.AlarmGroupDTO;
import io.holoinsight.server.home.facade.page.MonitorPageRequest;
import io.holoinsight.server.home.facade.page.MonitorPageResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
Expand All @@ -26,6 +28,9 @@ public class AlertGroupServiceImpl extends ServiceImpl<AlarmGroupMapper, AlarmGr
@Resource
private AlarmGroupConverter alarmGroupConverter;

@Autowired
private RequestContextAdapter requestContextAdapter;

@Override
public Long save(AlarmGroupDTO alarmGroupDTO) {
AlarmGroup alarmGroup = alarmGroupConverter.dtoToDO(alarmGroupDTO);
Expand All @@ -42,7 +47,8 @@ public Boolean updateById(AlarmGroupDTO alarmGroupDTO) {
@Override
public AlarmGroupDTO queryById(Long id, String tenant) {
QueryWrapper<AlarmGroup> wrapper = new QueryWrapper<>();
wrapper.eq("tenant", tenant);
requestContextAdapter.queryWrapperTenantAdapt(wrapper, tenant,
requestContextAdapter.getWorkspace(true));
wrapper.eq("id", id);
wrapper.last("LIMIT 1");
AlarmGroup alarmGroup = this.getOne(wrapper);
Expand All @@ -67,29 +73,28 @@ public MonitorPageResult<AlarmGroupDTO> getListByPage(

QueryWrapper<AlarmGroup> wrapper = new QueryWrapper<>();

AlarmGroup alarmHistory = alarmGroupConverter.dtoToDO(pageRequest.getTarget());
AlarmGroup alarmGroup = alarmGroupConverter.dtoToDO(pageRequest.getTarget());

if (null != alarmHistory.getId()) {
wrapper.eq("id", alarmHistory.getId());
}
this.requestContextAdapter.queryWrapperTenantAdapt(wrapper, alarmGroup.getTenant(),
alarmGroup.getWorkspace());

if (StringUtils.isNotBlank(alarmHistory.getTenant())) {
wrapper.eq("tenant", alarmHistory.getTenant().trim());
if (null != alarmGroup.getId()) {
wrapper.eq("id", alarmGroup.getId());
}

if (null != alarmHistory.getEnvType()) {
wrapper.eq("env_type", alarmHistory.getEnvType());
if (null != alarmGroup.getEnvType()) {
wrapper.eq("env_type", alarmGroup.getEnvType());
}

if (StringUtils.isNotBlank(alarmHistory.getGroupName())) {
wrapper.like("group_name", alarmHistory.getGroupName().trim());
if (StringUtils.isNotBlank(alarmGroup.getGroupName())) {
wrapper.like("group_name", alarmGroup.getGroupName().trim());
}

if (StringUtils.isNotBlank(alarmHistory.getCreator())) {
wrapper.like("creator", alarmHistory.getCreator().trim());
if (StringUtils.isNotBlank(alarmGroup.getCreator())) {
wrapper.like("creator", alarmGroup.getCreator().trim());
}
if (StringUtils.isNotBlank(alarmHistory.getModifier())) {
wrapper.like("modifier", alarmHistory.getModifier().trim());
if (StringUtils.isNotBlank(alarmGroup.getModifier())) {
wrapper.like("modifier", alarmGroup.getModifier().trim());
}

wrapper.orderByDesc("id");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public Boolean deleteById(Long id) {
@Override
public AlarmRuleDTO queryById(Long id, String tenant, String workspace) {
QueryWrapper<AlarmRule> wrapper = new QueryWrapper<>();
this.requestContextAdapter.queryWrapperTenantAdapte(wrapper, tenant, workspace);
this.requestContextAdapter.queryWrapperTenantAdapt(wrapper, tenant, workspace);

wrapper.eq("id", id);
wrapper.last("LIMIT 1");
Expand All @@ -100,7 +100,7 @@ public MonitorPageResult<AlarmRuleDTO> getListByPage(
wrapper.eq("id", alarmRule.getId());
}

this.requestContextAdapter.queryWrapperTenantAdapte(wrapper, alarmRule.getTenant(),
this.requestContextAdapter.queryWrapperTenantAdapt(wrapper, alarmRule.getTenant(),
alarmRule.getWorkspace());

if (null != alarmRule.getStatus()) {
Expand Down Expand Up @@ -223,7 +223,7 @@ protected void setAlarmContent(AlarmRuleDTO alarmRuleDTO) {
@Override
public List<AlarmRuleDTO> getListByKeyword(String keyword, String tenant, String workspace) {
QueryWrapper<AlarmRule> wrapper = new QueryWrapper<>();
this.requestContextAdapter.queryWrapperTenantAdapte(wrapper, tenant, workspace);
this.requestContextAdapter.queryWrapperTenantAdapt(wrapper, tenant, workspace);

wrapper.like("id", keyword).or().like("rule_name", keyword);
wrapper.last("LIMIT 10");
Expand Down
Loading

0 comments on commit 554ed05

Please sign in to comment.