Skip to content

Commit

Permalink
fix: workspace and tenant (#827)
Browse files Browse the repository at this point in the history
  • Loading branch information
masaimu authored Mar 28, 2024
1 parent d251dcc commit deee523
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void loadData(ComputeTaskPackage computeTaskPackage) {
alarmLoadData.queryDataResult(computeTaskPackage, inspectConfig, trigger);
trigger.setDataResult(dataResults);
} catch (Exception exception) {
LOGGER.error("AlarmLoadData Exception", exception);
LOGGER.error("{} AlarmLoadData Exception", inspectConfig.getTraceId(), exception);
RecordSucOrFailNotify.alertNotifyProcessFail("alarm load data Exception: " + exception,
ALERT_TASK_COMPUTE, "alarm load data", inspectConfig.getAlertNotifyRecord());
notifySuccess = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ public List<DataResult> queryDataResult(ComputeTaskPackage computeTask,
dataResults = merge(dataResults, deltaResponse);
}
} catch (Exception exception) {
LOGGER.error("QueryData Exception Request:{} Response:{} DeltaRequest:{} DeltaResponse: {}",
G.get().toJson(request), G.get().toJson(response), G.get().toJson(deltaRequest),
G.get().toJson(deltaResponse), exception);
LOGGER.error(
"{} QueryData Exception Request:{} Response:{} DeltaRequest:{} DeltaResponse: {}",
inspectConfig.getTraceId(), G.get().toJson(request), G.get().toJson(response),
G.get().toJson(deltaRequest), G.get().toJson(deltaResponse), exception);
}
return dataResults;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class DataSource implements Serializable {

private String downsample; // 时间窗口

private String name; // 代称 (a、b)
private String name = "a"; // 代称 (a、b)

private List<Filter> filters; // 维度筛选

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Trigger {

private List<DataSource> datasources;

private String query;
private String query = "a";

private String aggregator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -74,8 +75,10 @@ public MonitorPageResult<AlarmDingDingRobotDTO> getListByPage(
AlarmDingDingRobot alarmDingDingRobot =
alarmDingDingRobotConverter.dtoToDO(pageRequest.getTarget());

this.requestContextAdapter.queryWrapperTenantAdapt(wrapper, alarmDingDingRobot.getTenant(),
alarmDingDingRobot.getWorkspace());
wrapper.eq("tenant", alarmDingDingRobot.getTenant());
if (StringUtils.isNotEmpty(alarmDingDingRobot.getWorkspace())) {
wrapper.eq("workspace", alarmDingDingRobot.getWorkspace());
}

if (null != alarmDingDingRobot.getId()) {
wrapper.eq("id", alarmDingDingRobot.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@
*/
package io.holoinsight.server.home.web.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.holoinsight.server.common.JsonResult;
import io.holoinsight.server.home.biz.service.AlertSubscribeService;
import io.holoinsight.server.home.biz.ula.ULAFacade;
import io.holoinsight.server.home.common.service.RequestContextAdapter;
import io.holoinsight.server.home.common.util.ManageCallback;
import io.holoinsight.server.home.common.util.MonitorException;
import io.holoinsight.server.home.common.util.ResultCodeEnum;
import io.holoinsight.server.home.common.util.scope.AuthTargetType;
import io.holoinsight.server.home.common.util.scope.MonitorScope;
import io.holoinsight.server.home.common.util.scope.MonitorUser;
import io.holoinsight.server.home.common.util.scope.PowerConstants;
import io.holoinsight.server.home.common.util.scope.RequestContext;
import io.holoinsight.server.home.dal.model.AlarmSubscribe;
import io.holoinsight.server.home.dal.model.dto.AlarmSubscribeDTO;
import io.holoinsight.server.home.dal.model.dto.AlarmSubscribeInfo;
import io.holoinsight.server.home.web.common.ParaCheckUtil;
import io.holoinsight.server.home.web.interceptor.MonitorScopeAuth;
import io.holoinsight.server.home.web.security.ParameterSecurityService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -26,18 +34,9 @@
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import io.holoinsight.server.common.JsonResult;
import io.holoinsight.server.home.biz.service.AlertSubscribeService;
import io.holoinsight.server.home.biz.ula.ULAFacade;
import io.holoinsight.server.home.common.util.scope.AuthTargetType;
import io.holoinsight.server.home.common.util.scope.MonitorScope;
import io.holoinsight.server.home.common.util.scope.MonitorUser;
import io.holoinsight.server.home.common.util.scope.PowerConstants;
import io.holoinsight.server.home.common.util.scope.RequestContext;
import io.holoinsight.server.home.dal.model.dto.AlarmSubscribeDTO;
import io.holoinsight.server.home.common.util.ManageCallback;
import io.holoinsight.server.home.web.common.ParaCheckUtil;
import io.holoinsight.server.home.web.interceptor.MonitorScopeAuth;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
* @author wangsiyuan
Expand Down Expand Up @@ -108,16 +107,17 @@ public void checkParameter() {
if (StringUtils.isNotEmpty(alarmSubscribeDTO.getUniqueId())) {
ParaCheckUtil.checkParaBoolean(
parameterSecurityService.checkRuleTenantAndWorkspace(alarmSubscribeDTO.getUniqueId(),
ms.getTenant(), ms.getWorkspace()),
"uniqueId do not belong to this tenant or workspace");
tenant(), workspace()),
"uniqueId do not belong to this tenant " + tenant() + " or workspace " + workspace());
}
if (!CollectionUtils.isEmpty(alarmSubscribeDTO.getAlarmSubscribe())) {
for (AlarmSubscribeInfo alarmSubscribeInfo : alarmSubscribeDTO.getAlarmSubscribe()) {
if (StringUtils.isNotEmpty(alarmSubscribeInfo.getUniqueId())) {
ParaCheckUtil.checkParaBoolean(
parameterSecurityService.checkRuleTenantAndWorkspace(
alarmSubscribeInfo.getUniqueId(), ms.getTenant(), ms.getWorkspace()),
"uniqueId do not belong to this tenant or workspace");
alarmSubscribeInfo.getUniqueId(), tenant(), workspace()),
"uniqueId do not belong to this tenant " + tenant() + " or workspace "
+ workspace());
}
if (CollectionUtils.isEmpty(alarmSubscribeInfo.getNoticeType())) {
continue;
Expand Down Expand Up @@ -147,18 +147,13 @@ public void checkParameter() {

@Override
public void doManage() {
MonitorScope ms = RequestContext.getContext().ms;
MonitorUser mu = RequestContext.getContext().mu;
String creator = null;
String tenant = null;
if (null != mu) {
creator = mu.getLoginName();
}
if (null != ms && !StringUtils.isEmpty(ms.tenant)) {
tenant = ms.tenant;
}
boolean rtn =
alarmSubscribeService.saveDataBatch(alarmSubscribeDTO, creator, tenant, ms.workspace);
alarmSubscribeService.saveDataBatch(alarmSubscribeDTO, creator, tenant(), workspace());
JsonResult.createSuccessResult(result, rtn);
}
});
Expand All @@ -178,11 +173,9 @@ public void checkParameter() {

@Override
public void doManage() {
MonitorScope ms = RequestContext.getContext().ms;
QueryWrapper<AlarmSubscribe> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("unique_id", uniqueId);
requestContextAdapter.queryWrapperTenantAdapt(queryWrapper, ms.getTenant(),
ms.getWorkspace());
requestContextAdapter.queryWrapperTenantAdapt(queryWrapper, tenant(), workspace());
AlarmSubscribeDTO alarmSubscribeDTO =
alarmSubscribeService.queryByUniqueId(queryWrapper, uniqueId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
import io.holoinsight.server.common.service.MetricInfoService;
import io.holoinsight.server.home.biz.plugin.MetricInfoCheckService;
import io.holoinsight.server.home.biz.service.IntegrationProductService;
import io.holoinsight.server.home.common.util.ManageCallback;
import io.holoinsight.server.home.common.util.scope.AuthTargetType;
import io.holoinsight.server.home.common.util.scope.MonitorScope;
import io.holoinsight.server.home.common.util.scope.PowerConstants;
import io.holoinsight.server.home.common.util.scope.RequestContext;
import io.holoinsight.server.home.dal.model.dto.IntegrationProductDTO;
import io.holoinsight.server.home.task.MetricCrawlerConstant;
import io.holoinsight.server.home.common.util.ManageCallback;
import io.holoinsight.server.home.web.common.ParaCheckUtil;
import io.holoinsight.server.home.web.interceptor.MonitorScopeAuth;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -75,9 +73,8 @@ public void checkParameter() {

@Override
public void doManage() {
MonitorScope ms = RequestContext.getContext().ms;
JsonResult.createSuccessResult(result, metricInfoCheckService
.queryMetricInfoByMetricType(ms.getTenant(), ms.getWorkspace(), product.toLowerCase()));
.queryMetricInfoByMetricType(tenant(), workspace(), product.toLowerCase()));
}
});
return result;
Expand All @@ -97,7 +94,6 @@ public void checkParameter() {
public void doManage() {

List<MetricInfoDTO> metricInfoDTOS = new ArrayList<>();
MonitorScope ms = RequestContext.getContext().ms;
List<MetricInfoDTO> globalMetrics = metricInfoService.queryListByTenant(
MetricCrawlerConstant.GLOBAL_TENANT, MetricCrawlerConstant.GLOBAL_WORKSPACE);

Expand All @@ -106,7 +102,7 @@ public void doManage() {
}

List<MetricInfoDTO> tenantMetrics =
metricInfoService.queryListByTenant(ms.getTenant(), ms.getWorkspace());
metricInfoService.queryListByTenant(tenant(), workspace());

if (CollectionUtils.isEmpty(tenantMetrics)) {
metricInfoDTOS.addAll(tenantMetrics);
Expand All @@ -130,9 +126,8 @@ public void checkParameter() {

@Override
public void doManage() {
MonitorScope ms = RequestContext.getContext().ms;
MetricInfoDTO metricInfoDTO =
metricInfoService.queryByMetric(ms.getTenant(), ms.getWorkspace(), metric);
metricInfoService.queryByMetric(tenant(), workspace(), metric);
JsonResult.createSuccessResult(result, metricInfoDTO);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ private LevelAuthorizationCheckResult checkRule(Map<String, Object> ruleMap, Str
}

if (StringUtils.isNotEmpty(trigger.getTriggerContent())
&& !checkSqlName(trigger.getTriggerContent())) {
&& !sqlCnNameCheck(trigger.getTriggerContent())) {
return failCheckResult("fail to check triggerContent %s", trigger.getTriggerContent());
}

Expand Down

0 comments on commit deee523

Please sign in to comment.