diff --git a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/listener/IntegrationGeneratedUpdateListener.java b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/listener/IntegrationGeneratedUpdateListener.java index 2c5adf32a..339f33319 100644 --- a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/listener/IntegrationGeneratedUpdateListener.java +++ b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/listener/IntegrationGeneratedUpdateListener.java @@ -18,6 +18,7 @@ import io.holoinsight.server.home.dal.model.dto.GaeaCollectConfigDTO.GaeaCollectRange; import io.holoinsight.server.home.dal.model.dto.IntegrationGeneratedDTO; import io.holoinsight.server.home.dal.model.dto.IntegrationPluginDTO; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -35,6 +36,7 @@ * @version 1.0: IntegrationGeneratedUpdateListener.java, Date: 2023-07-26 Time: 10:57 */ @Component +@Slf4j public class IntegrationGeneratedUpdateListener { @Autowired @@ -51,15 +53,25 @@ void register() { @Subscribe @AllowConcurrentEvents public void onEvent(IntegrationGeneratedDTO integrationGeneratedDTO) { - if (CollectionUtils.isEmpty(integrationGeneratedDTO.config)) - return; - IntegrationPluginDTO integrationPluginDTO = convertIntegrationPlugin(integrationGeneratedDTO); - - if (StringUtils.isBlank(integrationPluginDTO.json) - || StringUtils.isBlank(integrationPluginDTO.type)) - return; - List upsert = integrationPluginUpdateListener.upsertGaea(integrationPluginDTO); - notify(upsert); + log.info("[integration_generated][{}][{}] convert start", integrationGeneratedDTO.getProduct(), + integrationGeneratedDTO.getId()); + + try { + if (CollectionUtils.isEmpty(integrationGeneratedDTO.config)) + return; + IntegrationPluginDTO integrationPluginDTO = convertIntegrationPlugin(integrationGeneratedDTO); + + if (StringUtils.isBlank(integrationPluginDTO.json) + || StringUtils.isBlank(integrationPluginDTO.type)) + return; + List upsert = integrationPluginUpdateListener.upsertGaea(integrationPluginDTO); + notify(upsert); + } catch (Throwable t) { + log.error("[integration_plugin][{}][{}] convert error, {}", + integrationGeneratedDTO.getProduct(), integrationGeneratedDTO.getId(), t.getMessage(), t); + } + log.info("[integration_generated][{}][{}] convert end", integrationGeneratedDTO.getProduct(), + integrationGeneratedDTO.getId()); } private IntegrationPluginDTO convertIntegrationPlugin(IntegrationGeneratedDTO generatedDTO) { diff --git a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/listener/IntegrationPluginUpdateListener.java b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/listener/IntegrationPluginUpdateListener.java index 9af917e21..0cb9cd456 100644 --- a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/listener/IntegrationPluginUpdateListener.java +++ b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/listener/IntegrationPluginUpdateListener.java @@ -14,6 +14,7 @@ import io.holoinsight.server.home.dal.model.dto.IntegrationPluginDTO; import com.google.common.eventbus.AllowConcurrentEvents; import com.google.common.eventbus.Subscribe; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -29,6 +30,7 @@ * @version 1.0: IntegrationPluginUpdateListener.java, v 0.1 2022年06月08日 8:40 下午 xiangwanpeng Exp $ */ @Component +@Slf4j public class IntegrationPluginUpdateListener { @Autowired @@ -50,24 +52,34 @@ void register() { @Subscribe @AllowConcurrentEvents public void onEvent(IntegrationPluginDTO integrationPluginDTO) { - boolean needUpsertGaea = isClassicPlugin(integrationPluginDTO.getProduct()) - || checkActionType(integrationPluginDTO, null, this.pluginRepository); - if (needUpsertGaea) { - List upsert = upsertGaea(integrationPluginDTO); - notify(upsert); - } else if (this.pluginRepository.isHostingPlugin(integrationPluginDTO.type)) { - HostingPlugin hostingPlugin = (HostingPlugin) this.pluginRepository - .getTemplate(integrationPluginDTO.type, integrationPluginDTO.version); - if (integrationPluginDTO.status) { - hostingPlugin.apply(integrationPluginDTO); - } else { - hostingPlugin.disable(integrationPluginDTO); - } - } else if ("OpenAiPlugin".equals(integrationPluginDTO.getProduct())) { - if (!integrationPluginDTO.status) { - this.openAiService.unload(integrationPluginDTO.tenant); + log.info("[integration_plugin][{}][{}] convert start", integrationPluginDTO.getProduct(), + integrationPluginDTO.getId()); + try { + boolean needUpsertGaea = isClassicPlugin(integrationPluginDTO.getProduct()) + || checkActionType(integrationPluginDTO, null, this.pluginRepository); + if (needUpsertGaea) { + List upsert = upsertGaea(integrationPluginDTO); + notify(upsert); + } else if (this.pluginRepository.isHostingPlugin(integrationPluginDTO.type)) { + HostingPlugin hostingPlugin = (HostingPlugin) this.pluginRepository + .getTemplate(integrationPluginDTO.type, integrationPluginDTO.version); + if (integrationPluginDTO.status) { + hostingPlugin.apply(integrationPluginDTO); + } else { + hostingPlugin.disable(integrationPluginDTO); + } + } else if ("OpenAiPlugin".equals(integrationPluginDTO.getProduct())) { + if (!integrationPluginDTO.status) { + this.openAiService.unload(integrationPluginDTO.tenant); + } } + } catch (Throwable t) { + log.error("[integration_plugin][{}][{}] convert error, {}", integrationPluginDTO.getProduct(), + integrationPluginDTO.getId(), t.getMessage(), t); } + + log.info("[integration_plugin][{}][{}] convert end", integrationPluginDTO.getProduct(), + integrationPluginDTO.getId()); } public List upsertGaea(IntegrationPluginDTO integrationPluginDTO) { diff --git a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/plugin/core/LogPlugin.java b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/plugin/core/LogPlugin.java index bc3f0523d..7c388d492 100644 --- a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/plugin/core/LogPlugin.java +++ b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/plugin/core/LogPlugin.java @@ -8,12 +8,18 @@ import io.holoinsight.server.home.biz.common.GaeaConvertUtil; import io.holoinsight.server.home.biz.common.GaeaSqlTaskUtil; import io.holoinsight.server.home.biz.plugin.config.LogPluginConfig; +import io.holoinsight.server.home.common.util.MonitorException; import io.holoinsight.server.home.dal.model.dto.CustomPluginPeriodType; import io.holoinsight.server.home.dal.model.dto.IntegrationPluginDTO; import io.holoinsight.server.home.dal.model.dto.conf.CollectMetric; +import io.holoinsight.server.home.dal.model.dto.conf.CollectMetric.AfterFilter; +import io.holoinsight.server.home.dal.model.dto.conf.CollectMetric.Metric; import io.holoinsight.server.home.dal.model.dto.conf.CustomPluginConf; import io.holoinsight.server.home.dal.model.dto.conf.CustomPluginConf.ExtraConfig; +import io.holoinsight.server.home.dal.model.dto.conf.CustomPluginConf.SplitCol; +import io.holoinsight.server.home.dal.model.dto.conf.CustomPluginConf.SpmCols; import io.holoinsight.server.home.dal.model.dto.conf.Filter; +import io.holoinsight.server.home.dal.model.dto.conf.FilterType; import io.holoinsight.server.home.dal.model.dto.conf.LogParse; import io.holoinsight.server.home.dal.model.dto.conf.LogPath; import io.holoinsight.server.common.J; @@ -32,6 +38,7 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Map; @@ -127,6 +134,8 @@ public List genPluginList(IntegrationPluginDTO integrationPluginDTO) CustomPluginConf customPluginConf = J.fromJson(J.toJson(config.conf), new TypeToken() {}.getType()); + addSpmColInPluginConf(customPluginConf); + if (CollectionUtils.isEmpty(customPluginConf.collectMetrics)) continue; CustomPluginPeriodType periodType = config.periodType; @@ -184,6 +193,10 @@ public String getPrefix() { return null; } + public void addSpmColInPluginConf(CustomPluginConf conf) { + + } + @Autowired private MetricInfoService metricInfoService; diff --git a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/plugin/core/LogPluginUtil.java b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/plugin/core/LogPluginUtil.java new file mode 100644 index 000000000..550d847f3 --- /dev/null +++ b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/plugin/core/LogPluginUtil.java @@ -0,0 +1,203 @@ +/* + * Copyright 2022 Holoinsight Project Authors. Licensed under Apache-2.0. + */ + +package io.holoinsight.server.home.biz.plugin.core; + +import io.holoinsight.server.home.common.util.MonitorException; +import io.holoinsight.server.home.dal.model.dto.conf.CollectMetric; +import io.holoinsight.server.home.dal.model.dto.conf.CollectMetric.AfterFilter; +import io.holoinsight.server.home.dal.model.dto.conf.CollectMetric.Metric; +import io.holoinsight.server.home.dal.model.dto.conf.CustomPluginConf; +import io.holoinsight.server.home.dal.model.dto.conf.CustomPluginConf.SplitCol; +import io.holoinsight.server.home.dal.model.dto.conf.CustomPluginConf.SpmCols; +import io.holoinsight.server.home.dal.model.dto.conf.FilterType; +import org.apache.commons.lang3.StringUtils; +import org.springframework.util.CollectionUtils; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * @author jsy1001de + * @version 1.0: LogPluginUtil.java, Date: 2024-01-19 Time: 15:18 + */ +public class LogPluginUtil { + + + public static void addSpmCols(CustomPluginConf conf) { + + Boolean spm = checkSpmConditions(conf); + + List newCollectMetrics = new ArrayList<>(); + int cols = 0; + if (!CollectionUtils.isEmpty(conf.collectMetrics)) { + for (CollectMetric collectMetric : conf.collectMetrics) { + if (null == collectMetric.spm || Boolean.FALSE == collectMetric.spm) { + if (spm == Boolean.TRUE + && Arrays.asList("total", "success", "fail", "cost", "successPercent") + .contains(collectMetric.tableName)) { + continue; + } + newCollectMetrics.add(collectMetric); + continue; + } + + if (spm == Boolean.FALSE) { + continue; + } + newCollectMetrics.add(collectMetric); + cols++; + } + } + + // add spm metrics + if (spm == Boolean.TRUE && cols == 0) { + SpmCols spmCols = conf.spmCols; + + List tags = new ArrayList<>(); + List splitCols = conf.splitCols; + if (!CollectionUtils.isEmpty(splitCols)) { + splitCols.forEach(splitCol -> { + if (splitCol.colType.equalsIgnoreCase("DIM")) { + tags.add(splitCol.name); + } + }); + } + + newCollectMetrics.add(genTotalCollectMetric(spmCols, tags)); + newCollectMetrics.add(genSuccessCollectMetric(spmCols, tags)); + newCollectMetrics.add(genFailCollectMetric(spmCols, tags)); + newCollectMetrics.add(genCostCollectMetric(spmCols, tags)); + newCollectMetrics.add(genSuccessPercentCollectMetric(tags)); + } + + conf.setCollectMetrics(newCollectMetrics); + + } + + + private static Boolean checkSpmConditions(CustomPluginConf conf) { + if (null == conf || null == conf.spm) { + return Boolean.FALSE; + } else if (Boolean.FALSE == conf.spm) { + return Boolean.FALSE; + } + + if (null == conf.spmCols) { + throw new MonitorException("spmCols is null"); + } + + SpmCols spmCols = conf.spmCols; + if (StringUtils.isBlank(spmCols.resultKey)) { + throw new MonitorException("resultCols is null"); + } + if (CollectionUtils.isEmpty(spmCols.successValue)) { + throw new MonitorException("successValue is null"); + } + if (StringUtils.isBlank(spmCols.costKey)) { + throw new MonitorException("costCols is null"); + } + + return Boolean.TRUE; + } + + private static CollectMetric genTotalCollectMetric(SpmCols spmCols, List tags) { + CollectMetric collectMetric = new CollectMetric(); + collectMetric.setTableName("total"); + collectMetric.setMetricType("count"); + collectMetric.setTags(tags); + collectMetric.setSpm(true); + Metric metric = new Metric(); + metric.setFunc("count"); + metric.setName("value"); + if (StringUtils.isNotBlank(spmCols.countKey)) { + collectMetric.setMetricType("select"); + metric.setFunc("sum"); + metric.setName(spmCols.countKey); + } + collectMetric.setMetrics(Collections.singletonList(metric)); + return collectMetric; + } + + private static CollectMetric genSuccessCollectMetric(SpmCols spmCols, List tags) { + CollectMetric collectMetric = new CollectMetric(); + collectMetric.setTableName("success"); + collectMetric.setMetricType("count"); + collectMetric.setTags(tags); + collectMetric.setSpm(true); + Metric metric = new Metric(); + metric.setFunc("count"); + metric.setName("value"); + if (StringUtils.isNotBlank(spmCols.countKey)) { + collectMetric.setMetricType("select"); + metric.setFunc("sum"); + metric.setName(spmCols.countKey); + } + collectMetric.setMetrics(Collections.singletonList(metric)); + + AfterFilter afterFilter = new AfterFilter(); + afterFilter.setName(spmCols.resultKey); + afterFilter.setFilterType(FilterType.IN); + afterFilter.setValues(spmCols.successValue); + collectMetric.setAfterFilters(Collections.singletonList(afterFilter)); + + return collectMetric; + } + + private static CollectMetric genFailCollectMetric(SpmCols spmCols, List tags) { + CollectMetric collectMetric = new CollectMetric(); + collectMetric.setTableName("fail"); + collectMetric.setMetricType("count"); + collectMetric.setTags(tags); + collectMetric.setSpm(true); + Metric metric = new Metric(); + metric.setFunc("count"); + metric.setName("value"); + if (StringUtils.isNotBlank(spmCols.countKey)) { + collectMetric.setMetricType("select"); + metric.setFunc("sum"); + metric.setName(spmCols.countKey); + } + collectMetric.setMetrics(Collections.singletonList(metric)); + + AfterFilter afterFilter = new AfterFilter(); + afterFilter.setName(spmCols.resultKey); + afterFilter.setFilterType(FilterType.NOT_IN); + afterFilter.setValues(spmCols.successValue); + collectMetric.setAfterFilters(Collections.singletonList(afterFilter)); + + return collectMetric; + } + + private static CollectMetric genCostCollectMetric(SpmCols spmCols, List tags) { + CollectMetric collectMetric = new CollectMetric(); + collectMetric.setTableName("cost"); + collectMetric.setMetricType("select"); + collectMetric.setTags(tags); + collectMetric.setSpm(true); + Metric metric = new Metric(); + metric.setFunc("avg"); + metric.setName(spmCols.costKey); + collectMetric.setMetrics(Collections.singletonList(metric)); + + return collectMetric; + } + + private static CollectMetric genSuccessPercentCollectMetric(List tags) { + CollectMetric collectMetric = new CollectMetric(); + collectMetric.setTableName("successPercent"); + collectMetric.setMetricType("count"); + collectMetric.setTags(tags); + collectMetric.setSpm(true); + Metric metric = new Metric(); + metric.setFunc("count"); + metric.setName("value"); + collectMetric.setMetrics(Collections.singletonList(metric)); + + + return collectMetric; + } +} diff --git a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/plugin/core/MultiLogPlugin.java b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/plugin/core/MultiLogPlugin.java index 962081deb..32ac428b3 100644 --- a/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/plugin/core/MultiLogPlugin.java +++ b/server/home/home-service/src/main/java/io/holoinsight/server/home/biz/plugin/core/MultiLogPlugin.java @@ -4,6 +4,7 @@ package io.holoinsight.server.home.biz.plugin.core; import io.holoinsight.server.home.biz.plugin.model.PluginModel; +import io.holoinsight.server.home.dal.model.dto.conf.CustomPluginConf; import org.springframework.stereotype.Component; /** @@ -14,4 +15,8 @@ @PluginModel(name = "io.holoinsight.server.plugin.MultiLogPlugin", version = "1") public class MultiLogPlugin extends LogPlugin { public MultiLogPlugin() {} + + public void addSpmColInPluginConf(CustomPluginConf conf) { + LogPluginUtil.addSpmCols(conf); + } } diff --git a/server/home/home-task/src/main/java/io/holoinsight/server/home/task/TenantIntegrationGeneratedTask.java b/server/home/home-task/src/main/java/io/holoinsight/server/home/task/TenantIntegrationGeneratedTask.java index 0a45d4646..b7579c9de 100644 --- a/server/home/home-task/src/main/java/io/holoinsight/server/home/task/TenantIntegrationGeneratedTask.java +++ b/server/home/home-task/src/main/java/io/holoinsight/server/home/task/TenantIntegrationGeneratedTask.java @@ -33,6 +33,7 @@ import io.holoinsight.server.home.biz.service.TenantOpsService; import io.holoinsight.server.home.common.model.TaskEnum; import io.holoinsight.server.home.common.util.cache.local.CommonLocalCache; +import io.holoinsight.server.home.dal.converter.IntegrationGeneratedConverter; import io.holoinsight.server.home.dal.model.IntegrationGenerated; import io.holoinsight.server.home.dal.model.dto.CloudMonitorRange; import io.holoinsight.server.home.dal.model.dto.GaeaCollectConfigDTO.GaeaCollectRange; @@ -81,6 +82,9 @@ public class TenantIntegrationGeneratedTask extends AbstractMonitorTask { @Autowired private TenantInitService tenantInitService; + @Autowired + private IntegrationGeneratedConverter integrationGeneratedConverter; + @Autowired private MetaService metaService; @@ -139,7 +143,9 @@ private void syncAoAction() { log.info("newList: " + newList.size()); if (!CollectionUtils.isEmpty(newList)) { for (IntegrationGeneratedDTO integrationGeneratedDTO : newList) { - integrationGeneratedService.insert(integrationGeneratedDTO); + IntegrationGenerated integrationGenerated = + integrationGeneratedConverter.dtoToDO(integrationGeneratedDTO); + integrationGeneratedService.save(integrationGenerated); } } @@ -188,6 +194,8 @@ private Map getIntegrationGeneratedList() { for (String tenant : tenants) { String tableName = tenantInitService.getTenantAppTable(tenant); + log.info("[integration_generated], {}, start", tableName); + List dbApps = getDbApps(tableName); if (CollectionUtils.isEmpty(dbApps)) continue; @@ -198,6 +206,8 @@ private Map getIntegrationGeneratedList() { Set uks = new HashSet<>(); if (!CollectionUtils.isEmpty(integrationPluginDTOS)) { for (IntegrationPluginDTO integrationPluginDTO : integrationPluginDTOS) { + log.info("[integration_generated], {}, {} start", tableName, + integrationPluginDTO.getProduct()); Plugin plugin = this.pluginRepository.getTemplate(integrationPluginDTO.type, integrationPluginDTO.version); if (null == plugin || plugin.getPluginType().equals(PluginType.hosting)) { @@ -263,9 +273,11 @@ private Map getIntegrationGeneratedList() { uks.add(uk); } } - log.info("outList: " + tableName + ", generated size: " + generateds.size()); + log.info("outList: {}, {}, generated size: {}", tableName, + integrationPluginDTO.getProduct(), generateds.size()); } } + log.info("[integration_generated], {}, apps={}", tableName, dbApps.size()); for (AppModel appModel : dbApps) { @@ -298,6 +310,7 @@ private Map getIntegrationGeneratedList() { } } } + log.info("[integration_generated], generated={}", generateds.size()); List extraGeneratedLists = tenantInitService.getExtraGeneratedLists(); if (!CollectionUtils.isEmpty(extraGeneratedLists)) { diff --git a/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/CustomPluginFacadeImpl.java b/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/CustomPluginFacadeImpl.java index cb1ec78c6..0ab66cd03 100644 --- a/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/CustomPluginFacadeImpl.java +++ b/server/home/home-web/src/main/java/io/holoinsight/server/home/web/controller/CustomPluginFacadeImpl.java @@ -4,6 +4,7 @@ package io.holoinsight.server.home.web.controller; import io.holoinsight.server.common.UtilMisc; +import io.holoinsight.server.home.biz.plugin.core.LogPluginUtil; import io.holoinsight.server.home.biz.service.AlarmMetricService; import io.holoinsight.server.home.biz.service.CustomPluginService; import io.holoinsight.server.home.biz.service.FolderService; @@ -115,7 +116,7 @@ public void checkParameter() { @Override public void doManage() { - addSpmCols(customPluginDTO.conf); + LogPluginUtil.addSpmCols(customPluginDTO.conf); MonitorScope ms = RequestContext.getContext().ms; MonitorUser mu = RequestContext.getContext().mu; @@ -179,7 +180,7 @@ public void checkParameter() { @Override public void doManage() { - addSpmCols(customPluginDTO.conf); + LogPluginUtil.addSpmCols(customPluginDTO.conf); MonitorScope ms = RequestContext.getContext().ms; MonitorUser mu = RequestContext.getContext().mu; @@ -504,178 +505,7 @@ public List presplitRegexp(List sampleLogs, String expression) return strings; } - private Boolean checkSpmConditions(CustomPluginConf conf) { - if (null == conf || null == conf.spm) { - return Boolean.FALSE; - } else if (Boolean.FALSE == conf.spm) { - return Boolean.FALSE; - } - - if (null == conf.spmCols) { - throw new MonitorException("spmCols is null"); - } - - SpmCols spmCols = conf.spmCols; - if (StringUtils.isBlank(spmCols.resultKey)) { - throw new MonitorException("resultCols is null"); - } - if (CollectionUtils.isEmpty(spmCols.successValue)) { - throw new MonitorException("successValue is null"); - } - if (StringUtils.isBlank(spmCols.costKey)) { - throw new MonitorException("costCols is null"); - } - - return Boolean.TRUE; - } - private void addSpmCols(CustomPluginConf conf) { - - Boolean spm = checkSpmConditions(conf); - - List newCollectMetrics = new ArrayList<>(); - int cols = 0; - if (!CollectionUtils.isEmpty(conf.collectMetrics)) { - for (CollectMetric collectMetric : conf.collectMetrics) { - if (null == collectMetric.spm || Boolean.FALSE == collectMetric.spm) { - if (spm == Boolean.TRUE - && Arrays.asList("total", "success", "fail", "cost", "successPercent") - .contains(collectMetric.tableName)) { - continue; - } - newCollectMetrics.add(collectMetric); - continue; - } - - if (spm == Boolean.FALSE) { - continue; - } - newCollectMetrics.add(collectMetric); - cols++; - } - } - - // add spm metrics - if (spm == Boolean.TRUE && cols == 0) { - SpmCols spmCols = conf.spmCols; - - List tags = new ArrayList<>(); - List splitCols = conf.splitCols; - if (!CollectionUtils.isEmpty(splitCols)) { - splitCols.forEach(splitCol -> { - if (splitCol.colType.equalsIgnoreCase("DIM")) { - tags.add(splitCol.name); - } - }); - } - - newCollectMetrics.add(genTotalCollectMetric(spmCols, tags)); - newCollectMetrics.add(genSuccessCollectMetric(spmCols, tags)); - newCollectMetrics.add(genFailCollectMetric(spmCols, tags)); - newCollectMetrics.add(genCostCollectMetric(spmCols, tags)); - newCollectMetrics.add(genSuccessPercentCollectMetric(tags)); - } - - conf.setCollectMetrics(newCollectMetrics); - - } - - private CollectMetric genTotalCollectMetric(SpmCols spmCols, List tags) { - CollectMetric collectMetric = new CollectMetric(); - collectMetric.setTableName("total"); - collectMetric.setMetricType("count"); - collectMetric.setTags(tags); - collectMetric.setSpm(true); - Metric metric = new Metric(); - metric.setFunc("count"); - metric.setName("value"); - if (StringUtils.isNotBlank(spmCols.countKey)) { - collectMetric.setMetricType("select"); - metric.setFunc("sum"); - metric.setName(spmCols.countKey); - } - collectMetric.setMetrics(Collections.singletonList(metric)); - return collectMetric; - } - - private CollectMetric genSuccessCollectMetric(SpmCols spmCols, List tags) { - CollectMetric collectMetric = new CollectMetric(); - collectMetric.setTableName("success"); - collectMetric.setMetricType("count"); - collectMetric.setTags(tags); - collectMetric.setSpm(true); - Metric metric = new Metric(); - metric.setFunc("count"); - metric.setName("value"); - if (StringUtils.isNotBlank(spmCols.countKey)) { - collectMetric.setMetricType("select"); - metric.setFunc("sum"); - metric.setName(spmCols.countKey); - } - collectMetric.setMetrics(Collections.singletonList(metric)); - - AfterFilter afterFilter = new AfterFilter(); - afterFilter.setName(spmCols.resultKey); - afterFilter.setFilterType(FilterType.IN); - afterFilter.setValues(spmCols.successValue); - collectMetric.setAfterFilters(Collections.singletonList(afterFilter)); - - return collectMetric; - } - - private CollectMetric genFailCollectMetric(SpmCols spmCols, List tags) { - CollectMetric collectMetric = new CollectMetric(); - collectMetric.setTableName("fail"); - collectMetric.setMetricType("count"); - collectMetric.setTags(tags); - collectMetric.setSpm(true); - Metric metric = new Metric(); - metric.setFunc("count"); - metric.setName("value"); - if (StringUtils.isNotBlank(spmCols.countKey)) { - collectMetric.setMetricType("select"); - metric.setFunc("sum"); - metric.setName(spmCols.countKey); - } - collectMetric.setMetrics(Collections.singletonList(metric)); - - AfterFilter afterFilter = new AfterFilter(); - afterFilter.setName(spmCols.resultKey); - afterFilter.setFilterType(FilterType.NOT_IN); - afterFilter.setValues(spmCols.successValue); - collectMetric.setAfterFilters(Collections.singletonList(afterFilter)); - - return collectMetric; - } - - private CollectMetric genCostCollectMetric(SpmCols spmCols, List tags) { - CollectMetric collectMetric = new CollectMetric(); - collectMetric.setTableName("cost"); - collectMetric.setMetricType("select"); - collectMetric.setTags(tags); - collectMetric.setSpm(true); - Metric metric = new Metric(); - metric.setFunc("avg"); - metric.setName(spmCols.costKey); - collectMetric.setMetrics(Collections.singletonList(metric)); - - return collectMetric; - } - - private CollectMetric genSuccessPercentCollectMetric(List tags) { - CollectMetric collectMetric = new CollectMetric(); - collectMetric.setTableName("successPercent"); - collectMetric.setMetricType("count"); - collectMetric.setTags(tags); - collectMetric.setSpm(true); - Metric metric = new Metric(); - metric.setFunc("count"); - metric.setName("value"); - collectMetric.setMetrics(Collections.singletonList(metric)); - - - return collectMetric; - } private void checkParentFolderId(CustomPluginDTO customPluginDTO) { if (customPluginDTO.parentFolderId == -1) {