From 77f615a8ae6c5713be23b0dbcb1ccead9009563b Mon Sep 17 00:00:00 2001 From: peng-yongsheng <8082209@qq.com> Date: Sun, 4 Feb 2018 22:16:52 +0800 Subject: [PATCH] Provide the queryBasicTraces query. --- .../define/graph/MetricGraphIdDefine.java | 2 +- .../define/graph/MetricWorkerIdDefine.java | 2 +- .../AnalysisMetricModuleProvider.java | 10 +- ...stGraph.java => SegmentDurationGraph.java} | 10 +- ... => SegmentDurationPersistenceWorker.java} | 20 +-- ....java => SegmentDurationSpanListener.java} | 46 +++--- .../src/main/resources/application.yml | 22 +-- .../apm/collector/storage/StorageModule.java | 8 +- ...va => ISegmentDurationPersistenceDAO.java} | 4 +- ...tUIDAO.java => ISegmentDurationUIDAO.java} | 17 +- ...{SegmentCost.java => SegmentDuration.java} | 37 +++-- ...stTable.java => SegmentDurationTable.java} | 8 +- .../storage/ui/overview/ConjecturalApp.java | 16 ++ .../ui/overview/ConjecturalAppBrief.java | 8 + .../storage/ui/trace/BasicTrace.java | 42 ++++- .../storage/ui/trace/TraceBrief.java | 23 ++- .../storage/ui/trace/TraceQueryCondition.java | 63 ++++++- .../storage/es/DataTTLKeeperTimer.java | 14 +- .../storage/es/StorageModuleEsProvider.java | 12 +- ...a => SegmentDurationEsPersistenceDAO.java} | 42 ++--- .../storage/es/dao/ui/SegmentCostEsUIDAO.java | 122 -------------- .../es/dao/ui/SegmentDurationEsUIDAO.java | 100 +++++++++++ .../es/define/SegmentCostEsTableDefine.java | 49 ------ .../define/SegmentDurationEsTableDefine.java | 49 ++++++ .../resources/META-INF/defines/storage.define | 2 +- .../storage/h2/StorageModuleH2Provider.java | 12 +- ...a => SegmentDurationH2PersistenceDAO.java} | 38 ++--- .../storage/h2/dao/ui/SegmentCostH2UIDAO.java | 155 ------------------ .../h2/dao/ui/SegmentDurationH2UIDAO.java | 118 +++++++++++++ .../h2/define/SegmentCostH2TableDefine.java | 45 ----- .../define/SegmentDurationH2TableDefine.java | 46 ++++++ .../resources/META-INF/defines/storage.define | 2 +- .../ui/query/OverViewLayerQuery.java | 15 +- .../apm/collector/ui/query/TraceQuery.java | 37 ++++- .../collector/ui/service/AlarmService.java | 44 +++++ .../ui/service/SegmentTopService.java | 44 +---- .../main/resources/ui-graphql/trace.graphqls | 3 +- 37 files changed, 714 insertions(+), 573 deletions(-) rename apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/segment/{SegmentCostGraph.java => SegmentDurationGraph.java} (83%) rename apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/segment/{SegmentCostPersistenceWorker.java => SegmentDurationPersistenceWorker.java} (74%) rename apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/segment/{SegmentCostSpanListener.java => SegmentDurationSpanListener.java} (70%) rename apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/{ISegmentCostPersistenceDAO.java => ISegmentDurationPersistenceDAO.java} (86%) rename apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/{ISegmentCostUIDAO.java => ISegmentDurationUIDAO.java} (70%) rename apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/segment/{SegmentCost.java => SegmentDuration.java} (73%) rename apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/segment/{SegmentCostTable.java => SegmentDurationTable.java} (85%) rename apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/{SegmentCostEsPersistenceDAO.java => SegmentDurationEsPersistenceDAO.java} (63%) delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/SegmentCostEsUIDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/SegmentDurationEsUIDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/SegmentCostEsTableDefine.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/SegmentDurationEsTableDefine.java rename apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/{SegmentCostH2PersistenceDAO.java => SegmentDurationH2PersistenceDAO.java} (59%) delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/SegmentCostH2UIDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/SegmentDurationH2UIDAO.java delete mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/SegmentCostH2TableDefine.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/SegmentDurationH2TableDefine.java create mode 100644 apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/AlarmService.java diff --git a/apm-collector/apm-collector-analysis/analysis-metric/metric-define/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/define/graph/MetricGraphIdDefine.java b/apm-collector/apm-collector-analysis/analysis-metric/metric-define/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/define/graph/MetricGraphIdDefine.java index d4b69bed7..e757f915f 100644 --- a/apm-collector/apm-collector-analysis/analysis-metric/metric-define/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/define/graph/MetricGraphIdDefine.java +++ b/apm-collector/apm-collector-analysis/analysis-metric/metric-define/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/define/graph/MetricGraphIdDefine.java @@ -33,7 +33,7 @@ public class MetricGraphIdDefine { public static final int APPLICATION_COMPONENT_GRAPH_ID = 406; public static final int APPLICATION_MAPPING_GRAPH_ID = 407; public static final int GLOBAL_TRACE_GRAPH_ID = 409; - public static final int SEGMENT_COST_GRAPH_ID = 410; + public static final int SEGMENT_DURATION_GRAPH_ID = 410; public static final int INSTANCE_MAPPING_GRAPH_ID = 411; public static final int INSTANCE_HEART_BEAT_PERSISTENCE_GRAPH_ID = 412; diff --git a/apm-collector/apm-collector-analysis/analysis-metric/metric-define/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/define/graph/MetricWorkerIdDefine.java b/apm-collector/apm-collector-analysis/analysis-metric/metric-define/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/define/graph/MetricWorkerIdDefine.java index a275a4417..cd9a6667b 100644 --- a/apm-collector/apm-collector-analysis/analysis-metric/metric-define/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/define/graph/MetricWorkerIdDefine.java +++ b/apm-collector/apm-collector-analysis/analysis-metric/metric-define/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/define/graph/MetricWorkerIdDefine.java @@ -113,7 +113,7 @@ public class MetricWorkerIdDefine { public static final int APPLICATION_COMPONENT_MONTH_TRANSFORM_NODE_ID = 4908; public static final int GLOBAL_TRACE_PERSISTENCE_WORKER_ID = 427; - public static final int SEGMENT_COST_PERSISTENCE_WORKER_ID = 428; + public static final int SEGMENT_DURATION_PERSISTENCE_WORKER_ID = 428; public static final int INSTANCE_REFERENCE_GRAPH_BRIDGE_WORKER_ID = 429; public static final int APPLICATION_REFERENCE_GRAPH_BRIDGE_WORKER_ID = 430; diff --git a/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/AnalysisMetricModuleProvider.java b/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/AnalysisMetricModuleProvider.java index be6c3d3ee..bf0a4a6a9 100644 --- a/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/AnalysisMetricModuleProvider.java +++ b/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/AnalysisMetricModuleProvider.java @@ -35,8 +35,8 @@ import org.apache.skywalking.apm.collector.analysis.metric.provider.worker.insta import org.apache.skywalking.apm.collector.analysis.metric.provider.worker.instance.mapping.InstanceMappingSpanListener; import org.apache.skywalking.apm.collector.analysis.metric.provider.worker.instance.metric.InstanceMetricGraph; import org.apache.skywalking.apm.collector.analysis.metric.provider.worker.instance.refmetric.InstanceReferenceMetricGraph; -import org.apache.skywalking.apm.collector.analysis.metric.provider.worker.segment.SegmentCostGraph; -import org.apache.skywalking.apm.collector.analysis.metric.provider.worker.segment.SegmentCostSpanListener; +import org.apache.skywalking.apm.collector.analysis.metric.provider.worker.segment.SegmentDurationGraph; +import org.apache.skywalking.apm.collector.analysis.metric.provider.worker.segment.SegmentDurationSpanListener; import org.apache.skywalking.apm.collector.analysis.metric.provider.worker.service.metric.ServiceMetricGraph; import org.apache.skywalking.apm.collector.analysis.metric.provider.worker.service.refmetric.ServiceReferenceMetricGraph; import org.apache.skywalking.apm.collector.analysis.metric.provider.worker.service.refmetric.ServiceReferenceMetricSpanListener; @@ -93,7 +93,7 @@ public class AnalysisMetricModuleProvider extends ModuleProvider { segmentParserListenerRegister.register(new ApplicationMappingSpanListener.Factory()); segmentParserListenerRegister.register(new InstanceMappingSpanListener.Factory()); segmentParserListenerRegister.register(new GlobalTraceSpanListener.Factory()); - segmentParserListenerRegister.register(new SegmentCostSpanListener.Factory()); + segmentParserListenerRegister.register(new SegmentDurationSpanListener.Factory()); } private void graphCreate(WorkerCreateListener workerCreateListener) { @@ -127,8 +127,8 @@ public class AnalysisMetricModuleProvider extends ModuleProvider { GlobalTraceGraph globalTraceGraph = new GlobalTraceGraph(getManager(), workerCreateListener); globalTraceGraph.create(); - SegmentCostGraph segmentCostGraph = new SegmentCostGraph(getManager(), workerCreateListener); - segmentCostGraph.create(); + SegmentDurationGraph segmentDurationGraph = new SegmentDurationGraph(getManager(), workerCreateListener); + segmentDurationGraph.create(); InstanceHeartBeatPersistenceGraph instanceHeartBeatPersistenceGraph = new InstanceHeartBeatPersistenceGraph(getManager(), workerCreateListener); instanceHeartBeatPersistenceGraph.create(); diff --git a/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/segment/SegmentCostGraph.java b/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/segment/SegmentDurationGraph.java similarity index 83% rename from apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/segment/SegmentCostGraph.java rename to apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/segment/SegmentDurationGraph.java index badd115a0..af8fd2813 100644 --- a/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/segment/SegmentCostGraph.java +++ b/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/segment/SegmentDurationGraph.java @@ -22,23 +22,23 @@ import org.apache.skywalking.apm.collector.analysis.metric.define.graph.MetricGr import org.apache.skywalking.apm.collector.analysis.worker.model.base.WorkerCreateListener; import org.apache.skywalking.apm.collector.core.graph.GraphManager; import org.apache.skywalking.apm.collector.core.module.ModuleManager; -import org.apache.skywalking.apm.collector.storage.table.segment.SegmentCost; +import org.apache.skywalking.apm.collector.storage.table.segment.SegmentDuration; /** * @author peng-yongsheng */ -public class SegmentCostGraph { +public class SegmentDurationGraph { private final ModuleManager moduleManager; private final WorkerCreateListener workerCreateListener; - public SegmentCostGraph(ModuleManager moduleManager, WorkerCreateListener workerCreateListener) { + public SegmentDurationGraph(ModuleManager moduleManager, WorkerCreateListener workerCreateListener) { this.moduleManager = moduleManager; this.workerCreateListener = workerCreateListener; } public void create() { - GraphManager.INSTANCE.createIfAbsent(MetricGraphIdDefine.SEGMENT_COST_GRAPH_ID, SegmentCost.class) - .addNode(new SegmentCostPersistenceWorker.Factory(moduleManager).create(workerCreateListener)); + GraphManager.INSTANCE.createIfAbsent(MetricGraphIdDefine.SEGMENT_DURATION_GRAPH_ID, SegmentDuration.class) + .addNode(new SegmentDurationPersistenceWorker.Factory(moduleManager).create(workerCreateListener)); } } diff --git a/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/segment/SegmentCostPersistenceWorker.java b/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/segment/SegmentDurationPersistenceWorker.java similarity index 74% rename from apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/segment/SegmentCostPersistenceWorker.java rename to apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/segment/SegmentDurationPersistenceWorker.java index aa6093627..17e9d7798 100644 --- a/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/segment/SegmentCostPersistenceWorker.java +++ b/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/segment/SegmentDurationPersistenceWorker.java @@ -24,20 +24,20 @@ import org.apache.skywalking.apm.collector.analysis.worker.model.impl.Persistenc import org.apache.skywalking.apm.collector.core.module.ModuleManager; import org.apache.skywalking.apm.collector.storage.StorageModule; import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; -import org.apache.skywalking.apm.collector.storage.dao.ISegmentCostPersistenceDAO; -import org.apache.skywalking.apm.collector.storage.table.segment.SegmentCost; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentDurationPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.table.segment.SegmentDuration; /** * @author peng-yongsheng */ -public class SegmentCostPersistenceWorker extends PersistenceWorker { +public class SegmentDurationPersistenceWorker extends PersistenceWorker { - public SegmentCostPersistenceWorker(ModuleManager moduleManager) { + SegmentDurationPersistenceWorker(ModuleManager moduleManager) { super(moduleManager); } @Override public int id() { - return MetricWorkerIdDefine.SEGMENT_COST_PERSISTENCE_WORKER_ID; + return MetricWorkerIdDefine.SEGMENT_DURATION_PERSISTENCE_WORKER_ID; } @Override protected boolean needMergeDBData() { @@ -45,18 +45,18 @@ public class SegmentCostPersistenceWorker extends PersistenceWorker } @SuppressWarnings("unchecked") - @Override protected IPersistenceDAO persistenceDAO() { - return getModuleManager().find(StorageModule.NAME).getService(ISegmentCostPersistenceDAO.class); + @Override protected IPersistenceDAO persistenceDAO() { + return getModuleManager().find(StorageModule.NAME).getService(ISegmentDurationPersistenceDAO.class); } - public static class Factory extends PersistenceWorkerProvider { + public static class Factory extends PersistenceWorkerProvider { public Factory(ModuleManager moduleManager) { super(moduleManager); } - @Override public SegmentCostPersistenceWorker workerInstance(ModuleManager moduleManager) { - return new SegmentCostPersistenceWorker(moduleManager); + @Override public SegmentDurationPersistenceWorker workerInstance(ModuleManager moduleManager) { + return new SegmentDurationPersistenceWorker(moduleManager); } @Override diff --git a/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/segment/SegmentCostSpanListener.java b/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/segment/SegmentDurationSpanListener.java similarity index 70% rename from apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/segment/SegmentCostSpanListener.java rename to apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/segment/SegmentDurationSpanListener.java index d12cfca97..e99126bc4 100644 --- a/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/segment/SegmentCostSpanListener.java +++ b/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/segment/SegmentDurationSpanListener.java @@ -35,46 +35,46 @@ import org.apache.skywalking.apm.collector.core.graph.GraphManager; import org.apache.skywalking.apm.collector.core.module.ModuleManager; import org.apache.skywalking.apm.collector.core.util.BooleanUtils; import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.apache.skywalking.apm.collector.storage.table.segment.SegmentCost; +import org.apache.skywalking.apm.collector.storage.table.segment.SegmentDuration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * @author peng-yongsheng */ -public class SegmentCostSpanListener implements EntrySpanListener, ExitSpanListener, LocalSpanListener, FirstSpanListener { +public class SegmentDurationSpanListener implements EntrySpanListener, ExitSpanListener, LocalSpanListener, FirstSpanListener { - private final Logger logger = LoggerFactory.getLogger(SegmentCostSpanListener.class); + private final Logger logger = LoggerFactory.getLogger(SegmentDurationSpanListener.class); - private final List segmentCosts; + private final List segmentDurations; private final ServiceNameCacheService serviceNameCacheService; private boolean isError = false; private long timeBucket; - public SegmentCostSpanListener(ModuleManager moduleManager) { - this.segmentCosts = new ArrayList<>(); + SegmentDurationSpanListener(ModuleManager moduleManager) { + this.segmentDurations = new ArrayList<>(); this.serviceNameCacheService = moduleManager.find(CacheModule.NAME).getService(ServiceNameCacheService.class); } @Override public void parseFirst(SpanDecorator spanDecorator, int applicationId, int instanceId, String segmentId) { - timeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(spanDecorator.getStartTime()); + timeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(spanDecorator.getStartTime()); - SegmentCost segmentCost = new SegmentCost(); - segmentCost.setId(segmentId); - segmentCost.setSegmentId(segmentId); - segmentCost.setApplicationId(applicationId); - segmentCost.setCost(spanDecorator.getEndTime() - spanDecorator.getStartTime()); - segmentCost.setStartTime(spanDecorator.getStartTime()); - segmentCost.setEndTime(spanDecorator.getEndTime()); + SegmentDuration segmentDuration = new SegmentDuration(); + segmentDuration.setId(segmentId); + segmentDuration.setSegmentId(segmentId); + segmentDuration.setApplicationId(applicationId); + segmentDuration.setDuration(spanDecorator.getEndTime() - spanDecorator.getStartTime()); + segmentDuration.setStartTime(spanDecorator.getStartTime()); + segmentDuration.setEndTime(spanDecorator.getEndTime()); if (spanDecorator.getOperationNameId() == 0) { - segmentCost.setServiceName(spanDecorator.getOperationName()); + segmentDuration.setServiceName(spanDecorator.getOperationName()); } else { - segmentCost.setServiceName(serviceNameCacheService.getSplitServiceName(serviceNameCacheService.get(spanDecorator.getOperationNameId()))); + segmentDuration.setServiceName(serviceNameCacheService.getSplitServiceName(serviceNameCacheService.get(spanDecorator.getOperationNameId()))); } - segmentCosts.add(segmentCost); + segmentDurations.add(segmentDuration); isError = isError || spanDecorator.getIsError(); } @@ -96,18 +96,18 @@ public class SegmentCostSpanListener implements EntrySpanListener, ExitSpanListe } @Override public void build() { - Graph graph = GraphManager.INSTANCE.findGraph(MetricGraphIdDefine.SEGMENT_COST_GRAPH_ID, SegmentCost.class); + Graph graph = GraphManager.INSTANCE.findGraph(MetricGraphIdDefine.SEGMENT_DURATION_GRAPH_ID, SegmentDuration.class); logger.debug("segment cost listener build"); - for (SegmentCost segmentCost : segmentCosts) { - segmentCost.setIsError(BooleanUtils.booleanToValue(isError)); - segmentCost.setTimeBucket(timeBucket); - graph.start(segmentCost); + for (SegmentDuration segmentDuration : segmentDurations) { + segmentDuration.setIsError(BooleanUtils.booleanToValue(isError)); + segmentDuration.setTimeBucket(timeBucket); + graph.start(segmentDuration); } } public static class Factory implements SpanListenerFactory { @Override public SpanListener create(ModuleManager moduleManager) { - return new SegmentCostSpanListener(moduleManager); + return new SegmentDurationSpanListener(moduleManager); } } } diff --git a/apm-collector/apm-collector-boot/src/main/resources/application.yml b/apm-collector/apm-collector-boot/src/main/resources/application.yml index 6e8a91ddc..aa38e3799 100644 --- a/apm-collector/apm-collector-boot/src/main/resources/application.yml +++ b/apm-collector/apm-collector-boot/src/main/resources/application.yml @@ -34,18 +34,18 @@ ui: host: localhost port: 12800 context_path: / -#storage: -# elasticsearch: -# cluster_name: CollectorDBCluster -# cluster_transport_sniffer: true -# cluster_nodes: localhost:9300 -# index_shards_number: 2 -# index_replicas_number: 0 -# ttl: 7 storage: - h2: - url: jdbc:h2:tcp://localhost/~/test - user_name: sa + elasticsearch: + cluster_name: CollectorDBCluster + cluster_transport_sniffer: true + cluster_nodes: localhost:9300 + index_shards_number: 2 + index_replicas_number: 0 + ttl: 7 +#storage: +# h2: +# url: jdbc:h2:tcp://localhost/~/test +# user_name: sa configuration: default: application_apdex_threshold: 2000 diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/StorageModule.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/StorageModule.java index c98f4c1e3..c024aafe8 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/StorageModule.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/StorageModule.java @@ -24,7 +24,7 @@ import org.apache.skywalking.apm.collector.core.module.Module; import org.apache.skywalking.apm.collector.storage.base.dao.IBatchDAO; import org.apache.skywalking.apm.collector.storage.dao.IGlobalTracePersistenceDAO; import org.apache.skywalking.apm.collector.storage.dao.IInstanceHeartBeatPersistenceDAO; -import org.apache.skywalking.apm.collector.storage.dao.ISegmentCostPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentDurationPersistenceDAO; import org.apache.skywalking.apm.collector.storage.dao.ISegmentPersistenceDAO; import org.apache.skywalking.apm.collector.storage.dao.acp.IApplicationComponentDayPersistenceDAO; import org.apache.skywalking.apm.collector.storage.dao.acp.IApplicationComponentHourPersistenceDAO; @@ -113,7 +113,7 @@ import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.IMemoryMetricUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.IMemoryPoolMetricUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.INetworkAddressUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.ui.ISegmentCostUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.ISegmentDurationUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.ISegmentUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceNameServiceUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceReferenceUIDAO; @@ -197,7 +197,7 @@ public class StorageModule extends Module { classes.add(IInstanceMappingMonthPersistenceDAO.class); classes.add(IGlobalTracePersistenceDAO.class); - classes.add(ISegmentCostPersistenceDAO.class); + classes.add(ISegmentDurationPersistenceDAO.class); classes.add(ISegmentPersistenceDAO.class); classes.add(IInstanceHeartBeatPersistenceDAO.class); @@ -247,7 +247,7 @@ public class StorageModule extends Module { classes.add(IApplicationComponentUIDAO.class); classes.add(IApplicationMappingUIDAO.class); classes.add(IApplicationReferenceMetricUIDAO.class); - classes.add(ISegmentCostUIDAO.class); + classes.add(ISegmentDurationUIDAO.class); classes.add(ISegmentUIDAO.class); classes.add(IServiceReferenceUIDAO.class); } diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ISegmentCostPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ISegmentDurationPersistenceDAO.java similarity index 86% rename from apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ISegmentCostPersistenceDAO.java rename to apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ISegmentDurationPersistenceDAO.java index f93b5c7f3..d9819e551 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ISegmentCostPersistenceDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ISegmentDurationPersistenceDAO.java @@ -19,10 +19,10 @@ package org.apache.skywalking.apm.collector.storage.dao; import org.apache.skywalking.apm.collector.storage.base.dao.IPersistenceDAO; -import org.apache.skywalking.apm.collector.storage.table.segment.SegmentCost; +import org.apache.skywalking.apm.collector.storage.table.segment.SegmentDuration; /** * @author peng-yongsheng */ -public interface ISegmentCostPersistenceDAO extends IPersistenceDAO { +public interface ISegmentDurationPersistenceDAO extends IPersistenceDAO { } diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/ISegmentCostUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/ISegmentDurationUIDAO.java similarity index 70% rename from apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/ISegmentCostUIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/ISegmentDurationUIDAO.java index 7304fc768..a1660a417 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/ISegmentCostUIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/ISegmentDurationUIDAO.java @@ -18,22 +18,13 @@ package org.apache.skywalking.apm.collector.storage.dao.ui; -import com.google.gson.JsonObject; -import java.util.List; import org.apache.skywalking.apm.collector.storage.base.dao.DAO; +import org.apache.skywalking.apm.collector.storage.ui.trace.TraceBrief; /** * @author peng-yongsheng */ -public interface ISegmentCostUIDAO extends DAO { - JsonObject loadTop(long startTime, long endTime, long minCost, long maxCost, String operationName, - Error error, int applicationId, List segmentIds, int limit, int from, Sort sort); - - enum Sort { - Cost, Time - } - - enum Error { - All, True, False - } +public interface ISegmentDurationUIDAO extends DAO { + TraceBrief loadTop(long startTime, long endTime, long minDuration, long maxDuration, String operationName, + int applicationId, String traceId, int limit, int from); } diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/segment/SegmentCost.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/segment/SegmentDuration.java similarity index 73% rename from apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/segment/SegmentCost.java rename to apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/segment/SegmentDuration.java index 475019bd0..9a0c94ff8 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/segment/SegmentCost.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/segment/SegmentDuration.java @@ -26,31 +26,32 @@ import org.apache.skywalking.apm.collector.core.data.operator.NonOperation; /** * @author peng-yongsheng */ -public class SegmentCost extends StreamData { +public class SegmentDuration extends StreamData { private static final Column[] STRING_COLUMNS = { - new Column(SegmentCostTable.COLUMN_ID, new NonOperation()), - new Column(SegmentCostTable.COLUMN_SEGMENT_ID, new CoverOperation()), - new Column(SegmentCostTable.COLUMN_SERVICE_NAME, new CoverOperation()), + new Column(SegmentDurationTable.COLUMN_ID, new NonOperation()), + new Column(SegmentDurationTable.COLUMN_SEGMENT_ID, new CoverOperation()), + new Column(SegmentDurationTable.COLUMN_SERVICE_NAME, new CoverOperation()), + new Column(SegmentDurationTable.COLUMN_TRACE_ID, new CoverOperation()), }; private static final Column[] LONG_COLUMNS = { - new Column(SegmentCostTable.COLUMN_COST, new CoverOperation()), - new Column(SegmentCostTable.COLUMN_START_TIME, new CoverOperation()), - new Column(SegmentCostTable.COLUMN_END_TIME, new CoverOperation()), - new Column(SegmentCostTable.COLUMN_TIME_BUCKET, new CoverOperation()), + new Column(SegmentDurationTable.COLUMN_DURATION, new CoverOperation()), + new Column(SegmentDurationTable.COLUMN_START_TIME, new CoverOperation()), + new Column(SegmentDurationTable.COLUMN_END_TIME, new CoverOperation()), + new Column(SegmentDurationTable.COLUMN_TIME_BUCKET, new CoverOperation()), }; private static final Column[] DOUBLE_COLUMNS = {}; private static final Column[] INTEGER_COLUMNS = { - new Column(SegmentCostTable.COLUMN_APPLICATION_ID, new CoverOperation()), - new Column(SegmentCostTable.COLUMN_IS_ERROR, new CoverOperation()), + new Column(SegmentDurationTable.COLUMN_APPLICATION_ID, new CoverOperation()), + new Column(SegmentDurationTable.COLUMN_IS_ERROR, new CoverOperation()), }; private static final Column[] BYTE_COLUMNS = {}; - public SegmentCost() { + public SegmentDuration() { super(STRING_COLUMNS, LONG_COLUMNS, DOUBLE_COLUMNS, INTEGER_COLUMNS, BYTE_COLUMNS); } @@ -86,12 +87,20 @@ public class SegmentCost extends StreamData { setDataString(2, serviceName); } - public Long getCost() { + public String getTraceId() { + return getDataString(3); + } + + public void setTraceId(String traceId) { + setDataString(3, traceId); + } + + public Long getDuration() { return getDataLong(0); } - public void setCost(Long cost) { - setDataLong(0, cost); + public void setDuration(Long duration) { + setDataLong(0, duration); } public Long getStartTime() { diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/segment/SegmentCostTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/segment/SegmentDurationTable.java similarity index 85% rename from apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/segment/SegmentCostTable.java rename to apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/segment/SegmentDurationTable.java index 4cf7abfaf..2784628ec 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/segment/SegmentCostTable.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/segment/SegmentDurationTable.java @@ -16,7 +16,6 @@ * */ - package org.apache.skywalking.apm.collector.storage.table.segment; import org.apache.skywalking.apm.collector.core.data.CommonTable; @@ -24,13 +23,14 @@ import org.apache.skywalking.apm.collector.core.data.CommonTable; /** * @author peng-yongsheng */ -public class SegmentCostTable extends CommonTable { - public static final String TABLE = "segment_cost"; +public class SegmentDurationTable extends CommonTable { + public static final String TABLE = "segment_duration"; public static final String COLUMN_SEGMENT_ID = "segment_id"; + public static final String COLUMN_TRACE_ID = "trace_id"; public static final String COLUMN_APPLICATION_ID = "application_id"; public static final String COLUMN_START_TIME = "start_time"; public static final String COLUMN_END_TIME = "end_time"; public static final String COLUMN_SERVICE_NAME = "service_name"; - public static final String COLUMN_COST = "cost"; + public static final String COLUMN_DURATION = "duration"; public static final String COLUMN_IS_ERROR = "is_error"; } diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/overview/ConjecturalApp.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/overview/ConjecturalApp.java index a1acc0fe7..5085e8926 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/overview/ConjecturalApp.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/overview/ConjecturalApp.java @@ -24,4 +24,20 @@ package org.apache.skywalking.apm.collector.storage.ui.overview; public class ConjecturalApp { private String name; private int num; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getNum() { + return num; + } + + public void setNum(int num) { + this.num = num; + } } diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/overview/ConjecturalAppBrief.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/overview/ConjecturalAppBrief.java index d220623fa..0d561359b 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/overview/ConjecturalAppBrief.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/overview/ConjecturalAppBrief.java @@ -25,4 +25,12 @@ import java.util.List; */ public class ConjecturalAppBrief { private List apps; + + public List getApps() { + return apps; + } + + public void setApps(List apps) { + this.apps = apps; + } } diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/BasicTrace.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/BasicTrace.java index f8829f128..127157bab 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/BasicTrace.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/BasicTrace.java @@ -24,7 +24,47 @@ package org.apache.skywalking.apm.collector.storage.ui.trace; public class BasicTrace { private String operationName; private int duration; - private String start; + private long start; private Boolean isError; private String traceId; + + public String getOperationName() { + return operationName; + } + + public void setOperationName(String operationName) { + this.operationName = operationName; + } + + public int getDuration() { + return duration; + } + + public void setDuration(int duration) { + this.duration = duration; + } + + public long getStart() { + return start; + } + + public void setStart(long start) { + this.start = start; + } + + public Boolean getError() { + return isError; + } + + public void setError(Boolean error) { + isError = error; + } + + public String getTraceId() { + return traceId; + } + + public void setTraceId(String traceId) { + this.traceId = traceId; + } } diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/TraceBrief.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/TraceBrief.java index 1ec1987e3..df1963487 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/TraceBrief.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/TraceBrief.java @@ -18,6 +18,7 @@ package org.apache.skywalking.apm.collector.storage.ui.trace; +import java.util.LinkedList; import java.util.List; /** @@ -25,5 +26,25 @@ import java.util.List; */ public class TraceBrief { private List traces; - private Integer total; + private int total; + + public TraceBrief() { + traces = new LinkedList<>(); + } + + public List getTraces() { + return traces; + } + + public void setTraces(List traces) { + this.traces = traces; + } + + public int getTotal() { + return total; + } + + public void setTotal(int total) { + this.total = total; + } } diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/TraceQueryCondition.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/TraceQueryCondition.java index 62757804d..86bea1abe 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/TraceQueryCondition.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/TraceQueryCondition.java @@ -18,19 +18,74 @@ package org.apache.skywalking.apm.collector.storage.ui.trace; -import java.util.List; import org.apache.skywalking.apm.collector.storage.ui.common.Duration; +import org.apache.skywalking.apm.collector.storage.ui.common.Pagination; /** * @author peng-yongsheng */ public class TraceQueryCondition { - private List applicationCodes; + private int applicationId; private String traceId; private String operationName; private Duration queryDuration; private int minTraceDuration; private int maxTraceDuration; - private Boolean topN; - private int needTotal; + private Pagination paging; + + public int getApplicationId() { + return applicationId; + } + + public void setApplicationId(int applicationId) { + this.applicationId = applicationId; + } + + public String getTraceId() { + return traceId; + } + + public void setTraceId(String traceId) { + this.traceId = traceId; + } + + public String getOperationName() { + return operationName; + } + + public void setOperationName(String operationName) { + this.operationName = operationName; + } + + public Duration getQueryDuration() { + return queryDuration; + } + + public void setQueryDuration(Duration queryDuration) { + this.queryDuration = queryDuration; + } + + public int getMinTraceDuration() { + return minTraceDuration; + } + + public void setMinTraceDuration(int minTraceDuration) { + this.minTraceDuration = minTraceDuration; + } + + public int getMaxTraceDuration() { + return maxTraceDuration; + } + + public void setMaxTraceDuration(int maxTraceDuration) { + this.maxTraceDuration = maxTraceDuration; + } + + public Pagination getPaging() { + return paging; + } + + public void setPaging(Pagination paging) { + this.paging = paging; + } } diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/DataTTLKeeperTimer.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/DataTTLKeeperTimer.java index ca152a492..fde18dac3 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/DataTTLKeeperTimer.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/DataTTLKeeperTimer.java @@ -16,16 +16,16 @@ * */ - package org.apache.skywalking.apm.collector.storage.es; -import org.apache.skywalking.apm.collector.core.module.ModuleManager; -import org.apache.skywalking.apm.collector.storage.StorageModule; -import org.apache.skywalking.apm.collector.storage.dao.*; - import java.util.Calendar; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.storage.dao.IGlobalTracePersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentDurationPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentPersistenceDAO; import org.apache.skywalking.apm.collector.storage.dao.acp.IApplicationComponentMinutePersistenceDAO; import org.apache.skywalking.apm.collector.storage.dao.ampp.IApplicationMappingMinutePersistenceDAO; import org.apache.skywalking.apm.collector.storage.dao.armp.IApplicationReferenceMinuteMetricPersistenceDAO; @@ -113,8 +113,8 @@ public class DataTTLKeeperTimer { IApplicationReferenceMinuteMetricPersistenceDAO applicationReferenceMetricPersistenceDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationReferenceMinuteMetricPersistenceDAO.class); applicationReferenceMetricPersistenceDAO.deleteHistory(startTimestamp, endTimestamp); - ISegmentCostPersistenceDAO segmentCostPersistenceDAO = moduleManager.find(StorageModule.NAME).getService(ISegmentCostPersistenceDAO.class); - segmentCostPersistenceDAO.deleteHistory(startTimestamp, endTimestamp); + ISegmentDurationPersistenceDAO segmentDurationPersistenceDAO = moduleManager.find(StorageModule.NAME).getService(ISegmentDurationPersistenceDAO.class); + segmentDurationPersistenceDAO.deleteHistory(startTimestamp, endTimestamp); ISegmentPersistenceDAO segmentPersistenceDAO = moduleManager.find(StorageModule.NAME).getService(ISegmentPersistenceDAO.class); segmentPersistenceDAO.deleteHistory(startTimestamp, endTimestamp); diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/StorageModuleEsProvider.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/StorageModuleEsProvider.java index 7a8ec4a9d..996b6cceb 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/StorageModuleEsProvider.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/StorageModuleEsProvider.java @@ -33,7 +33,7 @@ import org.apache.skywalking.apm.collector.storage.StorageModule; import org.apache.skywalking.apm.collector.storage.base.dao.IBatchDAO; import org.apache.skywalking.apm.collector.storage.dao.IGlobalTracePersistenceDAO; import org.apache.skywalking.apm.collector.storage.dao.IInstanceHeartBeatPersistenceDAO; -import org.apache.skywalking.apm.collector.storage.dao.ISegmentCostPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentDurationPersistenceDAO; import org.apache.skywalking.apm.collector.storage.dao.ISegmentPersistenceDAO; import org.apache.skywalking.apm.collector.storage.dao.acp.IApplicationComponentDayPersistenceDAO; import org.apache.skywalking.apm.collector.storage.dao.acp.IApplicationComponentHourPersistenceDAO; @@ -122,7 +122,7 @@ import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.IMemoryMetricUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.IMemoryPoolMetricUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.INetworkAddressUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.ui.ISegmentCostUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.ISegmentDurationUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.ISegmentUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceNameServiceUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceReferenceUIDAO; @@ -130,7 +130,7 @@ import org.apache.skywalking.apm.collector.storage.es.base.dao.BatchEsDAO; import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchStorageInstaller; import org.apache.skywalking.apm.collector.storage.es.dao.GlobalTraceEsPersistenceDAO; import org.apache.skywalking.apm.collector.storage.es.dao.InstanceHeartBeatEsPersistenceDAO; -import org.apache.skywalking.apm.collector.storage.es.dao.SegmentCostEsPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.SegmentDurationEsPersistenceDAO; import org.apache.skywalking.apm.collector.storage.es.dao.SegmentEsPersistenceDAO; import org.apache.skywalking.apm.collector.storage.es.dao.acp.ApplicationComponentDayEsPersistenceDAO; import org.apache.skywalking.apm.collector.storage.es.dao.acp.ApplicationComponentHourEsPersistenceDAO; @@ -219,7 +219,7 @@ import org.apache.skywalking.apm.collector.storage.es.dao.ui.InstanceMetricEsUID import org.apache.skywalking.apm.collector.storage.es.dao.ui.MemoryMetricEsUIDAO; import org.apache.skywalking.apm.collector.storage.es.dao.ui.MemoryPoolMetricEsUIDAO; import org.apache.skywalking.apm.collector.storage.es.dao.ui.NetworkAddressEsUIDAO; -import org.apache.skywalking.apm.collector.storage.es.dao.ui.SegmentCostEsUIDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.ui.SegmentDurationEsUIDAO; import org.apache.skywalking.apm.collector.storage.es.dao.ui.SegmentEsUIDAO; import org.apache.skywalking.apm.collector.storage.es.dao.ui.ServiceNameServiceEsUIDAO; import org.apache.skywalking.apm.collector.storage.es.dao.ui.ServiceReferenceEsUIDAO; @@ -364,7 +364,7 @@ public class StorageModuleEsProvider extends ModuleProvider { this.registerServiceImplementation(IApplicationReferenceDayMetricPersistenceDAO.class, new ApplicationReferenceDayMetricEsPersistenceDAO(elasticSearchClient)); this.registerServiceImplementation(IApplicationReferenceMonthMetricPersistenceDAO.class, new ApplicationReferenceMonthMetricEsPersistenceDAO(elasticSearchClient)); - this.registerServiceImplementation(ISegmentCostPersistenceDAO.class, new SegmentCostEsPersistenceDAO(elasticSearchClient)); + this.registerServiceImplementation(ISegmentDurationPersistenceDAO.class, new SegmentDurationEsPersistenceDAO(elasticSearchClient)); this.registerServiceImplementation(ISegmentPersistenceDAO.class, new SegmentEsPersistenceDAO(elasticSearchClient)); this.registerServiceImplementation(IServiceMinuteMetricPersistenceDAO.class, new ServiceMinuteMetricEsPersistenceDAO(elasticSearchClient)); @@ -405,7 +405,7 @@ public class StorageModuleEsProvider extends ModuleProvider { this.registerServiceImplementation(IApplicationComponentUIDAO.class, new ApplicationComponentEsUIDAO(elasticSearchClient)); this.registerServiceImplementation(IApplicationMappingUIDAO.class, new ApplicationMappingEsUIDAO(elasticSearchClient)); this.registerServiceImplementation(IApplicationReferenceMetricUIDAO.class, new ApplicationReferenceMetricEsUIDAO(elasticSearchClient)); - this.registerServiceImplementation(ISegmentCostUIDAO.class, new SegmentCostEsUIDAO(elasticSearchClient)); + this.registerServiceImplementation(ISegmentDurationUIDAO.class, new SegmentDurationEsUIDAO(elasticSearchClient)); this.registerServiceImplementation(ISegmentUIDAO.class, new SegmentEsUIDAO(elasticSearchClient)); this.registerServiceImplementation(IServiceReferenceUIDAO.class, new ServiceReferenceEsUIDAO(elasticSearchClient)); } diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/SegmentCostEsPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/SegmentDurationEsPersistenceDAO.java similarity index 63% rename from apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/SegmentCostEsPersistenceDAO.java rename to apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/SegmentDurationEsPersistenceDAO.java index 847e8b562..a1602b47b 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/SegmentCostEsPersistenceDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/SegmentDurationEsPersistenceDAO.java @@ -22,10 +22,10 @@ import java.util.HashMap; import java.util.Map; import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.apache.skywalking.apm.collector.storage.dao.ISegmentCostPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentDurationPersistenceDAO; import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.apache.skywalking.apm.collector.storage.table.segment.SegmentCost; -import org.apache.skywalking.apm.collector.storage.table.segment.SegmentCostTable; +import org.apache.skywalking.apm.collector.storage.table.segment.SegmentDuration; +import org.apache.skywalking.apm.collector.storage.table.segment.SegmentDurationTable; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.update.UpdateRequestBuilder; import org.elasticsearch.index.query.QueryBuilders; @@ -36,46 +36,46 @@ import org.slf4j.LoggerFactory; /** * @author peng-yongsheng */ -public class SegmentCostEsPersistenceDAO extends EsDAO implements ISegmentCostPersistenceDAO { +public class SegmentDurationEsPersistenceDAO extends EsDAO implements ISegmentDurationPersistenceDAO { - private final Logger logger = LoggerFactory.getLogger(SegmentCostEsPersistenceDAO.class); + private final Logger logger = LoggerFactory.getLogger(SegmentDurationEsPersistenceDAO.class); - public SegmentCostEsPersistenceDAO(ElasticSearchClient client) { + public SegmentDurationEsPersistenceDAO(ElasticSearchClient client) { super(client); } - @Override public SegmentCost get(String id) { + @Override public SegmentDuration get(String id) { return null; } - @Override public UpdateRequestBuilder prepareBatchUpdate(SegmentCost data) { + @Override public UpdateRequestBuilder prepareBatchUpdate(SegmentDuration data) { return null; } - @Override public IndexRequestBuilder prepareBatchInsert(SegmentCost data) { + @Override public IndexRequestBuilder prepareBatchInsert(SegmentDuration data) { logger.debug("segment cost prepareBatchInsert, getId: {}", data.getId()); Map source = new HashMap<>(); - source.put(SegmentCostTable.COLUMN_SEGMENT_ID, data.getSegmentId()); - source.put(SegmentCostTable.COLUMN_APPLICATION_ID, data.getApplicationId()); - source.put(SegmentCostTable.COLUMN_SERVICE_NAME, data.getServiceName()); - source.put(SegmentCostTable.COLUMN_COST, data.getCost()); - source.put(SegmentCostTable.COLUMN_START_TIME, data.getStartTime()); - source.put(SegmentCostTable.COLUMN_END_TIME, data.getEndTime()); - source.put(SegmentCostTable.COLUMN_IS_ERROR, data.getIsError()); - source.put(SegmentCostTable.COLUMN_TIME_BUCKET, data.getTimeBucket()); + source.put(SegmentDurationTable.COLUMN_SEGMENT_ID, data.getSegmentId()); + source.put(SegmentDurationTable.COLUMN_APPLICATION_ID, data.getApplicationId()); + source.put(SegmentDurationTable.COLUMN_SERVICE_NAME, data.getServiceName()); + source.put(SegmentDurationTable.COLUMN_DURATION, data.getDuration()); + source.put(SegmentDurationTable.COLUMN_START_TIME, data.getStartTime()); + source.put(SegmentDurationTable.COLUMN_END_TIME, data.getEndTime()); + source.put(SegmentDurationTable.COLUMN_IS_ERROR, data.getIsError()); + source.put(SegmentDurationTable.COLUMN_TIME_BUCKET, data.getTimeBucket()); logger.debug("segment cost source: {}", source.toString()); - return getClient().prepareIndex(SegmentCostTable.TABLE, data.getId()).setSource(source); + return getClient().prepareIndex(SegmentDurationTable.TABLE, data.getId()).setSource(source); } @Override public void deleteHistory(Long startTimestamp, Long endTimestamp) { long startTimeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(startTimestamp); long endTimeBucket = TimeBucketUtils.INSTANCE.getMinuteTimeBucket(endTimestamp); BulkByScrollResponse response = getClient().prepareDelete() - .filter(QueryBuilders.rangeQuery(SegmentCostTable.COLUMN_TIME_BUCKET).gte(startTimeBucket).lte(endTimeBucket)) - .source(SegmentCostTable.TABLE) + .filter(QueryBuilders.rangeQuery(SegmentDurationTable.COLUMN_TIME_BUCKET).gte(startTimeBucket).lte(endTimeBucket)) + .source(SegmentDurationTable.TABLE) .get(); long deleted = response.getDeleted(); - logger.info("Delete {} rows history from {} index.", deleted, SegmentCostTable.TABLE); + logger.info("Delete {} rows history from {} index.", deleted, SegmentDurationTable.TABLE); } } diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/SegmentCostEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/SegmentCostEsUIDAO.java deleted file mode 100644 index e33177881..000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/SegmentCostEsUIDAO.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.apache.skywalking.apm.collector.storage.es.dao.ui; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import java.util.List; -import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.apache.skywalking.apm.collector.core.util.CollectionUtils; -import org.apache.skywalking.apm.collector.core.util.StringUtils; -import org.apache.skywalking.apm.collector.storage.dao.ui.ISegmentCostUIDAO; -import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.apache.skywalking.apm.collector.storage.table.segment.SegmentCostTable; -import org.elasticsearch.action.search.SearchRequestBuilder; -import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.action.search.SearchType; -import org.elasticsearch.index.query.BoolQueryBuilder; -import org.elasticsearch.index.query.QueryBuilder; -import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.index.query.RangeQueryBuilder; -import org.elasticsearch.search.SearchHit; -import org.elasticsearch.search.sort.SortOrder; - -/** - * @author peng-yongsheng - */ -public class SegmentCostEsUIDAO extends EsDAO implements ISegmentCostUIDAO { - - public SegmentCostEsUIDAO(ElasticSearchClient client) { - super(client); - } - - @Override public JsonObject loadTop(long startTime, long endTime, long minCost, long maxCost, String operationName, - Error error, int applicationId, List segmentIds, int limit, int from, Sort sort) { - SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(SegmentCostTable.TABLE); - searchRequestBuilder.setTypes(SegmentCostTable.TABLE_TYPE); - searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); - BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); - searchRequestBuilder.setQuery(boolQueryBuilder); - List mustQueryList = boolQueryBuilder.must(); - - mustQueryList.add(QueryBuilders.rangeQuery(SegmentCostTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime)); - if (minCost != -1 || maxCost != -1) { - RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery(SegmentCostTable.COLUMN_COST); - if (minCost != -1) { - rangeQueryBuilder.gte(minCost); - } - if (maxCost != -1) { - rangeQueryBuilder.lte(maxCost); - } - boolQueryBuilder.must().add(rangeQueryBuilder); - } - if (StringUtils.isNotEmpty(operationName)) { - mustQueryList.add(QueryBuilders.matchQuery(SegmentCostTable.COLUMN_SERVICE_NAME, operationName)); - } - if (CollectionUtils.isNotEmpty(segmentIds)) { - boolQueryBuilder.must().add(QueryBuilders.termsQuery(SegmentCostTable.COLUMN_SEGMENT_ID, segmentIds.toArray(new String[0]))); - } - if (Error.True.equals(error)) { - boolQueryBuilder.must().add(QueryBuilders.termQuery(SegmentCostTable.COLUMN_IS_ERROR, true)); - } else if (Error.False.equals(error)) { - boolQueryBuilder.must().add(QueryBuilders.termQuery(SegmentCostTable.COLUMN_IS_ERROR, false)); - } - if (applicationId != 0) { - boolQueryBuilder.must().add(QueryBuilders.termQuery(SegmentCostTable.COLUMN_APPLICATION_ID, applicationId)); - } - - if (Sort.Cost.equals(sort)) { - searchRequestBuilder.addSort(SegmentCostTable.COLUMN_COST, SortOrder.DESC); - } else if (Sort.Time.equals(sort)) { - searchRequestBuilder.addSort(SegmentCostTable.COLUMN_START_TIME, SortOrder.DESC); - } - searchRequestBuilder.setSize(limit); - searchRequestBuilder.setFrom(from); - - SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); - - JsonObject topSegPaging = new JsonObject(); - topSegPaging.addProperty("recordsTotal", searchResponse.getHits().totalHits); - - JsonArray topSegArray = new JsonArray(); - topSegPaging.add("data", topSegArray); - - int num = from; - for (SearchHit searchHit : searchResponse.getHits().getHits()) { - JsonObject topSegmentJson = new JsonObject(); - topSegmentJson.addProperty("num", num); - String segmentId = (String)searchHit.getSource().get(SegmentCostTable.COLUMN_SEGMENT_ID); - topSegmentJson.addProperty(SegmentCostTable.COLUMN_SEGMENT_ID, segmentId); - topSegmentJson.addProperty(SegmentCostTable.COLUMN_START_TIME, (Number)searchHit.getSource().get(SegmentCostTable.COLUMN_START_TIME)); - if (searchHit.getSource().containsKey(SegmentCostTable.COLUMN_END_TIME)) { - topSegmentJson.addProperty(SegmentCostTable.COLUMN_END_TIME, (Number)searchHit.getSource().get(SegmentCostTable.COLUMN_END_TIME)); - } - - topSegmentJson.addProperty(SegmentCostTable.COLUMN_APPLICATION_ID, (Number)searchHit.getSource().get(SegmentCostTable.COLUMN_APPLICATION_ID)); - topSegmentJson.addProperty(SegmentCostTable.COLUMN_SERVICE_NAME, (String)searchHit.getSource().get(SegmentCostTable.COLUMN_SERVICE_NAME)); - topSegmentJson.addProperty(SegmentCostTable.COLUMN_COST, (Number)searchHit.getSource().get(SegmentCostTable.COLUMN_COST)); - topSegmentJson.addProperty(SegmentCostTable.COLUMN_IS_ERROR, (Boolean)searchHit.getSource().get(SegmentCostTable.COLUMN_IS_ERROR)); - - num++; - topSegArray.add(topSegmentJson); - } - - return topSegPaging; - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/SegmentDurationEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/SegmentDurationEsUIDAO.java new file mode 100644 index 000000000..2ea1b4581 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/SegmentDurationEsUIDAO.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.collector.storage.es.dao.ui; + +import java.util.List; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.core.util.BooleanUtils; +import org.apache.skywalking.apm.collector.core.util.StringUtils; +import org.apache.skywalking.apm.collector.storage.dao.ui.ISegmentDurationUIDAO; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.segment.SegmentDurationTable; +import org.apache.skywalking.apm.collector.storage.ui.trace.BasicTrace; +import org.apache.skywalking.apm.collector.storage.ui.trace.TraceBrief; +import org.elasticsearch.action.search.SearchRequestBuilder; +import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.action.search.SearchType; +import org.elasticsearch.index.query.BoolQueryBuilder; +import org.elasticsearch.index.query.QueryBuilder; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.index.query.RangeQueryBuilder; +import org.elasticsearch.search.SearchHit; + +/** + * @author peng-yongsheng + */ +public class SegmentDurationEsUIDAO extends EsDAO implements ISegmentDurationUIDAO { + + public SegmentDurationEsUIDAO(ElasticSearchClient client) { + super(client); + } + + @Override + public TraceBrief loadTop(long startTime, long endTime, long minDuration, long maxDuration, String operationName, + int applicationId, String traceId, int limit, int from) { + SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(SegmentDurationTable.TABLE); + searchRequestBuilder.setTypes(SegmentDurationTable.TABLE_TYPE); + searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); + BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); + searchRequestBuilder.setQuery(boolQueryBuilder); + List mustQueryList = boolQueryBuilder.must(); + + mustQueryList.add(QueryBuilders.rangeQuery(SegmentDurationTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime)); + if (minDuration != 0 || maxDuration != 0) { + RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery(SegmentDurationTable.COLUMN_DURATION); + if (minDuration != 0) { + rangeQueryBuilder.gte(minDuration); + } + if (maxDuration != 0) { + rangeQueryBuilder.lte(maxDuration); + } + boolQueryBuilder.must().add(rangeQueryBuilder); + } + if (StringUtils.isNotEmpty(operationName)) { + mustQueryList.add(QueryBuilders.matchQuery(SegmentDurationTable.COLUMN_SERVICE_NAME, operationName)); + } + if (StringUtils.isNotEmpty(traceId)) { + boolQueryBuilder.must().add(QueryBuilders.termQuery(SegmentDurationTable.COLUMN_SEGMENT_ID, traceId)); + } + if (applicationId != 0) { + boolQueryBuilder.must().add(QueryBuilders.termQuery(SegmentDurationTable.COLUMN_APPLICATION_ID, applicationId)); + } + + searchRequestBuilder.setSize(limit); + searchRequestBuilder.setFrom(from); + + SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); + + TraceBrief traceBrief = new TraceBrief(); + traceBrief.setTotal((int)searchResponse.getHits().totalHits); + + for (SearchHit searchHit : searchResponse.getHits().getHits()) { + BasicTrace basicTrace = new BasicTrace(); + + basicTrace.setTraceId((String)searchHit.getSource().get(SegmentDurationTable.COLUMN_TRACE_ID)); + basicTrace.setStart(((Number)searchHit.getSource().get(SegmentDurationTable.COLUMN_START_TIME)).longValue()); + basicTrace.setOperationName((String)searchHit.getSource().get(SegmentDurationTable.COLUMN_SERVICE_NAME)); + basicTrace.setDuration(((Number)searchHit.getSource().get(SegmentDurationTable.COLUMN_DURATION)).intValue()); + basicTrace.setError(BooleanUtils.valueToBoolean(((Number)searchHit.getSource().get(SegmentDurationTable.COLUMN_IS_ERROR)).intValue())); + traceBrief.getTraces().add(basicTrace); + } + + return traceBrief; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/SegmentCostEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/SegmentCostEsTableDefine.java deleted file mode 100644 index 99003673b..000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/SegmentCostEsTableDefine.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - - -package org.apache.skywalking.apm.collector.storage.es.define; - -import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; -import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; -import org.apache.skywalking.apm.collector.storage.table.segment.SegmentCostTable; - -/** - * @author peng-yongsheng - */ -public class SegmentCostEsTableDefine extends ElasticSearchTableDefine { - - public SegmentCostEsTableDefine() { - super(SegmentCostTable.TABLE); - } - - @Override public int refreshInterval() { - return 5; - } - - @Override public void initialize() { - addColumn(new ElasticSearchColumnDefine(SegmentCostTable.COLUMN_SEGMENT_ID, ElasticSearchColumnDefine.Type.Keyword.name())); - addColumn(new ElasticSearchColumnDefine(SegmentCostTable.COLUMN_APPLICATION_ID, ElasticSearchColumnDefine.Type.Integer.name())); - addColumn(new ElasticSearchColumnDefine(SegmentCostTable.COLUMN_SERVICE_NAME, ElasticSearchColumnDefine.Type.Text.name())); - addColumn(new ElasticSearchColumnDefine(SegmentCostTable.COLUMN_COST, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(SegmentCostTable.COLUMN_START_TIME, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(SegmentCostTable.COLUMN_END_TIME, ElasticSearchColumnDefine.Type.Long.name())); - addColumn(new ElasticSearchColumnDefine(SegmentCostTable.COLUMN_IS_ERROR, ElasticSearchColumnDefine.Type.Integer.name())); - addColumn(new ElasticSearchColumnDefine(SegmentCostTable.COLUMN_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/SegmentDurationEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/SegmentDurationEsTableDefine.java new file mode 100644 index 000000000..02d0a69d4 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/SegmentDurationEsTableDefine.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.collector.storage.es.define; + +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchColumnDefine; +import org.apache.skywalking.apm.collector.storage.es.base.define.ElasticSearchTableDefine; +import org.apache.skywalking.apm.collector.storage.table.segment.SegmentDurationTable; + +/** + * @author peng-yongsheng + */ +public class SegmentDurationEsTableDefine extends ElasticSearchTableDefine { + + public SegmentDurationEsTableDefine() { + super(SegmentDurationTable.TABLE); + } + + @Override public int refreshInterval() { + return 5; + } + + @Override public void initialize() { + addColumn(new ElasticSearchColumnDefine(SegmentDurationTable.COLUMN_SEGMENT_ID, ElasticSearchColumnDefine.Type.Keyword.name())); + addColumn(new ElasticSearchColumnDefine(SegmentDurationTable.COLUMN_APPLICATION_ID, ElasticSearchColumnDefine.Type.Integer.name())); + addColumn(new ElasticSearchColumnDefine(SegmentDurationTable.COLUMN_SERVICE_NAME, ElasticSearchColumnDefine.Type.Text.name())); + addColumn(new ElasticSearchColumnDefine(SegmentDurationTable.COLUMN_TRACE_ID, ElasticSearchColumnDefine.Type.Keyword.name())); + addColumn(new ElasticSearchColumnDefine(SegmentDurationTable.COLUMN_DURATION, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(SegmentDurationTable.COLUMN_START_TIME, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(SegmentDurationTable.COLUMN_END_TIME, ElasticSearchColumnDefine.Type.Long.name())); + addColumn(new ElasticSearchColumnDefine(SegmentDurationTable.COLUMN_IS_ERROR, ElasticSearchColumnDefine.Type.Integer.name())); + addColumn(new ElasticSearchColumnDefine(SegmentDurationTable.COLUMN_TIME_BUCKET, ElasticSearchColumnDefine.Type.Long.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/resources/META-INF/defines/storage.define b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/resources/META-INF/defines/storage.define index d016737fb..725a4ceef 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/resources/META-INF/defines/storage.define +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/resources/META-INF/defines/storage.define @@ -50,7 +50,7 @@ org.apache.skywalking.apm.collector.storage.es.define.amp.ApplicationMonthMetric org.apache.skywalking.apm.collector.storage.es.define.GlobalTraceEsTableDefine org.apache.skywalking.apm.collector.storage.es.define.SegmentEsTableDefine -org.apache.skywalking.apm.collector.storage.es.define.SegmentCostEsTableDefine +org.apache.skywalking.apm.collector.storage.es.define.SegmentDurationEsTableDefine org.apache.skywalking.apm.collector.storage.es.define.alarm.ApplicationAlarmEsTableDefine org.apache.skywalking.apm.collector.storage.es.define.alarm.ApplicationAlarmListEsTableDefine diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/StorageModuleH2Provider.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/StorageModuleH2Provider.java index f70a8e8c2..bc9278a0a 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/StorageModuleH2Provider.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/StorageModuleH2Provider.java @@ -29,7 +29,7 @@ import org.apache.skywalking.apm.collector.storage.StorageModule; import org.apache.skywalking.apm.collector.storage.base.dao.IBatchDAO; import org.apache.skywalking.apm.collector.storage.dao.IGlobalTracePersistenceDAO; import org.apache.skywalking.apm.collector.storage.dao.IInstanceHeartBeatPersistenceDAO; -import org.apache.skywalking.apm.collector.storage.dao.ISegmentCostPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentDurationPersistenceDAO; import org.apache.skywalking.apm.collector.storage.dao.ISegmentPersistenceDAO; import org.apache.skywalking.apm.collector.storage.dao.acp.IApplicationComponentDayPersistenceDAO; import org.apache.skywalking.apm.collector.storage.dao.acp.IApplicationComponentHourPersistenceDAO; @@ -118,7 +118,7 @@ import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.IMemoryMetricUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.IMemoryPoolMetricUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.INetworkAddressUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.ui.ISegmentCostUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.ISegmentDurationUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.ISegmentUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceNameServiceUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceReferenceUIDAO; @@ -126,7 +126,7 @@ import org.apache.skywalking.apm.collector.storage.h2.base.dao.BatchH2DAO; import org.apache.skywalking.apm.collector.storage.h2.base.define.H2StorageInstaller; import org.apache.skywalking.apm.collector.storage.h2.dao.GlobalTraceH2PersistenceDAO; import org.apache.skywalking.apm.collector.storage.h2.dao.InstanceHeartBeatH2PersistenceDAO; -import org.apache.skywalking.apm.collector.storage.h2.dao.SegmentCostH2PersistenceDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.SegmentDurationH2PersistenceDAO; import org.apache.skywalking.apm.collector.storage.h2.dao.SegmentH2PersistenceDAO; import org.apache.skywalking.apm.collector.storage.h2.dao.acp.ApplicationComponentDayH2PersistenceDAO; import org.apache.skywalking.apm.collector.storage.h2.dao.acp.ApplicationComponentHourH2PersistenceDAO; @@ -215,7 +215,7 @@ import org.apache.skywalking.apm.collector.storage.h2.dao.ui.InstanceMetricH2UID import org.apache.skywalking.apm.collector.storage.h2.dao.ui.MemoryMetricH2UIDAO; import org.apache.skywalking.apm.collector.storage.h2.dao.ui.MemoryPoolMetricH2UIDAO; import org.apache.skywalking.apm.collector.storage.h2.dao.ui.NetworkAddressH2UIDAO; -import org.apache.skywalking.apm.collector.storage.h2.dao.ui.SegmentCostH2UIDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.ui.SegmentDurationH2UIDAO; import org.apache.skywalking.apm.collector.storage.h2.dao.ui.SegmentH2UIDAO; import org.apache.skywalking.apm.collector.storage.h2.dao.ui.ServiceNameServiceH2UIDAO; import org.apache.skywalking.apm.collector.storage.h2.dao.ui.ServiceReferenceH2UIDAO; @@ -316,7 +316,7 @@ public class StorageModuleH2Provider extends ModuleProvider { this.registerServiceImplementation(IMemoryPoolMonthMetricPersistenceDAO.class, new MemoryPoolMonthMetricH2PersistenceDAO(h2Client)); this.registerServiceImplementation(IGlobalTracePersistenceDAO.class, new GlobalTraceH2PersistenceDAO(h2Client)); - this.registerServiceImplementation(ISegmentCostPersistenceDAO.class, new SegmentCostH2PersistenceDAO(h2Client)); + this.registerServiceImplementation(ISegmentDurationPersistenceDAO.class, new SegmentDurationH2PersistenceDAO(h2Client)); this.registerServiceImplementation(ISegmentPersistenceDAO.class, new SegmentH2PersistenceDAO(h2Client)); this.registerServiceImplementation(IInstanceHeartBeatPersistenceDAO.class, new InstanceHeartBeatH2PersistenceDAO(h2Client)); @@ -381,7 +381,7 @@ public class StorageModuleH2Provider extends ModuleProvider { this.registerServiceImplementation(IApplicationComponentUIDAO.class, new ApplicationComponentH2UIDAO(h2Client)); this.registerServiceImplementation(IApplicationMappingUIDAO.class, new ApplicationMappingH2UIDAO(h2Client)); this.registerServiceImplementation(IApplicationReferenceMetricUIDAO.class, new ApplicationReferenceMetricH2UIDAO(h2Client)); - this.registerServiceImplementation(ISegmentCostUIDAO.class, new SegmentCostH2UIDAO(h2Client)); + this.registerServiceImplementation(ISegmentDurationUIDAO.class, new SegmentDurationH2UIDAO(h2Client)); this.registerServiceImplementation(ISegmentUIDAO.class, new SegmentH2UIDAO(h2Client)); this.registerServiceImplementation(IServiceReferenceUIDAO.class, new ServiceReferenceH2UIDAO(h2Client)); } diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/SegmentCostH2PersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/SegmentDurationH2PersistenceDAO.java similarity index 59% rename from apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/SegmentCostH2PersistenceDAO.java rename to apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/SegmentDurationH2PersistenceDAO.java index ced4126e0..30f70f50c 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/SegmentCostH2PersistenceDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/SegmentDurationH2PersistenceDAO.java @@ -23,51 +23,51 @@ import java.util.HashMap; import java.util.Map; import org.apache.skywalking.apm.collector.client.h2.H2Client; import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.apache.skywalking.apm.collector.storage.dao.ISegmentCostPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.ISegmentDurationPersistenceDAO; import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; import org.apache.skywalking.apm.collector.storage.h2.base.define.H2SqlEntity; -import org.apache.skywalking.apm.collector.storage.table.segment.SegmentCost; -import org.apache.skywalking.apm.collector.storage.table.segment.SegmentCostTable; +import org.apache.skywalking.apm.collector.storage.table.segment.SegmentDuration; +import org.apache.skywalking.apm.collector.storage.table.segment.SegmentDurationTable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * @author peng-yongsheng, clevertension */ -public class SegmentCostH2PersistenceDAO extends H2DAO implements ISegmentCostPersistenceDAO { +public class SegmentDurationH2PersistenceDAO extends H2DAO implements ISegmentDurationPersistenceDAO { - private final Logger logger = LoggerFactory.getLogger(SegmentCostH2PersistenceDAO.class); + private final Logger logger = LoggerFactory.getLogger(SegmentDurationH2PersistenceDAO.class); - public SegmentCostH2PersistenceDAO(H2Client client) { + public SegmentDurationH2PersistenceDAO(H2Client client) { super(client); } - @Override public SegmentCost get(String id) { + @Override public SegmentDuration get(String id) { return null; } - @Override public H2SqlEntity prepareBatchInsert(SegmentCost data) { + @Override public H2SqlEntity prepareBatchInsert(SegmentDuration data) { logger.debug("segment cost prepareBatchInsert, getId: {}", data.getId()); H2SqlEntity entity = new H2SqlEntity(); Map source = new HashMap<>(); - source.put(SegmentCostTable.COLUMN_ID, data.getId()); - source.put(SegmentCostTable.COLUMN_SEGMENT_ID, data.getSegmentId()); - source.put(SegmentCostTable.COLUMN_APPLICATION_ID, data.getApplicationId()); - source.put(SegmentCostTable.COLUMN_SERVICE_NAME, data.getServiceName()); - source.put(SegmentCostTable.COLUMN_COST, data.getCost()); - source.put(SegmentCostTable.COLUMN_START_TIME, data.getStartTime()); - source.put(SegmentCostTable.COLUMN_END_TIME, data.getEndTime()); - source.put(SegmentCostTable.COLUMN_IS_ERROR, data.getIsError()); - source.put(SegmentCostTable.COLUMN_TIME_BUCKET, data.getTimeBucket()); + source.put(SegmentDurationTable.COLUMN_ID, data.getId()); + source.put(SegmentDurationTable.COLUMN_SEGMENT_ID, data.getSegmentId()); + source.put(SegmentDurationTable.COLUMN_APPLICATION_ID, data.getApplicationId()); + source.put(SegmentDurationTable.COLUMN_SERVICE_NAME, data.getServiceName()); + source.put(SegmentDurationTable.COLUMN_DURATION, data.getDuration()); + source.put(SegmentDurationTable.COLUMN_START_TIME, data.getStartTime()); + source.put(SegmentDurationTable.COLUMN_END_TIME, data.getEndTime()); + source.put(SegmentDurationTable.COLUMN_IS_ERROR, data.getIsError()); + source.put(SegmentDurationTable.COLUMN_TIME_BUCKET, data.getTimeBucket()); logger.debug("segment cost source: {}", source.toString()); - String sql = SqlBuilder.buildBatchInsertSql(SegmentCostTable.TABLE, source.keySet()); + String sql = SqlBuilder.buildBatchInsertSql(SegmentDurationTable.TABLE, source.keySet()); entity.setSql(sql); entity.setParams(source.values().toArray(new Object[0])); return entity; } - @Override public H2SqlEntity prepareBatchUpdate(SegmentCost data) { + @Override public H2SqlEntity prepareBatchUpdate(SegmentDuration data) { return null; } diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/SegmentCostH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/SegmentCostH2UIDAO.java deleted file mode 100644 index f3e0701e9..000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/SegmentCostH2UIDAO.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - - -package org.apache.skywalking.apm.collector.storage.h2.dao.ui; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import org.apache.skywalking.apm.collector.core.util.CollectionUtils; -import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.apache.skywalking.apm.collector.storage.dao.ui.ISegmentCostUIDAO; -import org.elasticsearch.search.sort.SortOrder; -import org.apache.skywalking.apm.collector.client.h2.H2Client; -import org.apache.skywalking.apm.collector.client.h2.H2ClientException; -import org.apache.skywalking.apm.collector.core.util.StringUtils; -import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.apache.skywalking.apm.collector.storage.table.segment.SegmentCostTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng, clevertension - */ -public class SegmentCostH2UIDAO extends H2DAO implements ISegmentCostUIDAO { - - private final Logger logger = LoggerFactory.getLogger(SegmentCostH2UIDAO.class); - private static final String GET_SEGMENT_COST_SQL = "select * from {0} where {1} >= ? and {1} <= ?"; - - public SegmentCostH2UIDAO(H2Client client) { - super(client); - } - - @Override public JsonObject loadTop(long startTime, long endTime, long minCost, long maxCost, String operationName, - Error error, int applicationId, List segmentIds, int limit, int from, Sort sort) { - H2Client client = getClient(); - String sql = GET_SEGMENT_COST_SQL; - List params = new ArrayList<>(); - List columns = new ArrayList<>(); - columns.add(SegmentCostTable.TABLE); - columns.add(SegmentCostTable.COLUMN_TIME_BUCKET); - params.add(startTime); - params.add(endTime); - int paramIndex = 1; - if (minCost != -1 || maxCost != -1) { - if (minCost != -1) { - paramIndex++; - sql = sql + " and {" + paramIndex + "} >= ?"; - params.add(minCost); - columns.add(SegmentCostTable.COLUMN_COST); - } - if (maxCost != -1) { - paramIndex++; - sql = sql + " and {" + paramIndex + "} <= ?"; - params.add(maxCost); - columns.add(SegmentCostTable.COLUMN_COST); - } - } - if (StringUtils.isNotEmpty(operationName)) { - paramIndex++; - sql = sql + " and {" + paramIndex + "} = ?"; - params.add(operationName); - columns.add(SegmentCostTable.COLUMN_SERVICE_NAME); - } - if (CollectionUtils.isNotEmpty(segmentIds)) { - paramIndex++; - sql = sql + " and {" + paramIndex + "} in ("; - columns.add(SegmentCostTable.COLUMN_SEGMENT_ID); - StringBuilder builder = new StringBuilder(); - for (int i = 0; i < segmentIds.size(); i++) { - builder.append("?,"); - } - builder.delete(builder.length() - 1, builder.length()); - builder.append(")"); - sql = sql + builder; - for (String segmentId : segmentIds) { - params.add(segmentId); - } - } - if (Error.True.equals(error)) { - paramIndex++; - sql = sql + " and {" + paramIndex + "} = ?"; - params.add(true); - columns.add(SegmentCostTable.COLUMN_IS_ERROR); - } else if (Error.False.equals(error)) { - paramIndex++; - sql = sql + " and {" + paramIndex + "} = ?"; - params.add(false); - columns.add(SegmentCostTable.COLUMN_IS_ERROR); - } - if (applicationId != 0) { - paramIndex++; - sql = sql + " and {" + paramIndex + "} = ?"; - params.add(applicationId); - columns.add(SegmentCostTable.COLUMN_APPLICATION_ID); - } - - if (Sort.Cost.equals(sort)) { - sql = sql + " order by " + SegmentCostTable.COLUMN_COST + " " + SortOrder.DESC; - } else if (Sort.Time.equals(sort)) { - sql = sql + " order by " + SegmentCostTable.COLUMN_START_TIME + " " + SortOrder.DESC; - } - - sql = sql + " limit " + from + "," + limit; - sql = SqlBuilder.buildSql(sql, columns); - Object[] p = params.toArray(new Object[0]); - - JsonObject topSegPaging = new JsonObject(); - - JsonArray topSegArray = new JsonArray(); - topSegPaging.add("data", topSegArray); - int cnt = 0; - int num = from; - try (ResultSet rs = client.executeQuery(sql, p)) { - while (rs.next()) { - JsonObject topSegmentJson = new JsonObject(); - topSegmentJson.addProperty("num", num); - String segmentId = rs.getString(SegmentCostTable.COLUMN_SEGMENT_ID); - topSegmentJson.addProperty(SegmentCostTable.COLUMN_SEGMENT_ID, segmentId); - topSegmentJson.addProperty(SegmentCostTable.COLUMN_START_TIME, rs.getLong(SegmentCostTable.COLUMN_START_TIME)); - topSegmentJson.addProperty(SegmentCostTable.COLUMN_END_TIME, rs.getLong(SegmentCostTable.COLUMN_END_TIME)); - topSegmentJson.addProperty(SegmentCostTable.COLUMN_APPLICATION_ID, rs.getInt(SegmentCostTable.COLUMN_APPLICATION_ID)); - topSegmentJson.addProperty(SegmentCostTable.COLUMN_SERVICE_NAME, rs.getString(SegmentCostTable.COLUMN_SERVICE_NAME)); - topSegmentJson.addProperty(SegmentCostTable.COLUMN_COST, rs.getLong(SegmentCostTable.COLUMN_COST)); - topSegmentJson.addProperty(SegmentCostTable.COLUMN_IS_ERROR, rs.getBoolean(SegmentCostTable.COLUMN_IS_ERROR)); - - num++; - topSegArray.add(topSegmentJson); - cnt++; - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - topSegPaging.addProperty("recordsTotal", cnt); - return topSegPaging; - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/SegmentDurationH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/SegmentDurationH2UIDAO.java new file mode 100644 index 000000000..a12771f73 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/SegmentDurationH2UIDAO.java @@ -0,0 +1,118 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.collector.storage.h2.dao.ui; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.apache.skywalking.apm.collector.core.util.BooleanUtils; +import org.apache.skywalking.apm.collector.core.util.StringUtils; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.ui.ISegmentDurationUIDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.table.segment.SegmentDurationTable; +import org.apache.skywalking.apm.collector.storage.ui.trace.BasicTrace; +import org.apache.skywalking.apm.collector.storage.ui.trace.TraceBrief; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng, clevertension + */ +public class SegmentDurationH2UIDAO extends H2DAO implements ISegmentDurationUIDAO { + + private final Logger logger = LoggerFactory.getLogger(SegmentDurationH2UIDAO.class); + + public SegmentDurationH2UIDAO(H2Client client) { + super(client); + } + + @Override + public TraceBrief loadTop(long startTime, long endTime, long minDuration, long maxDuration, String operationName, + int applicationId, String traceId, int limit, int from) { + H2Client client = getClient(); + String sql = "select * from {0} where {1} >= ? and {1} <= ?"; + List params = new ArrayList<>(); + List columns = new ArrayList<>(); + columns.add(SegmentDurationTable.TABLE); + columns.add(SegmentDurationTable.COLUMN_TIME_BUCKET); + params.add(startTime); + params.add(endTime); + int paramIndex = 1; + if (minDuration != -1 || maxDuration != -1) { + if (minDuration != -1) { + paramIndex++; + sql = sql + " and {" + paramIndex + "} >= ?"; + params.add(minDuration); + columns.add(SegmentDurationTable.COLUMN_DURATION); + } + if (maxDuration != -1) { + paramIndex++; + sql = sql + " and {" + paramIndex + "} <= ?"; + params.add(maxDuration); + columns.add(SegmentDurationTable.COLUMN_DURATION); + } + } + if (StringUtils.isNotEmpty(operationName)) { + paramIndex++; + sql = sql + " and {" + paramIndex + "} = ?"; + params.add(operationName); + columns.add(SegmentDurationTable.COLUMN_SERVICE_NAME); + } + if (StringUtils.isNotEmpty(traceId)) { + paramIndex++; + sql = sql + " and {" + paramIndex + "} = ?"; + params.add(traceId); + columns.add(SegmentDurationTable.COLUMN_TRACE_ID); + } + if (applicationId != 0) { + paramIndex++; + sql = sql + " and {" + paramIndex + "} = ?"; + params.add(applicationId); + columns.add(SegmentDurationTable.COLUMN_APPLICATION_ID); + } + + sql = sql + " limit " + from + "," + limit; + sql = SqlBuilder.buildSql(sql, columns); + Object[] p = params.toArray(new Object[0]); + + TraceBrief traceBrief = new TraceBrief(); + + int cnt = 0; + try (ResultSet rs = client.executeQuery(sql, p)) { + while (rs.next()) { + BasicTrace basicTrace = new BasicTrace(); + basicTrace.setDuration(rs.getInt(SegmentDurationTable.COLUMN_DURATION)); + basicTrace.setStart(rs.getLong(SegmentDurationTable.COLUMN_START_TIME)); + basicTrace.setTraceId(rs.getString(SegmentDurationTable.COLUMN_TRACE_ID)); + basicTrace.setOperationName(rs.getString(SegmentDurationTable.COLUMN_SERVICE_NAME)); + basicTrace.setError(BooleanUtils.valueToBoolean(rs.getInt(SegmentDurationTable.COLUMN_IS_ERROR))); + traceBrief.getTraces().add(basicTrace); + cnt++; + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + traceBrief.setTotal(cnt); + return traceBrief; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/SegmentCostH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/SegmentCostH2TableDefine.java deleted file mode 100644 index bc51a2d56..000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/SegmentCostH2TableDefine.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.apache.skywalking.apm.collector.storage.h2.define; - -import org.apache.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; -import org.apache.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; -import org.apache.skywalking.apm.collector.storage.table.segment.SegmentCostTable; - -/** - * @author peng-yongsheng - */ -public class SegmentCostH2TableDefine extends H2TableDefine { - - public SegmentCostH2TableDefine() { - super(SegmentCostTable.TABLE); - } - - @Override public void initialize() { - addColumn(new H2ColumnDefine(SegmentCostTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); - addColumn(new H2ColumnDefine(SegmentCostTable.COLUMN_SEGMENT_ID, H2ColumnDefine.Type.Varchar.name())); - addColumn(new H2ColumnDefine(SegmentCostTable.COLUMN_APPLICATION_ID, H2ColumnDefine.Type.Int.name())); - addColumn(new H2ColumnDefine(SegmentCostTable.COLUMN_SERVICE_NAME, H2ColumnDefine.Type.Varchar.name())); - addColumn(new H2ColumnDefine(SegmentCostTable.COLUMN_COST, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(SegmentCostTable.COLUMN_START_TIME, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(SegmentCostTable.COLUMN_END_TIME, H2ColumnDefine.Type.Bigint.name())); - addColumn(new H2ColumnDefine(SegmentCostTable.COLUMN_IS_ERROR, H2ColumnDefine.Type.Int.name())); - addColumn(new H2ColumnDefine(SegmentCostTable.COLUMN_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name())); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/SegmentDurationH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/SegmentDurationH2TableDefine.java new file mode 100644 index 000000000..1cf32d312 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/SegmentDurationH2TableDefine.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.collector.storage.h2.define; + +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2ColumnDefine; +import org.apache.skywalking.apm.collector.storage.h2.base.define.H2TableDefine; +import org.apache.skywalking.apm.collector.storage.table.segment.SegmentDurationTable; + +/** + * @author peng-yongsheng + */ +public class SegmentDurationH2TableDefine extends H2TableDefine { + + public SegmentDurationH2TableDefine() { + super(SegmentDurationTable.TABLE); + } + + @Override public void initialize() { + addColumn(new H2ColumnDefine(SegmentDurationTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); + addColumn(new H2ColumnDefine(SegmentDurationTable.COLUMN_SEGMENT_ID, H2ColumnDefine.Type.Varchar.name())); + addColumn(new H2ColumnDefine(SegmentDurationTable.COLUMN_APPLICATION_ID, H2ColumnDefine.Type.Int.name())); + addColumn(new H2ColumnDefine(SegmentDurationTable.COLUMN_SERVICE_NAME, H2ColumnDefine.Type.Varchar.name())); + addColumn(new H2ColumnDefine(SegmentDurationTable.COLUMN_TRACE_ID, H2ColumnDefine.Type.Varchar.name())); + addColumn(new H2ColumnDefine(SegmentDurationTable.COLUMN_DURATION, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(SegmentDurationTable.COLUMN_START_TIME, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(SegmentDurationTable.COLUMN_END_TIME, H2ColumnDefine.Type.Bigint.name())); + addColumn(new H2ColumnDefine(SegmentDurationTable.COLUMN_IS_ERROR, H2ColumnDefine.Type.Int.name())); + addColumn(new H2ColumnDefine(SegmentDurationTable.COLUMN_TIME_BUCKET, H2ColumnDefine.Type.Bigint.name())); + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/resources/META-INF/defines/storage.define b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/resources/META-INF/defines/storage.define index 476ac990e..b3403d961 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/resources/META-INF/defines/storage.define +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/resources/META-INF/defines/storage.define @@ -43,7 +43,7 @@ org.apache.skywalking.apm.collector.storage.h2.define.instmapping.InstanceMappin org.apache.skywalking.apm.collector.storage.h2.define.instmapping.InstanceMappingMonthH2TableDefine org.apache.skywalking.apm.collector.storage.h2.define.GlobalTraceH2TableDefine -org.apache.skywalking.apm.collector.storage.h2.define.SegmentCostH2TableDefine +org.apache.skywalking.apm.collector.storage.h2.define.SegmentDurationH2TableDefine org.apache.skywalking.apm.collector.storage.h2.define.SegmentH2TableDefine org.apache.skywalking.apm.collector.storage.h2.define.amp.ApplicationMinuteMetricH2TableDefine diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/OverViewLayerQuery.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/OverViewLayerQuery.java index 9ac853c47..6d1fa55a9 100644 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/OverViewLayerQuery.java +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/OverViewLayerQuery.java @@ -30,6 +30,7 @@ import org.apache.skywalking.apm.collector.storage.ui.overview.ConjecturalAppBri import org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo; import org.apache.skywalking.apm.collector.storage.ui.service.ServiceInfo; import org.apache.skywalking.apm.collector.ui.graphql.Query; +import org.apache.skywalking.apm.collector.ui.service.AlarmService; import org.apache.skywalking.apm.collector.ui.service.ApplicationService; import org.apache.skywalking.apm.collector.ui.service.ClusterTopologyService; import org.apache.skywalking.apm.collector.ui.service.NetworkAddressService; @@ -46,6 +47,7 @@ public class OverViewLayerQuery implements Query { private ApplicationService applicationService; private NetworkAddressService networkAddressService; private ServiceNameService serviceNameService; + private AlarmService alarmService; public OverViewLayerQuery(ModuleManager moduleManager) { this.moduleManager = moduleManager; @@ -79,6 +81,13 @@ public class OverViewLayerQuery implements Query { return serviceNameService; } + private AlarmService getAlarmService() { + if (ObjectUtils.isEmpty(alarmService)) { + this.alarmService = new AlarmService(moduleManager); + } + return alarmService; + } + public Topology getClusterTopology(Duration duration) throws ParseException { long start = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getStart()); long end = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getEnd()); @@ -99,8 +108,10 @@ public class OverViewLayerQuery implements Query { return clusterBrief; } - public AlarmTrend getAlarmTrend(Duration duration) { - return null; + public AlarmTrend getAlarmTrend(Duration duration) throws ParseException { + long start = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getStart()); + long end = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getEnd()); + return getAlarmService().getApplicationAlarmTrend(duration.getStep(), start, end); } public ConjecturalAppBrief getConjecturalApps(Duration duration) { diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/TraceQuery.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/TraceQuery.java index 32eaa7291..e77a8e59f 100644 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/TraceQuery.java +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/TraceQuery.java @@ -18,17 +18,48 @@ package org.apache.skywalking.apm.collector.ui.query; -import org.apache.skywalking.apm.collector.ui.graphql.Query; +import java.text.ParseException; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.core.util.ObjectUtils; import org.apache.skywalking.apm.collector.storage.ui.trace.Trace; import org.apache.skywalking.apm.collector.storage.ui.trace.TraceBrief; import org.apache.skywalking.apm.collector.storage.ui.trace.TraceQueryCondition; +import org.apache.skywalking.apm.collector.ui.graphql.Query; +import org.apache.skywalking.apm.collector.ui.service.SegmentTopService; +import org.apache.skywalking.apm.collector.ui.utils.DurationUtils; /** * @author peng-yongsheng */ public class TraceQuery implements Query { - public TraceBrief queryBasicTraces(TraceQueryCondition condition) { - return null; + + private final ModuleManager moduleManager; + private SegmentTopService segmentTopService; + + public TraceQuery(ModuleManager moduleManager) { + this.moduleManager = moduleManager; + } + + private SegmentTopService getSegmentTopService() { + if (ObjectUtils.isEmpty(segmentTopService)) { + this.segmentTopService = new SegmentTopService(moduleManager); + } + return segmentTopService; + } + + public TraceBrief queryBasicTraces(TraceQueryCondition condition) throws ParseException { + long start = DurationUtils.INSTANCE.durationToSecondTimeBucket(condition.getQueryDuration().getStep(), condition.getQueryDuration().getStart()); + long end = DurationUtils.INSTANCE.durationToSecondTimeBucket(condition.getQueryDuration().getStep(), condition.getQueryDuration().getEnd()); + + long minDuration = condition.getMinTraceDuration(); + long maxDuration = condition.getMaxTraceDuration(); + String operationName = condition.getOperationName(); + String traceId = condition.getTraceId(); + int applicationId = condition.getApplicationId(); + int limit = condition.getPaging().getPageSize(); + int from = condition.getPaging().getPageSize() * condition.getPaging().getPageNum(); + + return segmentTopService.loadTop(start, end, minDuration, maxDuration, operationName, traceId, applicationId, limit, from); } public Trace queryTrace(String id) { diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/AlarmService.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/AlarmService.java new file mode 100644 index 000000000..e364088f8 --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/AlarmService.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.collector.ui.service; + +import java.text.ParseException; +import java.util.List; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.storage.ui.overview.AlarmTrend; +import org.apache.skywalking.apm.collector.storage.utils.DurationPoint; +import org.apache.skywalking.apm.collector.ui.utils.DurationUtils; + +/** + * @author peng-yongsheng + */ +public class AlarmService { + + public AlarmService(ModuleManager moduleManager) { + + } + + public AlarmTrend getApplicationAlarmTrend(Step step, long start, long end) throws ParseException { + List durationPoints = DurationUtils.INSTANCE.getDurationPoints(step, start, end); + + AlarmTrend alarmTrend = new AlarmTrend(); + return alarmTrend; + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/SegmentTopService.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/SegmentTopService.java index 3d3b452f5..10173b3e6 100644 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/SegmentTopService.java +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/SegmentTopService.java @@ -16,22 +16,12 @@ * */ - package org.apache.skywalking.apm.collector.ui.service; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import java.util.LinkedList; -import java.util.List; import org.apache.skywalking.apm.collector.core.module.ModuleManager; -import org.apache.skywalking.apm.collector.core.util.CollectionUtils; -import org.apache.skywalking.apm.collector.storage.dao.ui.IGlobalTraceUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.ui.ISegmentCostUIDAO; -import org.apache.skywalking.apm.collector.storage.table.segment.SegmentCostTable; -import org.apache.skywalking.apm.collector.core.util.StringUtils; import org.apache.skywalking.apm.collector.storage.StorageModule; -import org.apache.skywalking.apm.collector.storage.table.global.GlobalTraceTable; +import org.apache.skywalking.apm.collector.storage.dao.ui.ISegmentDurationUIDAO; +import org.apache.skywalking.apm.collector.storage.ui.trace.TraceBrief; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,34 +32,16 @@ public class SegmentTopService { private final Logger logger = LoggerFactory.getLogger(SegmentTopService.class); - private final IGlobalTraceUIDAO globalTraceDAO; - private final ISegmentCostUIDAO segmentCostDAO; + private final ISegmentDurationUIDAO segmentDurationUIDAO; public SegmentTopService(ModuleManager moduleManager) { - this.globalTraceDAO = moduleManager.find(StorageModule.NAME).getService(IGlobalTraceUIDAO.class); - this.segmentCostDAO = moduleManager.find(StorageModule.NAME).getService(ISegmentCostUIDAO.class); + this.segmentDurationUIDAO = moduleManager.find(StorageModule.NAME).getService(ISegmentDurationUIDAO.class); } - public JsonObject loadTop(long startTime, long endTime, long minCost, long maxCost, String operationName, - String globalTraceId, ISegmentCostUIDAO.Error error, int applicationId, int limit, int from, - ISegmentCostUIDAO.Sort sort) { - logger.debug("startTime: {}, endTime: {}, minCost: {}, maxCost: {}, operationName: {}, globalTraceId: {}, error: {}, applicationId: {}, limit: {}, from: {}", startTime, endTime, minCost, maxCost, operationName, globalTraceId, error, applicationId, limit, from); + public TraceBrief loadTop(long startTime, long endTime, long minDuration, long maxDuration, String operationName, + String traceId, int applicationId, int limit, int from) { + logger.debug("startTime: {}, endTime: {}, minDuration: {}, maxDuration: {}, operationName: {}, traceId: {}, applicationId: {}, limit: {}, from: {}", startTime, endTime, minDuration, maxDuration, operationName, traceId, applicationId, limit, from); - List segmentIds = new LinkedList<>(); - if (StringUtils.isNotEmpty(globalTraceId)) { - segmentIds = globalTraceDAO.getSegmentIds(globalTraceId); - } - - JsonObject loadTopJsonObj = segmentCostDAO.loadTop(startTime, endTime, minCost, maxCost, operationName, error, applicationId, segmentIds, limit, from, sort); - JsonArray loadTopJsonArray = loadTopJsonObj.get("data").getAsJsonArray(); - for (JsonElement loadTopElement : loadTopJsonArray) { - JsonObject jsonObject = loadTopElement.getAsJsonObject(); - String segmentId = jsonObject.get(SegmentCostTable.COLUMN_SEGMENT_ID).getAsString(); - List globalTraces = globalTraceDAO.getGlobalTraceId(segmentId); - if (CollectionUtils.isNotEmpty(globalTraces)) { - jsonObject.addProperty(GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID, globalTraces.get(0)); - } - } - return loadTopJsonObj; + return segmentDurationUIDAO.loadTop(startTime, endTime, minDuration, maxDuration, operationName, applicationId, traceId, limit, from); } } diff --git a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/trace.graphqls b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/trace.graphqls index 0e5340899..9188cfedb 100644 --- a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/trace.graphqls +++ b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/trace.graphqls @@ -15,7 +15,8 @@ type BasicTrace { # Represent the conditions used for query TraceBrief input TraceQueryCondition { - applicationCodes: [String!] + # The value of 0 means all application. + applicationId: Int traceId: String operationName: String # The time range of traces started