Skip to content

Commit

Permalink
refactor(home): optimize tenantInitService (#582)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsy1001de authored Aug 2, 2023
1 parent 42e8ca2 commit 0d17138
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class CacheConst {

public static final String USER_CACHE_KEY = "user_cache_key";
public static final String APP_META_KEY = "app_meta_key";
public static final String TENANT_USER_META_KEY = "tenant_user_meta_key";
public static final String TENANT_MEMBER_META_KEY = "tenant_member_meta_key";
public static final String INTEGRATION_GENERATED_CACHE_KEY = "integration_generated_cache_key";
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.holoinsight.server.home.dal.model.dto.IntegrationGeneratedDTO;
import io.holoinsight.server.home.dal.model.dto.IntegrationPluginDTO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

Expand All @@ -27,7 +28,10 @@
* @version 1.0: IntegrationGeneratedUpdateListener.java, Date: 2023-07-26 Time: 10:57
*/
@Component
public class IntegrationGeneratedUpdateListener extends IntegrationPluginUpdateListener {
public class IntegrationGeneratedUpdateListener {

@Autowired
private IntegrationPluginUpdateListener integrationPluginUpdateListener;

@PostConstruct
void register() {
Expand All @@ -44,7 +48,7 @@ public void onEvent(IntegrationGeneratedDTO integrationGeneratedDTO) {
if (StringUtils.isBlank(integrationPluginDTO.json)
|| StringUtils.isBlank(integrationPluginDTO.type))
return;
List<Long> upsert = upsertGaea(integrationPluginDTO);
List<Long> upsert = integrationPluginUpdateListener.upsertGaea(integrationPluginDTO);
notify(upsert);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,11 @@ public List<PortCheckPlugin> genPluginList(IntegrationPluginDTO integrationPlugi
portCheckPlugin.gaeaTableName = integrationPluginDTO.name + "_" + i++;

portCheckPlugin.collectRange =
tenantInitService.getCollectMonitorRange(integrationPluginDTO.getTenant() + "_server",
integrationPluginDTO.getWorkspace(), config.range, config.getMetaLabel());
tenantInitService.getCollectMonitorRange(
tenantInitService.getTenantServerTable(
integrationPluginDTO.getTenant() + "_server"),
integrationPluginDTO.getTenant(), integrationPluginDTO.getWorkspace(), config.range,
config.getMetaLabel());

portCheckPlugin.portCheckTask = portCheckTask;
portCheckPlugin.collectPlugin = "dialcheck";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public interface TenantInitService {
*/
String getTsdbTenant(String tenant);

Boolean checkConditions(String workspace, String metric, List<QueryFilter> filters);
Boolean checkConditions(String tenant, String workspace, String metric,
List<QueryFilter> filters);


/**
Expand All @@ -69,15 +70,15 @@ public interface TenantInitService {
* @param workspace
* @return
*/
Map<String, String> getTenantWorkspaceMetaConditions(String workspace);
Map<String, String> getTenantWorkspaceMetaConditions(String tenant, String workspace);

/**
* add query filters by workspace
*
* @param workspace
* @return
*/
List<QueryFilter> getTenantFilters(String workspace);
List<QueryFilter> getTenantFilters(String tenant, String workspace);

/**
* logmonitor metric table
Expand All @@ -88,8 +89,8 @@ public interface TenantInitService {
String getLogMonitorMetricTable(String tableName);


CloudMonitorRange getCollectMonitorRange(String table, String workspace, List<String> strings,
MetaLabel metaLabel);
CloudMonitorRange getCollectMonitorRange(String table, String tenant, String workspace,
List<String> strings, MetaLabel metaLabel);

Boolean checkCookie(String tenant, String workspace);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ private Map<String, Object> getDimByRequest(AgentParamRequest agentParamRequest,
}


Map<String, String> conditions = tenantInitService.getTenantWorkspaceMetaConditions(workspace);
Map<String, String> conditions =
tenantInitService.getTenantWorkspaceMetaConditions(tenant, workspace);
if (!CollectionUtils.isEmpty(conditions)) {
queryExample.getParams().putAll(conditions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,18 @@ public String getTsdbTenant(String tenant) {
}

@Override
public Boolean checkConditions(String workspace, String metric, List<QueryFilter> filters) {
public Boolean checkConditions(String tenant, String workspace, String metric,
List<QueryFilter> filters) {
return true;
}

@Override
public Map<String, String> getTenantWorkspaceMetaConditions(String workspace) {
public Map<String, String> getTenantWorkspaceMetaConditions(String tenant, String workspace) {
return new HashMap<>();
}

@Override
public List<QueryFilter> getTenantFilters(String workspace) {
public List<QueryFilter> getTenantFilters(String tenant, String workspace) {
return new ArrayList<>();
}

Expand All @@ -73,7 +74,7 @@ public String getLogMonitorMetricTable(String tableName) {
}

@Override
public CloudMonitorRange getCollectMonitorRange(String table, String workspace,
public CloudMonitorRange getCollectMonitorRange(String table, String tenant, String workspace,
List<String> strings, MetaLabel metaLabel) {
return GaeaConvertUtil.convertCloudMonitorRange(table, metaLabel, strings);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,7 @@ public IntegrationPluginDTO create(IntegrationPluginDTO integrationPluginDTO) {
IntegrationPlugin model = integrationPluginConverter.dtoToDO(integrationPluginDTO);
save(model);
IntegrationPluginDTO integrationPlugin = integrationPluginConverter.doToDTO(model);

EventBusHolder.post(integrationPlugin);


return integrationPlugin;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@
import io.holoinsight.server.home.common.util.MonitorException;
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.common.util.scope.RequestContext.Context;
import io.holoinsight.server.home.web.common.ManageCallback;
import io.holoinsight.server.home.web.common.ParaCheckUtil;
import io.holoinsight.server.home.web.interceptor.MonitorScopeAuth;
import io.holoinsight.server.common.J;
import io.holoinsight.server.common.JsonResult;
import io.holoinsight.server.meta.common.model.QueryExample;
import io.holoinsight.server.meta.facade.service.DataClientService;
Expand All @@ -28,10 +25,8 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -70,7 +65,7 @@ public void doManage() {
queryExample.getParams().putAll(condition);
MonitorScope ms = RequestContext.getContext().ms;
Map<String, String> conditions =
tenantInitService.getTenantWorkspaceMetaConditions(ms.getWorkspace());
tenantInitService.getTenantWorkspaceMetaConditions(ms.getTenant(), ms.getWorkspace());
if (!CollectionUtils.isEmpty(conditions)) {
queryExample.getParams().putAll(conditions);
}
Expand Down Expand Up @@ -141,7 +136,7 @@ public void doManage() {
}
MonitorScope ms = RequestContext.getContext().ms;
Map<String, String> conditions =
tenantInitService.getTenantWorkspaceMetaConditions(ms.getWorkspace());
tenantInitService.getTenantWorkspaceMetaConditions(ms.getTenant(), ms.getWorkspace());
if (!CollectionUtils.isEmpty(conditions)) {
conditions.forEach((k, v) -> queryExample.getParams().put(k, v));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void doManage() {
.setEnd(System.currentTimeMillis() - 60000 * 5);

List<QueryProto.QueryFilter> tenantFilters =
tenantInitService.getTenantFilters(ms.getWorkspace());
tenantInitService.getTenantFilters(ms.getTenant(), ms.getWorkspace());
if (!CollectionUtils.isEmpty(tenantFilters)) {
builder.addAllFilters(tenantFilters);
}
Expand Down Expand Up @@ -297,7 +297,7 @@ public void doManage() {
.addAllGroupBy(Collections.singletonList(tagQueryRequest.getKey()));

List<QueryProto.QueryFilter> tenantFilters =
tenantInitService.getTenantFilters(ms.getWorkspace());
tenantInitService.getTenantFilters(ms.getTenant(), ms.getWorkspace());

if (!CollectionUtils.isEmpty(tagQueryRequest.getConditions())) {
tagQueryRequest.getConditions().forEach((k, v) -> {
Expand Down Expand Up @@ -474,7 +474,7 @@ public QueryProto.QueryRequest convertRequest(DataQueryRequest request) {

QueryProto.Datasource.Builder datasourceBuilder = QueryProto.Datasource.newBuilder();
toProtoBean(datasourceBuilder, d);
Boolean aBoolean = tenantInitService.checkConditions(ms.getWorkspace(),
Boolean aBoolean = tenantInitService.checkConditions(ms.getTenant(), ms.getWorkspace(),
datasourceBuilder.getMetric(), datasourceBuilder.getFiltersList());
if (!aBoolean) {
throw new MonitorException("workspace is illegal");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public SearchKeywordRet searchInfraEntity(String keyword, String tenant, String
Pattern.compile(String.format("^.*%s.*$", keyword), Pattern.CASE_INSENSITIVE));
if (StringUtils.isNotBlank(workspace)) {
Map<String, String> conditions =
tenantInitService.getTenantWorkspaceMetaConditions(workspace);
tenantInitService.getTenantWorkspaceMetaConditions(tenant, workspace);
if (!CollectionUtils.isEmpty(conditions)) {
conditions.forEach((k, v) -> queryExample.getParams().put(k, v));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void checkParameter() {
map.put("hostname", userFavorite.name);
queryExample.setParams(map);
Map<String, String> conditions = tenantInitService
.getTenantWorkspaceMetaConditions(RequestContext.getContext().ms.getWorkspace());
.getTenantWorkspaceMetaConditions(ms.getTenant(), ms.getWorkspace());
if (!CollectionUtils.isEmpty(conditions)) {
queryExample.getParams().putAll(conditions);
}
Expand Down

0 comments on commit 0d17138

Please sign in to comment.