diff --git a/apm-collector/apm-collector-agent/agent-grpc/agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/provider/handler/InstanceDiscoveryServiceHandler.java b/apm-collector/apm-collector-agent/agent-grpc/agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/provider/handler/InstanceDiscoveryServiceHandler.java index 682b6c410..cde3e4c69 100644 --- a/apm-collector/apm-collector-agent/agent-grpc/agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/provider/handler/InstanceDiscoveryServiceHandler.java +++ b/apm-collector/apm-collector-agent/agent-grpc/agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/provider/handler/InstanceDiscoveryServiceHandler.java @@ -26,7 +26,6 @@ import org.apache.skywalking.apm.collector.analysis.metric.define.service.IInsta import org.apache.skywalking.apm.collector.analysis.register.define.AnalysisRegisterModule; import org.apache.skywalking.apm.collector.analysis.register.define.service.IInstanceIDService; import org.apache.skywalking.apm.collector.core.module.ModuleManager; -import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; import org.apache.skywalking.apm.collector.server.grpc.GRPCHandler; import org.apache.skywalking.apm.network.proto.ApplicationInstance; import org.apache.skywalking.apm.network.proto.ApplicationInstanceHeartbeat; @@ -55,8 +54,7 @@ public class InstanceDiscoveryServiceHandler extends InstanceDiscoveryServiceGrp @Override public void registerInstance(ApplicationInstance request, StreamObserver responseObserver) { - long timeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(request.getRegisterTime()); - int instanceId = instanceIDService.getOrCreateByAgentUUID(request.getApplicationId(), request.getAgentUUID(), timeBucket, buildOsInfo(request.getOsinfo())); + int instanceId = instanceIDService.getOrCreateByAgentUUID(request.getApplicationId(), request.getAgentUUID(), request.getRegisterTime(), buildOsInfo(request.getOsinfo())); ApplicationInstanceMapping.Builder builder = ApplicationInstanceMapping.newBuilder(); builder.setApplicationId(request.getApplicationId()); builder.setApplicationInstanceId(instanceId); diff --git a/apm-collector/apm-collector-agent/agent-grpc/agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/provider/handler/NetworkAddressRegisterServiceHandler.java b/apm-collector/apm-collector-agent/agent-grpc/agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/provider/handler/NetworkAddressRegisterServiceHandler.java index a00de671c..c7b562514 100644 --- a/apm-collector/apm-collector-agent/agent-grpc/agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/provider/handler/NetworkAddressRegisterServiceHandler.java +++ b/apm-collector/apm-collector-agent/agent-grpc/agent-grpc-provider/src/main/java/org/apache/skywalking/apm/collector/agent/grpc/provider/handler/NetworkAddressRegisterServiceHandler.java @@ -50,9 +50,8 @@ public class NetworkAddressRegisterServiceHandler extends NetworkAddressRegister ProtocolStringList addressesList = request.getAddressesList(); NetworkAddressMappings.Builder builder = NetworkAddressMappings.newBuilder(); - for (int i = 0; i < addressesList.size(); i++) { - String networkAddress = addressesList.get(i); - int addressId = networkAddressIDService.getOrCreate(networkAddress); + for (String networkAddress : addressesList) { + int addressId = networkAddressIDService.get(networkAddress); if (addressId != 0) { KeyWithIntegerValue value = KeyWithIntegerValue.newBuilder().setKey(networkAddress).setValue(addressId).build(); diff --git a/apm-collector/apm-collector-agent/agent-jetty/agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/provider/handler/NetworkAddressRegisterServletHandler.java b/apm-collector/apm-collector-agent/agent-jetty/agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/provider/handler/NetworkAddressRegisterServletHandler.java index c5768e767..14dc1efe3 100644 --- a/apm-collector/apm-collector-agent/agent-jetty/agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/provider/handler/NetworkAddressRegisterServletHandler.java +++ b/apm-collector/apm-collector-agent/agent-jetty/agent-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/agent/jetty/provider/handler/NetworkAddressRegisterServletHandler.java @@ -63,7 +63,7 @@ public class NetworkAddressRegisterServletHandler extends JettyHandler { for (int i = 0; i < networkAddresses.size(); i++) { String networkAddress = networkAddresses.get(i).getAsString(); logger.debug("network address register, network address: {}", networkAddress); - int addressId = networkAddressIDService.getOrCreate(networkAddress); + int addressId = networkAddressIDService.get(networkAddress); JsonObject mapping = new JsonObject(); mapping.addProperty(ADDRESS_ID, addressId); mapping.addProperty(NETWORK_ADDRESS, networkAddress); diff --git a/apm-collector/apm-collector-agent/agent-jetty/agent-jetty-provider/src/test/resources/json/dubbox-consumer.json b/apm-collector/apm-collector-agent/agent-jetty/agent-jetty-provider/src/test/resources/json/dubbox-consumer.json index 4c80222bd..1b3958992 100644 --- a/apm-collector/apm-collector-agent/agent-jetty/agent-jetty-provider/src/test/resources/json/dubbox-consumer.json +++ b/apm-collector/apm-collector-agent/agent-jetty/agent-jetty-provider/src/test/resources/json/dubbox-consumer.json @@ -1,43 +1,33 @@ [ { - "gt": [ - [ - 230150, - 185809, - 24040000 - ] - ], + "gt": [[230150, 185809, 24040000]], //trace_id 链路编码 "sg": { - "ts": [ - 230150, - 185809, - 24040000 - ], - "ai": -1, - "ii": 2, - "rs": [], - "ss": [ + "ts": [230150, 185809, 24040000], //segment_id 一个应用中的一个实例在链路中产生的编号 + "ai": -1, //应用ID,应用启动注册时产生 + "ii": 2, //实例ID,应用启动注册时产生 + "rs": [], //链路的上下文信息,头节点,所以为空 + "ss": [ //一个埋点(手动埋点或者自动埋点) { - "si": 1, - "tv": 1, - "lv": 1, - "ps": 0, - "st": 1501858094526, - "et": 1501858097004, - "ci": 3, - "cn": "", - "oi": 0, - "on": "org.skywaking.apm.testcase.dubbo.services.GreetService.doBusiness()", - "pi": 0, - "pn": "172.25.0.4:20880", - "ie": false, - "to": [ + "si": 1, //埋点编号 + "tv": 1, //埋点类型(手动、入口、出口) + "lv": 2, //层(RPCFramework,Database,Http) + "ps": 0, //上级埋点编号 + "st": 1501858094526, //开始时间 + "et": 1501858097004, //结束时间 + "ci": 3, //组件编号(Tomcat、Mysql、Dubbo...) + "cn": "", //组件名称 + "oi": 0, //埋点的服务ID + "on": "org.skywaking.apm.testcase.dubbo.services.GreetService.doBusiness()", //埋点的服务名 + "pi": 0, //地址注册的ID,调用抓取后注册 + "pn": "172.25.0.4:20880", //地址 + "ie": false, //是否发生错误,是否有Exception + "to": [ //与链路分析关系较小的TAG,SQL也在其中 { "k": "url", "v": "rest://172.25.0.4:20880/org.skywaking.apm.testcase.dubbo.services.GreetService.doBusiness()" } ], - "lo": [] + "lo": [] //日志,与链路分析完全无关,只作为展示使用,手动埋点时可以任意追加,kv的形式,例如收集一些业务相关的信息 }, { "si": 0, diff --git a/apm-collector/apm-collector-agent/agent-jetty/agent-jetty-provider/src/test/resources/json/dubbox-provider.json b/apm-collector/apm-collector-agent/agent-jetty/agent-jetty-provider/src/test/resources/json/dubbox-provider.json index e446706f2..856cfc03c 100644 --- a/apm-collector/apm-collector-agent/agent-jetty/agent-jetty-provider/src/test/resources/json/dubbox-provider.json +++ b/apm-collector/apm-collector-agent/agent-jetty/agent-jetty-provider/src/test/resources/json/dubbox-provider.json @@ -1,18 +1,8 @@ [ { - "gt": [ - [ - 230150, - 185809, - 24040000 - ] - ], + "gt": [[230150, 185809, 24040000]], //trace_id 链路编码,与调用方相同 "sg": { - "ts": [ - 137150, - 185809, - 48780000 - ], + "ts": [137150, 185809, 48780000], //segment_id,新产生 "ai": 2, "ii": 3, "ss": [ @@ -32,21 +22,17 @@ "ie": false, "rs": [ { - "pts": [ - 230150, - 185809, - 24040000 - ], - "pii": 2, - "psp": 0, - "psi": 0, - "psn": "/dubbox-case/case/dubbox-rest", - "ni": 0, - "nn": "172.25.0.4:20880", - "eii": 2, - "esi": 0, - "esn": "/dubbox-case/case/dubbox-rest", - "rn": 0 + "pts": [230150, 185809, 24040000], //上级的segment_id 一个应用中的一个实例在链路中产生的编号 + "pii": 2, //上级的实例编号 + "psp": 1, //上级的埋点编号span_id + "psi": 0, //上级的服务编号(org.skywaking.apm.testcase.dubbo.services.GreetService.doBusiness()注册后的ID) + "psn": "/dubbox-case/case/dubbox-rest", //上级的服务名 + "ni": 0, //上级调用时使用的地址注册后的ID + "nn": "172.25.0.4:20880", //上级的地址 + "eii": 2, //入口的实例编号 + "esi": 0, //入口的服务编号 + "esn": "/dubbox-case/case/dubbox-rest", //入口的服务名词 + "rn": 0 //调用方式(CrossProcess,CrossThread) } ], "to": [ @@ -60,6 +46,23 @@ } ], "lo": [] + }, + { + "si": 1, + "tv": 1, + "lv": 1, + "ps": 0, + "st": 1501858094726, + "et": 1501858095804, + "ci": 9, + "cn": "", + "oi": 0, + "on": "mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]", + "pi": 0, + "pn": "localhost:27017", + "ie": false, + "to": [], + "lo": [] } ] } diff --git a/apm-collector/apm-collector-agent/agent-jetty/agent-jetty-provider/src/test/resources/json/instance-register-consumer.json b/apm-collector/apm-collector-agent/agent-jetty/agent-jetty-provider/src/test/resources/json/instance-register-consumer.json index 139dc5743..e2cb6e068 100644 --- a/apm-collector/apm-collector-agent/agent-jetty/agent-jetty-provider/src/test/resources/json/instance-register-consumer.json +++ b/apm-collector/apm-collector-agent/agent-jetty/agent-jetty-provider/src/test/resources/json/instance-register-consumer.json @@ -3,7 +3,12 @@ "au": "dubbox-consumer", "rt": 1501858094526, "oi": { - "any_name": "any_value", - "any_name1": "any_value1" + "osName": "MacOS XX", + "hostName": "pengys", + "processId": "1001", + "ipv4s": [ + "10.0.0.3", + "10.0.0.4" + ] } } \ No newline at end of file diff --git a/apm-collector/apm-collector-agent/agent-jetty/agent-jetty-provider/src/test/resources/json/instance-register-provider.json b/apm-collector/apm-collector-agent/agent-jetty/agent-jetty-provider/src/test/resources/json/instance-register-provider.json index 976928f9c..304de7c4f 100644 --- a/apm-collector/apm-collector-agent/agent-jetty/agent-jetty-provider/src/test/resources/json/instance-register-provider.json +++ b/apm-collector/apm-collector-agent/agent-jetty/agent-jetty-provider/src/test/resources/json/instance-register-provider.json @@ -3,7 +3,12 @@ "au": "dubbox-provider", "rt": 1501858094526, "oi": { - "any_name": "any_value", - "any_name1": "any_value1" + "osName": "MacOS X", + "hostName": "peng-yongsheng", + "processId": "1000", + "ipv4s": [ + "10.0.0.1", + "10.0.0.2" + ] } } \ No newline at end of file diff --git a/apm-collector/apm-collector-analysis/analysis-alarm/alarm-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/alarm/provider/worker/AlarmAssertWorker.java b/apm-collector/apm-collector-analysis/analysis-alarm/alarm-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/alarm/provider/worker/AlarmAssertWorker.java index c00db5644..b0d211f75 100644 --- a/apm-collector/apm-collector-analysis/analysis-alarm/alarm-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/alarm/provider/worker/AlarmAssertWorker.java +++ b/apm-collector/apm-collector-analysis/analysis-alarm/alarm-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/alarm/provider/worker/AlarmAssertWorker.java @@ -18,7 +18,7 @@ package org.apache.skywalking.apm.collector.analysis.alarm.provider.worker; -import org.apache.skywalking.apm.collector.analysis.metric.define.MetricSource; +import org.apache.skywalking.apm.collector.storage.table.MetricSource; import org.apache.skywalking.apm.collector.analysis.worker.model.base.AbstractLocalAsyncWorker; import org.apache.skywalking.apm.collector.analysis.worker.model.base.WorkerException; import org.apache.skywalking.apm.collector.core.data.StreamData; diff --git a/apm-collector/apm-collector-analysis/analysis-jvm/jvm-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/jvm/provider/service/MemoryMetricService.java b/apm-collector/apm-collector-analysis/analysis-jvm/jvm-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/jvm/provider/service/MemoryMetricService.java index 97e1d7fd0..f1fedb22e 100644 --- a/apm-collector/apm-collector-analysis/analysis-jvm/jvm-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/jvm/provider/service/MemoryMetricService.java +++ b/apm-collector/apm-collector-analysis/analysis-jvm/jvm-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/jvm/provider/service/MemoryMetricService.java @@ -47,7 +47,7 @@ public class MemoryMetricService implements IMemoryMetricService { @Override public void send(int instanceId, long timeBucket, boolean isHeap, long init, long max, long used, long committed) { - String metricId = instanceId + Const.ID_SPLIT + String.valueOf(isHeap); + String metricId = instanceId + Const.ID_SPLIT + BooleanUtils.booleanToValue(isHeap); String id = timeBucket + Const.ID_SPLIT + metricId; MemoryMetric memoryMetric = new MemoryMetric(); 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..de3545e30 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 @@ -32,8 +32,9 @@ 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 SERVICE_MAPPING_GRAPH_ID = 408; 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..80e6d31c5 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 @@ -22,35 +22,45 @@ package org.apache.skywalking.apm.collector.analysis.metric.define.graph; * @author peng-yongsheng */ public class MetricWorkerIdDefine { - public static final int SERVICE_REFERENCE_MINUTE_METRIC_AGGREGATION_WORKER_ID = 4100; - public static final int SERVICE_REFERENCE_MINUTE_METRIC_REMOTE_WORKER_ID = 4101; - public static final int SERVICE_REFERENCE_MINUTE_METRIC_PERSISTENCE_WORKER_ID = 4102; - public static final int SERVICE_REFERENCE_HOUR_METRIC_PERSISTENCE_WORKER_ID = 4103; - public static final int SERVICE_REFERENCE_HOUR_METRIC_TRANSFORM_NODE_ID = 4104; - public static final int SERVICE_REFERENCE_DAY_METRIC_PERSISTENCE_WORKER_ID = 4105; - public static final int SERVICE_REFERENCE_DAY_METRIC_TRANSFORM_NODE_ID = 4106; - public static final int SERVICE_REFERENCE_MONTH_METRIC_PERSISTENCE_WORKER_ID = 4107; - public static final int SERVICE_REFERENCE_MONTH_METRIC_TRANSFORM_NODE_ID = 4108; + public static final int SERVICE_REFERENCE_MINUTE_METRIC_AGGREGATION_WORKER_ID = 4010; + public static final int SERVICE_REFERENCE_MINUTE_METRIC_REMOTE_WORKER_ID = 4011; + public static final int SERVICE_REFERENCE_MINUTE_METRIC_PERSISTENCE_WORKER_ID = 4012; + public static final int SERVICE_REFERENCE_HOUR_METRIC_PERSISTENCE_WORKER_ID = 4013; + public static final int SERVICE_REFERENCE_HOUR_METRIC_TRANSFORM_NODE_ID = 4014; + public static final int SERVICE_REFERENCE_DAY_METRIC_PERSISTENCE_WORKER_ID = 4015; + public static final int SERVICE_REFERENCE_DAY_METRIC_TRANSFORM_NODE_ID = 4016; + public static final int SERVICE_REFERENCE_MONTH_METRIC_PERSISTENCE_WORKER_ID = 4017; + public static final int SERVICE_REFERENCE_MONTH_METRIC_TRANSFORM_NODE_ID = 4018; - public static final int INSTANCE_REFERENCE_MINUTE_METRIC_AGGREGATION_WORKER_ID = 4200; - public static final int INSTANCE_REFERENCE_MINUTE_METRIC_REMOTE_WORKER_ID = 4201; - public static final int INSTANCE_REFERENCE_MINUTE_METRIC_PERSISTENCE_WORKER_ID = 4202; - public static final int INSTANCE_REFERENCE_HOUR_METRIC_PERSISTENCE_WORKER_ID = 4203; - public static final int INSTANCE_REFERENCE_HOUR_METRIC_TRANSFORM_NODE_ID = 4204; - public static final int INSTANCE_REFERENCE_DAY_METRIC_PERSISTENCE_WORKER_ID = 4205; - public static final int INSTANCE_REFERENCE_DAY_METRIC_TRANSFORM_NODE_ID = 4206; - public static final int INSTANCE_REFERENCE_MONTH_METRIC_PERSISTENCE_WORKER_ID = 4207; - public static final int INSTANCE_REFERENCE_MONTH_METRIC_TRANSFORM_NODE_ID = 4208; + public static final int INSTANCE_REFERENCE_MINUTE_METRIC_AGGREGATION_WORKER_ID = 4020; + public static final int INSTANCE_REFERENCE_MINUTE_METRIC_REMOTE_WORKER_ID = 4021; + public static final int INSTANCE_REFERENCE_MINUTE_METRIC_PERSISTENCE_WORKER_ID = 4022; + public static final int INSTANCE_REFERENCE_HOUR_METRIC_PERSISTENCE_WORKER_ID = 4023; + public static final int INSTANCE_REFERENCE_HOUR_METRIC_TRANSFORM_NODE_ID = 4024; + public static final int INSTANCE_REFERENCE_DAY_METRIC_PERSISTENCE_WORKER_ID = 4025; + public static final int INSTANCE_REFERENCE_DAY_METRIC_TRANSFORM_NODE_ID = 4026; + public static final int INSTANCE_REFERENCE_MONTH_METRIC_PERSISTENCE_WORKER_ID = 4027; + public static final int INSTANCE_REFERENCE_MONTH_METRIC_TRANSFORM_NODE_ID = 4028; - public static final int APPLICATION_REFERENCE_MINUTE_METRIC_AGGREGATION_WORKER_ID = 4300; - public static final int APPLICATION_REFERENCE_MINUTE_METRIC_REMOTE_WORKER_ID = 4301; - public static final int APPLICATION_REFERENCE_MINUTE_METRIC_PERSISTENCE_WORKER_ID = 4302; - public static final int APPLICATION_REFERENCE_HOUR_METRIC_PERSISTENCE_WORKER_ID = 4303; - public static final int APPLICATION_REFERENCE_HOUR_METRIC_TRANSFORM_NODE_ID = 4304; - public static final int APPLICATION_REFERENCE_DAY_METRIC_PERSISTENCE_WORKER_ID = 4305; - public static final int APPLICATION_REFERENCE_DAY_METRIC_TRANSFORM_NODE_ID = 4306; - public static final int APPLICATION_REFERENCE_MONTH_METRIC_PERSISTENCE_WORKER_ID = 4307; - public static final int APPLICATION_REFERENCE_MONTH_METRIC_TRANSFORM_NODE_ID = 4308; + public static final int APPLICATION_REFERENCE_MINUTE_METRIC_AGGREGATION_WORKER_ID = 4030; + public static final int APPLICATION_REFERENCE_MINUTE_METRIC_REMOTE_WORKER_ID = 4031; + public static final int APPLICATION_REFERENCE_MINUTE_METRIC_PERSISTENCE_WORKER_ID = 4032; + public static final int APPLICATION_REFERENCE_HOUR_METRIC_PERSISTENCE_WORKER_ID = 4033; + public static final int APPLICATION_REFERENCE_HOUR_METRIC_TRANSFORM_NODE_ID = 4034; + public static final int APPLICATION_REFERENCE_DAY_METRIC_PERSISTENCE_WORKER_ID = 4035; + public static final int APPLICATION_REFERENCE_DAY_METRIC_TRANSFORM_NODE_ID = 4036; + public static final int APPLICATION_REFERENCE_MONTH_METRIC_PERSISTENCE_WORKER_ID = 4037; + public static final int APPLICATION_REFERENCE_MONTH_METRIC_TRANSFORM_NODE_ID = 4038; + + public static final int SERVICE_MAPPING_MINUTE_AGGREGATION_WORKER_ID = 4040; + public static final int SERVICE_MAPPING_MINUTE_REMOTE_WORKER_ID = 4041; + public static final int SERVICE_MAPPING_MINUTE_PERSISTENCE_WORKER_ID = 4042; + public static final int SERVICE_MAPPING_HOUR_PERSISTENCE_WORKER_ID = 4043; + public static final int SERVICE_MAPPING_HOUR_TRANSFORM_NODE_ID = 4044; + public static final int SERVICE_MAPPING_DAY_PERSISTENCE_WORKER_ID = 4045; + public static final int SERVICE_MAPPING_DAY_TRANSFORM_NODE_ID = 4046; + public static final int SERVICE_MAPPING_MONTH_PERSISTENCE_WORKER_ID = 4047; + public static final int SERVICE_MAPPING_MONTH_TRANSFORM_NODE_ID = 4048; public static final int SERVICE_MINUTE_METRIC_AGGREGATION_WORKER_ID = 4400; public static final int SERVICE_MINUTE_METRIC_REMOTE_WORKER_ID = 4401; @@ -113,7 +123,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/application/component/ApplicationComponentCopy.java b/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/application/component/ApplicationComponentCopy.java index 27cf97272..510ac814e 100644 --- a/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/application/component/ApplicationComponentCopy.java +++ b/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/application/component/ApplicationComponentCopy.java @@ -31,7 +31,7 @@ public class ApplicationComponentCopy { newApplicationComponent.setMetricId(applicationComponent.getMetricId()); newApplicationComponent.setComponentId(applicationComponent.getComponentId()); - newApplicationComponent.setPeerId(applicationComponent.getPeerId()); + newApplicationComponent.setApplicationId(applicationComponent.getApplicationId()); newApplicationComponent.setTimeBucket(newApplicationComponent.getTimeBucket()); return newApplicationComponent; } diff --git a/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/application/component/ApplicationComponentSpanListener.java b/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/application/component/ApplicationComponentSpanListener.java index 80e4c7ece..aa9ddee1b 100644 --- a/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/application/component/ApplicationComponentSpanListener.java +++ b/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/application/component/ApplicationComponentSpanListener.java @@ -27,6 +27,8 @@ import org.apache.skywalking.apm.collector.analysis.segment.parser.define.listen import org.apache.skywalking.apm.collector.analysis.segment.parser.define.listener.FirstSpanListener; import org.apache.skywalking.apm.collector.analysis.segment.parser.define.listener.SpanListener; import org.apache.skywalking.apm.collector.analysis.segment.parser.define.listener.SpanListenerFactory; +import org.apache.skywalking.apm.collector.cache.CacheModule; +import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService; import org.apache.skywalking.apm.collector.core.graph.Graph; import org.apache.skywalking.apm.collector.core.graph.GraphManager; import org.apache.skywalking.apm.collector.core.module.ModuleManager; @@ -39,17 +41,24 @@ import org.apache.skywalking.apm.collector.storage.table.application.Application */ public class ApplicationComponentSpanListener implements EntrySpanListener, ExitSpanListener, FirstSpanListener { + private final ApplicationCacheService applicationCacheService; private List applicationComponents = new ArrayList<>(); private long timeBucket; + ApplicationComponentSpanListener(ModuleManager moduleManager) { + this.applicationCacheService = moduleManager.find(CacheModule.NAME).getService(ApplicationCacheService.class); + } + @Override public void parseExit(SpanDecorator spanDecorator, int applicationId, int instanceId, String segmentId) { - String metricId = spanDecorator.getPeerId() + Const.ID_SPLIT + String.valueOf(spanDecorator.getComponentId()); + int applicationIdFromPeerId = applicationCacheService.getApplicationIdByAddressId(spanDecorator.getPeerId()); + + String metricId = applicationIdFromPeerId + Const.ID_SPLIT + String.valueOf(spanDecorator.getComponentId()); ApplicationComponent applicationComponent = new ApplicationComponent(); applicationComponent.setMetricId(metricId); applicationComponent.setComponentId(spanDecorator.getComponentId()); - applicationComponent.setPeerId(spanDecorator.getPeerId()); + applicationComponent.setApplicationId(applicationIdFromPeerId); applicationComponents.add(applicationComponent); } @@ -60,7 +69,7 @@ public class ApplicationComponentSpanListener implements EntrySpanListener, Exit ApplicationComponent applicationComponent = new ApplicationComponent(); applicationComponent.setMetricId(metricId); applicationComponent.setComponentId(spanDecorator.getComponentId()); - applicationComponent.setPeerId(applicationId); + applicationComponent.setApplicationId(applicationId); applicationComponents.add(applicationComponent); } @@ -82,7 +91,7 @@ public class ApplicationComponentSpanListener implements EntrySpanListener, Exit public static class Factory implements SpanListenerFactory { @Override public SpanListener create(ModuleManager moduleManager) { - return new ApplicationComponentSpanListener(); + return new ApplicationComponentSpanListener(moduleManager); } } } diff --git a/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/application/mapping/ApplicationMappingCopy.java b/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/application/mapping/ApplicationMappingCopy.java index aa5aad45f..3797f1d5f 100644 --- a/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/application/mapping/ApplicationMappingCopy.java +++ b/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/application/mapping/ApplicationMappingCopy.java @@ -32,7 +32,7 @@ public class ApplicationMappingCopy { newApplicationMapping.setTimeBucket(applicationMapping.getTimeBucket()); newApplicationMapping.setApplicationId(applicationMapping.getApplicationId()); - newApplicationMapping.setAddressId(applicationMapping.getAddressId()); + newApplicationMapping.setMappingApplicationId(applicationMapping.getMappingApplicationId()); return newApplicationMapping; } } diff --git a/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/application/mapping/ApplicationMappingSpanListener.java b/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/application/mapping/ApplicationMappingSpanListener.java index 9433f2d5e..eda62f9fd 100644 --- a/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/application/mapping/ApplicationMappingSpanListener.java +++ b/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/application/mapping/ApplicationMappingSpanListener.java @@ -26,6 +26,8 @@ import org.apache.skywalking.apm.collector.analysis.segment.parser.define.listen import org.apache.skywalking.apm.collector.analysis.segment.parser.define.listener.FirstSpanListener; import org.apache.skywalking.apm.collector.analysis.segment.parser.define.listener.SpanListener; import org.apache.skywalking.apm.collector.analysis.segment.parser.define.listener.SpanListenerFactory; +import org.apache.skywalking.apm.collector.cache.CacheModule; +import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService; import org.apache.skywalking.apm.collector.core.graph.Graph; import org.apache.skywalking.apm.collector.core.graph.GraphManager; import org.apache.skywalking.apm.collector.core.module.ModuleManager; @@ -42,18 +44,26 @@ public class ApplicationMappingSpanListener implements FirstSpanListener, EntryS private final Logger logger = LoggerFactory.getLogger(ApplicationMappingSpanListener.class); + private final ApplicationCacheService applicationCacheService; private List applicationMappings = new LinkedList<>(); private long timeBucket; + ApplicationMappingSpanListener(ModuleManager moduleManager) { + this.applicationCacheService = moduleManager.find(CacheModule.NAME).getService(ApplicationCacheService.class); + } + @Override public void parseEntry(SpanDecorator spanDecorator, int applicationId, int instanceId, String segmentId) { logger.debug("application mapping listener parse reference"); if (spanDecorator.getRefsCount() > 0) { for (int i = 0; i < spanDecorator.getRefsCount(); i++) { ApplicationMapping applicationMapping = new ApplicationMapping(); applicationMapping.setApplicationId(applicationId); - applicationMapping.setAddressId(spanDecorator.getRefs(i).getNetworkAddressId()); - String metricId = String.valueOf(applicationId) + Const.ID_SPLIT + String.valueOf(applicationMapping.getAddressId()); + int addressId = spanDecorator.getRefs(i).getNetworkAddressId(); + int mappingApplicationId = applicationCacheService.getApplicationIdByAddressId(addressId); + applicationMapping.setMappingApplicationId(mappingApplicationId); + + String metricId = String.valueOf(applicationId) + Const.ID_SPLIT + String.valueOf(applicationMapping.getMappingApplicationId()); applicationMapping.setMetricId(metricId); applicationMappings.add(applicationMapping); } @@ -79,7 +89,7 @@ public class ApplicationMappingSpanListener implements FirstSpanListener, EntryS public static class Factory implements SpanListenerFactory { @Override public SpanListener create(ModuleManager moduleManager) { - return new ApplicationMappingSpanListener(); + return new ApplicationMappingSpanListener(moduleManager); } } } 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 71% 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..89e13eed4 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.get(spanDecorator.getOperationNameId()).getServiceName()); } - 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-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/service/refmetric/ServiceReferenceMetricSpanListener.java b/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/service/refmetric/ServiceReferenceMetricSpanListener.java index c2b933d72..8c7d04333 100644 --- a/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/service/refmetric/ServiceReferenceMetricSpanListener.java +++ b/apm-collector/apm-collector-analysis/analysis-metric/metric-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/provider/worker/service/refmetric/ServiceReferenceMetricSpanListener.java @@ -20,7 +20,7 @@ package org.apache.skywalking.apm.collector.analysis.metric.provider.worker.serv import java.util.LinkedList; import java.util.List; -import org.apache.skywalking.apm.collector.analysis.metric.define.MetricSource; +import org.apache.skywalking.apm.collector.storage.table.MetricSource; import org.apache.skywalking.apm.collector.analysis.metric.define.graph.MetricGraphIdDefine; import org.apache.skywalking.apm.collector.analysis.segment.parser.define.decorator.ReferenceDecorator; import org.apache.skywalking.apm.collector.analysis.segment.parser.define.decorator.SpanDecorator; diff --git a/apm-collector/apm-collector-analysis/analysis-register/register-define/src/main/java/org/apache/skywalking/apm/collector/analysis/register/define/service/INetworkAddressIDService.java b/apm-collector/apm-collector-analysis/analysis-register/register-define/src/main/java/org/apache/skywalking/apm/collector/analysis/register/define/service/INetworkAddressIDService.java index 427f605bc..faa1ea16a 100644 --- a/apm-collector/apm-collector-analysis/analysis-register/register-define/src/main/java/org/apache/skywalking/apm/collector/analysis/register/define/service/INetworkAddressIDService.java +++ b/apm-collector/apm-collector-analysis/analysis-register/register-define/src/main/java/org/apache/skywalking/apm/collector/analysis/register/define/service/INetworkAddressIDService.java @@ -24,5 +24,7 @@ import org.apache.skywalking.apm.collector.core.module.Service; * @author peng-yongsheng */ public interface INetworkAddressIDService extends Service { - int getOrCreate(String networkAddress); + int create(String networkAddress, int spanLayer); + + int get(String networkAddress); } diff --git a/apm-collector/apm-collector-analysis/analysis-register/register-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/register/provider/register/NetworkAddressRegisterSerialWorker.java b/apm-collector/apm-collector-analysis/analysis-register/register-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/register/provider/register/NetworkAddressRegisterSerialWorker.java index 9ec551498..f11b7f7bf 100644 --- a/apm-collector/apm-collector-analysis/analysis-register/register-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/register/provider/register/NetworkAddressRegisterSerialWorker.java +++ b/apm-collector/apm-collector-analysis/analysis-register/register-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/register/provider/register/NetworkAddressRegisterSerialWorker.java @@ -62,6 +62,7 @@ public class NetworkAddressRegisterSerialWorker extends AbstractLocalAsyncWorker newNetworkAddress = new NetworkAddress(); newNetworkAddress.setId("-1"); newNetworkAddress.setAddressId(-1); + newNetworkAddress.setSpanLayer(networkAddress.getSpanLayer()); newNetworkAddress.setNetworkAddress(networkAddress.getNetworkAddress()); } else { int max = networkAddressRegisterDAO.getMaxNetworkAddressId(); @@ -70,6 +71,7 @@ public class NetworkAddressRegisterSerialWorker extends AbstractLocalAsyncWorker newNetworkAddress = new NetworkAddress(); newNetworkAddress.setId(String.valueOf(addressId)); newNetworkAddress.setAddressId(addressId); + newNetworkAddress.setSpanLayer(networkAddress.getSpanLayer()); newNetworkAddress.setNetworkAddress(networkAddress.getNetworkAddress()); } networkAddressRegisterDAO.save(newNetworkAddress); diff --git a/apm-collector/apm-collector-analysis/analysis-register/register-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/register/provider/service/NetworkAddressIDService.java b/apm-collector/apm-collector-analysis/analysis-register/register-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/register/provider/service/NetworkAddressIDService.java index ad5fc4c8b..bdf37b1bb 100644 --- a/apm-collector/apm-collector-analysis/analysis-register/register-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/register/provider/service/NetworkAddressIDService.java +++ b/apm-collector/apm-collector-analysis/analysis-register/register-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/register/provider/service/NetworkAddressIDService.java @@ -30,16 +30,12 @@ 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.ObjectUtils; import org.apache.skywalking.apm.collector.storage.table.register.NetworkAddress; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * @author peng-yongsheng */ public class NetworkAddressIDService implements INetworkAddressIDService { - private final Logger logger = LoggerFactory.getLogger(NetworkAddressIDService.class); - private final ModuleManager moduleManager; private NetworkAddressCacheService networkAddressCacheService; private IApplicationIDService applicationIDService; @@ -78,7 +74,7 @@ public class NetworkAddressIDService implements INetworkAddressIDService { return this.networkAddressGraph; } - @Override public int getOrCreate(String networkAddress) { + @Override public int create(String networkAddress, int spanLayer) { int addressId = getNetworkAddressCacheService().getAddressId(networkAddress); if (addressId != 0) { @@ -95,6 +91,7 @@ public class NetworkAddressIDService implements INetworkAddressIDService { NetworkAddress newNetworkAddress = new NetworkAddress(); newNetworkAddress.setId("0"); newNetworkAddress.setNetworkAddress(networkAddress); + newNetworkAddress.setSpanLayer(spanLayer); newNetworkAddress.setAddressId(0); getNetworkAddressGraph().start(newNetworkAddress); @@ -102,4 +99,8 @@ public class NetworkAddressIDService implements INetworkAddressIDService { return 0; } + + @Override public int get(String networkAddress) { + return getNetworkAddressCacheService().getAddressId(networkAddress); + } } diff --git a/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/parser/standardization/ReferenceIdExchanger.java b/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/parser/standardization/ReferenceIdExchanger.java index ccef9af41..90bcbc364 100644 --- a/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/parser/standardization/ReferenceIdExchanger.java +++ b/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/parser/standardization/ReferenceIdExchanger.java @@ -19,7 +19,6 @@ package org.apache.skywalking.apm.collector.analysis.segment.parser.provider.parser.standardization; import org.apache.skywalking.apm.collector.analysis.register.define.AnalysisRegisterModule; -import org.apache.skywalking.apm.collector.analysis.register.define.service.IApplicationIDService; import org.apache.skywalking.apm.collector.analysis.register.define.service.INetworkAddressIDService; import org.apache.skywalking.apm.collector.analysis.register.define.service.IServiceNameService; import org.apache.skywalking.apm.collector.analysis.segment.parser.define.decorator.ReferenceDecorator; @@ -39,7 +38,6 @@ public class ReferenceIdExchanger implements IdExchanger { private final Logger logger = LoggerFactory.getLogger(ReferenceIdExchanger.class); private static ReferenceIdExchanger EXCHANGER; - private final IApplicationIDService applicationIDService; private final IServiceNameService serviceNameService; private final InstanceCacheService instanceCacheService; private final INetworkAddressIDService networkAddressIDService; @@ -52,7 +50,6 @@ public class ReferenceIdExchanger implements IdExchanger { } private ReferenceIdExchanger(ModuleManager moduleManager) { - this.applicationIDService = moduleManager.find(AnalysisRegisterModule.NAME).getService(IApplicationIDService.class); this.serviceNameService = moduleManager.find(AnalysisRegisterModule.NAME).getService(IServiceNameService.class); this.networkAddressIDService = moduleManager.find(AnalysisRegisterModule.NAME).getService(INetworkAddressIDService.class); this.instanceCacheService = moduleManager.find(CacheModule.NAME).getService(InstanceCacheService.class); @@ -92,7 +89,7 @@ public class ReferenceIdExchanger implements IdExchanger { } if (standardBuilder.getNetworkAddressId() == 0 && StringUtils.isNotEmpty(standardBuilder.getNetworkAddress())) { - int networkAddressId = networkAddressIDService.getOrCreate(standardBuilder.getNetworkAddress()); + int networkAddressId = networkAddressIDService.get(standardBuilder.getNetworkAddress()); if (networkAddressId == 0) { if (logger.isDebugEnabled()) { logger.debug("network address: {} from application id: {} exchange failed", standardBuilder.getNetworkAddress(), applicationId); diff --git a/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/parser/standardization/SpanIdExchanger.java b/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/parser/standardization/SpanIdExchanger.java index 13f8d6a6d..c5389a44f 100644 --- a/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/parser/standardization/SpanIdExchanger.java +++ b/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/parser/standardization/SpanIdExchanger.java @@ -53,7 +53,7 @@ public class SpanIdExchanger implements IdExchanger { @Override public boolean exchange(SpanDecorator standardBuilder, int applicationId) { if (standardBuilder.getPeerId() == 0 && StringUtils.isNotEmpty(standardBuilder.getPeer())) { - int peerId = networkAddressIDService.getOrCreate(standardBuilder.getPeer()); + int peerId = networkAddressIDService.create(standardBuilder.getPeer(), standardBuilder.getSpanLayer().getNumber()); if (peerId == 0) { logger.debug("peer: {} in application: {} exchange failed", standardBuilder.getPeer(), applicationId); 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-cache/collector-cache-define/src/main/java/org/apache/skywalking/apm/collector/cache/service/ApplicationCacheService.java b/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/apache/skywalking/apm/collector/cache/service/ApplicationCacheService.java index 57d0c39e3..f576b2830 100644 --- a/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/apache/skywalking/apm/collector/cache/service/ApplicationCacheService.java +++ b/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/apache/skywalking/apm/collector/cache/service/ApplicationCacheService.java @@ -19,6 +19,7 @@ package org.apache.skywalking.apm.collector.cache.service; import org.apache.skywalking.apm.collector.core.module.Service; +import org.apache.skywalking.apm.collector.storage.table.register.Application; /** * @author peng-yongsheng @@ -26,7 +27,7 @@ import org.apache.skywalking.apm.collector.core.module.Service; public interface ApplicationCacheService extends Service { int getApplicationIdByCode(String applicationCode); - String getApplicationCodeById(int applicationId); + Application getApplicationById(int applicationId); int getApplicationIdByAddressId(int addressId); } diff --git a/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/apache/skywalking/apm/collector/cache/service/ServiceNameCacheService.java b/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/apache/skywalking/apm/collector/cache/service/ServiceNameCacheService.java index 0517e4d20..298a5a659 100644 --- a/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/apache/skywalking/apm/collector/cache/service/ServiceNameCacheService.java +++ b/apm-collector/apm-collector-cache/collector-cache-define/src/main/java/org/apache/skywalking/apm/collector/cache/service/ServiceNameCacheService.java @@ -16,16 +16,14 @@ * */ - package org.apache.skywalking.apm.collector.cache.service; import org.apache.skywalking.apm.collector.core.module.Service; +import org.apache.skywalking.apm.collector.storage.table.register.ServiceName; /** * @author peng-yongsheng */ public interface ServiceNameCacheService extends Service { - String get(int serviceId); - - String getSplitServiceName(String serviceName); + ServiceName get(int serviceId); } diff --git a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/ApplicationCacheGuavaService.java b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/ApplicationCacheGuavaService.java index 530378740..64480c765 100644 --- a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/ApplicationCacheGuavaService.java +++ b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/ApplicationCacheGuavaService.java @@ -22,11 +22,10 @@ import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService; import org.apache.skywalking.apm.collector.core.module.ModuleManager; -import org.apache.skywalking.apm.collector.core.util.Const; import org.apache.skywalking.apm.collector.core.util.ObjectUtils; -import org.apache.skywalking.apm.collector.core.util.StringUtils; import org.apache.skywalking.apm.collector.storage.StorageModule; import org.apache.skywalking.apm.collector.storage.dao.cache.IApplicationCacheDAO; +import org.apache.skywalking.apm.collector.storage.table.register.Application; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -70,23 +69,23 @@ public class ApplicationCacheGuavaService implements ApplicationCacheService { return applicationId; } - private final Cache idCache = CacheBuilder.newBuilder().maximumSize(1000).build(); + private final Cache applicationCache = CacheBuilder.newBuilder().maximumSize(1000).build(); - @Override public String getApplicationCodeById(int applicationId) { - String applicationCode = Const.EMPTY_STRING; + @Override public Application getApplicationById(int applicationId) { + Application application = null; try { - applicationCode = idCache.get(applicationId, () -> getApplicationCacheDAO().getApplicationCode(applicationId)); + application = applicationCache.get(applicationId, () -> getApplicationCacheDAO().getApplication(applicationId)); } catch (Throwable e) { logger.error(e.getMessage(), e); } - if (StringUtils.isEmpty(applicationCode)) { - applicationCode = getApplicationCacheDAO().getApplicationCode(applicationId); - if (StringUtils.isNotEmpty(applicationCode)) { - codeCache.put(applicationCode, applicationId); + if (ObjectUtils.isEmpty(application)) { + application = getApplicationCacheDAO().getApplication(applicationId); + if (ObjectUtils.isNotEmpty(application)) { + applicationCache.put(applicationId, application); } } - return applicationCode; + return application; } private final Cache addressIdCache = CacheBuilder.newBuilder().maximumSize(1000).build(); diff --git a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/ServiceNameCacheGuavaService.java b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/ServiceNameCacheGuavaService.java index 5aa3fd80e..528dbd6f0 100644 --- a/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/ServiceNameCacheGuavaService.java +++ b/apm-collector/apm-collector-cache/collector-cache-guava-provider/src/main/java/org/apache/skywalking/apm/collector/cache/guava/service/ServiceNameCacheGuavaService.java @@ -16,18 +16,16 @@ * */ - package org.apache.skywalking.apm.collector.cache.guava.service; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; -import org.apache.skywalking.apm.collector.core.module.ModuleManager; -import org.apache.skywalking.apm.collector.core.util.Const; -import org.apache.skywalking.apm.collector.core.util.ObjectUtils; import org.apache.skywalking.apm.collector.cache.service.ServiceNameCacheService; -import org.apache.skywalking.apm.collector.core.util.StringUtils; +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.StorageModule; import org.apache.skywalking.apm.collector.storage.dao.cache.IServiceNameCacheDAO; +import org.apache.skywalking.apm.collector.storage.table.register.ServiceName; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,7 +36,7 @@ public class ServiceNameCacheGuavaService implements ServiceNameCacheService { private final Logger logger = LoggerFactory.getLogger(ServiceNameCacheGuavaService.class); - private final Cache serviceNameCache = CacheBuilder.newBuilder().maximumSize(10000).build(); + private final Cache serviceCache = CacheBuilder.newBuilder().maximumSize(10000).build(); private final ModuleManager moduleManager; private IServiceNameCacheDAO serviceNameCacheDAO; @@ -54,34 +52,21 @@ public class ServiceNameCacheGuavaService implements ServiceNameCacheService { return this.serviceNameCacheDAO; } - public String get(int serviceId) { - String serviceName = Const.EMPTY_STRING; + public ServiceName get(int serviceId) { + ServiceName serviceName = null; try { - serviceName = serviceNameCache.get(serviceId, () -> getServiceNameCacheDAO().getServiceName(serviceId)); + serviceName = serviceCache.get(serviceId, () -> getServiceNameCacheDAO().get(serviceId)); } catch (Throwable e) { logger.error(e.getMessage(), e); } - if (StringUtils.isEmpty(serviceName)) { - serviceName = getServiceNameCacheDAO().getServiceName(serviceId); - if (StringUtils.isNotEmpty(serviceName)) { - serviceNameCache.put(serviceId, serviceName); + if (ObjectUtils.isEmpty(serviceName)) { + serviceName = getServiceNameCacheDAO().get(serviceId); + if (ObjectUtils.isNotEmpty(serviceName)) { + serviceCache.put(serviceId, serviceName); } } return serviceName; } - - public String getSplitServiceName(String serviceName) { - if (StringUtils.isNotEmpty(serviceName)) { - String[] serviceNames = serviceName.split(Const.ID_SPLIT, 2); - if (serviceNames.length == 2) { - return serviceNames[1]; - } else { - return Const.EMPTY_STRING; - } - } else { - return Const.EMPTY_STRING; - } - } } diff --git a/apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/jetty/JettyHandler.java b/apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/jetty/JettyHandler.java index 5113e666b..15520fc42 100644 --- a/apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/jetty/JettyHandler.java +++ b/apm-collector/apm-collector-component/server-component/src/main/java/org/apache/skywalking/apm/collector/server/jetty/JettyHandler.java @@ -16,7 +16,6 @@ * */ - package org.apache.skywalking.apm.collector.server.jetty; import com.google.gson.JsonElement; @@ -33,35 +32,47 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.skywalking.apm.collector.core.util.ObjectUtils; import org.apache.skywalking.apm.collector.server.ServerHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author peng-yongsheng */ public abstract class JettyHandler extends HttpServlet implements ServerHandler { + private final Logger logger = LoggerFactory.getLogger(JettyHandler.class); + public abstract String pathSpec(); @Override - protected final void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + protected final void doGet(HttpServletRequest req, HttpServletResponse resp) { try { reply(resp, doGet(req)); - } catch (ArgumentsParseException e) { - replyError(resp, e.getMessage(), HttpServletResponse.SC_BAD_REQUEST); + } catch (ArgumentsParseException | IOException e) { + try { + replyError(resp, e.getMessage(), HttpServletResponse.SC_BAD_REQUEST); + } catch (IOException replyException) { + logger.error(replyException.getMessage(), e); + } } } protected abstract JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException; @Override - protected final void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + protected final void doPost(HttpServletRequest req, HttpServletResponse resp) { try { reply(resp, doPost(req)); - } catch (ArgumentsParseException e) { - replyError(resp, e.getMessage(), HttpServletResponse.SC_BAD_REQUEST); + } catch (ArgumentsParseException | IOException e) { + try { + replyError(resp, e.getMessage(), HttpServletResponse.SC_BAD_REQUEST); + } catch (IOException replyException) { + logger.error(replyException.getMessage(), e); + } } } - protected abstract JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException; + protected abstract JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException, IOException; @Override protected final void doHead(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { @@ -150,7 +161,7 @@ public abstract class JettyHandler extends HttpServlet implements ServerHandler } private void reply(HttpServletResponse response, JsonElement resJson) throws IOException { - response.setContentType("text/json"); + response.setContentType("application/json"); response.setCharacterEncoding("utf-8"); response.setStatus(HttpServletResponse.SC_OK); @@ -163,7 +174,7 @@ public abstract class JettyHandler extends HttpServlet implements ServerHandler } private void replyError(HttpServletResponse response, String errorMessage, int status) throws IOException { - response.setContentType("text/plain"); + response.setContentType("application/json"); response.setCharacterEncoding("utf-8"); response.setStatus(status); response.setHeader("error-message", errorMessage); diff --git a/apm-collector/apm-collector-core/pom.xml b/apm-collector/apm-collector-core/pom.xml index 8873a68fe..aef472f42 100644 --- a/apm-collector/apm-collector-core/pom.xml +++ b/apm-collector/apm-collector-core/pom.xml @@ -36,5 +36,10 @@ gson 2.8.1 + + joda-time + joda-time + 2.9.9 + diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/BooleanUtils.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/BooleanUtils.java index 24341aea0..14a767cfc 100644 --- a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/BooleanUtils.java +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/BooleanUtils.java @@ -25,20 +25,20 @@ import org.apache.skywalking.apm.collector.core.UnexpectedException; */ public class BooleanUtils { - public static final Integer TRUE = 1; - public static final Integer FALSE = 0; + public static final int TRUE = 1; + public static final int FALSE = 0; - public static boolean valueToBoolean(Integer value) { - if (TRUE.equals(value)) { + public static boolean valueToBoolean(int value) { + if (TRUE == value) { return true; - } else if (FALSE.equals(value)) { + } else if (FALSE == value) { return false; } else { throw new UnexpectedException("Boolean value error, must be 0 or 1"); } } - public static Integer booleanToValue(Boolean booleanValue) { + public static int booleanToValue(Boolean booleanValue) { if (booleanValue) { return TRUE; } else { diff --git a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/TimeBucketUtils.java b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/TimeBucketUtils.java index f14c4c677..9597231b3 100644 --- a/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/TimeBucketUtils.java +++ b/apm-collector/apm-collector-core/src/main/java/org/apache/skywalking/apm/collector/core/util/TimeBucketUtils.java @@ -20,8 +20,6 @@ package org.apache.skywalking.apm.collector.core.util; import java.text.SimpleDateFormat; import java.util.Calendar; -import java.util.TimeZone; -import org.apache.skywalking.apm.collector.core.UnexpectedException; /** * @author peng-yongsheng @@ -89,65 +87,7 @@ public enum TimeBucketUtils { return secondBucket / 100 / 100 / 100 / 100; } - public long changeTimeBucket2TimeStamp(String timeBucketType, long timeBucket) { - if (TimeBucketType.SECOND.name().toLowerCase().equals(timeBucketType.toLowerCase())) { - Calendar calendar = Calendar.getInstance(); - calendar.set(Calendar.YEAR, Integer.valueOf(String.valueOf(timeBucket).substring(0, 4))); - calendar.set(Calendar.MONTH, Integer.valueOf(String.valueOf(timeBucket).substring(4, 6)) - 1); - calendar.set(Calendar.DAY_OF_MONTH, Integer.valueOf(String.valueOf(timeBucket).substring(6, 8))); - calendar.set(Calendar.HOUR_OF_DAY, Integer.valueOf(String.valueOf(timeBucket).substring(8, 10))); - calendar.set(Calendar.MINUTE, Integer.valueOf(String.valueOf(timeBucket).substring(10, 12))); - calendar.set(Calendar.SECOND, Integer.valueOf(String.valueOf(timeBucket).substring(12, 14))); - return calendar.getTimeInMillis(); - } else if (TimeBucketType.MINUTE.name().toLowerCase().equals(timeBucketType.toLowerCase())) { - Calendar calendar = Calendar.getInstance(); - calendar.set(Calendar.YEAR, Integer.valueOf(String.valueOf(timeBucket).substring(0, 4))); - calendar.set(Calendar.MONTH, Integer.valueOf(String.valueOf(timeBucket).substring(4, 6)) - 1); - calendar.set(Calendar.DAY_OF_MONTH, Integer.valueOf(String.valueOf(timeBucket).substring(6, 8))); - calendar.set(Calendar.HOUR_OF_DAY, Integer.valueOf(String.valueOf(timeBucket).substring(8, 10))); - calendar.set(Calendar.MINUTE, Integer.valueOf(String.valueOf(timeBucket).substring(10, 12))); - return calendar.getTimeInMillis(); - } else { - throw new UnexpectedException("time bucket type must be second or minute"); - } - } - - public long[] getFiveSecondTimeBuckets(long secondTimeBucket) { - long timeStamp = changeTimeBucket2TimeStamp(TimeBucketType.SECOND.name(), secondTimeBucket); - Calendar calendar = Calendar.getInstance(); - calendar.setTimeInMillis(timeStamp); - - long[] timeBuckets = new long[5]; - timeBuckets[0] = secondTimeBucket; - for (int i = 0; i < 4; i++) { - calendar.add(Calendar.SECOND, -1); - timeBuckets[i + 1] = getSecondTimeBucket(calendar.getTimeInMillis()); - } - return timeBuckets; - } - - public long changeToUTCTimeBucket(long timeBucket) { - String timeBucketStr = String.valueOf(timeBucket); - - if (TimeZone.getDefault().getID().equals("GMT+08:00") || timeBucketStr.endsWith("0000")) { - return timeBucket; - } else { - return timeBucket - 800; - } - } - - public long addSecondForSecondTimeBucket(String timeBucketType, long timeBucket, int second) { - if (!TimeBucketType.SECOND.name().equals(timeBucketType)) { - throw new UnexpectedException("time bucket type must be second "); - } - Calendar calendar = Calendar.getInstance(); - calendar.setTimeInMillis(changeTimeBucket2TimeStamp(timeBucketType, timeBucket)); - calendar.add(Calendar.SECOND, second); - - return getSecondTimeBucket(calendar.getTimeInMillis()); - } - public enum TimeBucketType { - SECOND, MINUTE, HOUR, DAY + SECOND, MINUTE, HOUR, DAY, MONTH } } diff --git a/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/util/TimeBucketUtilsTest.java b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/util/TimeBucketUtilsTest.java index 35f8d2276..dcc659980 100644 --- a/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/util/TimeBucketUtilsTest.java +++ b/apm-collector/apm-collector-core/src/test/java/org/apache/skywalking/apm/collector/core/util/TimeBucketUtilsTest.java @@ -16,14 +16,10 @@ * */ - package org.apache.skywalking.apm.collector.core.util; import java.util.TimeZone; -import org.junit.After; -import org.junit.Assert; import org.junit.Before; -import org.junit.Test; /** * @author wu-sheng @@ -33,25 +29,4 @@ public class TimeBucketUtilsTest { public void setup() { TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai")); } - - @After - public void teardown() { - - } - - @Test - public void testGetInfoFromATimestamp() { - long timeMillis = 1509521745220L; - Assert.assertArrayEquals(new long[] { - 20171101153545L, - 20171101153544L, - 20171101153543L, - 20171101153542L, - 20171101153541L - }, TimeBucketUtils.INSTANCE.getFiveSecondTimeBuckets(TimeBucketUtils.INSTANCE.getSecondTimeBucket(timeMillis))); - Assert.assertEquals(20171101153545L, TimeBucketUtils.INSTANCE.getSecondTimeBucket(timeMillis)); - Assert.assertEquals(201711011535L, TimeBucketUtils.INSTANCE.getMinuteTimeBucket(timeMillis)); - Assert.assertEquals(201711011500L, TimeBucketUtils.INSTANCE.getHourTimeBucket(timeMillis)); - Assert.assertEquals(201711010000L, TimeBucketUtils.INSTANCE.getDayTimeBucket(timeMillis)); - } } 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 769b8154f..b2230b947 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 @@ -22,23 +22,10 @@ import java.util.ArrayList; import java.util.List; 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.IApplicationComponentUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.IApplicationMappingUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.ICpuMetricUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.IGCMetricUIDAO; import org.apache.skywalking.apm.collector.storage.dao.IGlobalTracePersistenceDAO; -import org.apache.skywalking.apm.collector.storage.dao.IGlobalTraceUIDAO; import org.apache.skywalking.apm.collector.storage.dao.IInstanceHeartBeatPersistenceDAO; -import org.apache.skywalking.apm.collector.storage.dao.IInstanceMetricUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.IInstanceUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.IMemoryMetricUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.IMemoryPoolMetricUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.ISegmentCostPersistenceDAO; -import org.apache.skywalking.apm.collector.storage.dao.ISegmentCostUIDAO; +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.ISegmentUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.IServiceReferenceUIDAO; import org.apache.skywalking.apm.collector.storage.dao.acp.IApplicationComponentDayPersistenceDAO; import org.apache.skywalking.apm.collector.storage.dao.acp.IApplicationComponentHourPersistenceDAO; import org.apache.skywalking.apm.collector.storage.dao.acp.IApplicationComponentMinutePersistenceDAO; @@ -115,6 +102,22 @@ import org.apache.skywalking.apm.collector.storage.dao.srmp.IServiceReferenceDay import org.apache.skywalking.apm.collector.storage.dao.srmp.IServiceReferenceHourMetricPersistenceDAO; import org.apache.skywalking.apm.collector.storage.dao.srmp.IServiceReferenceMinuteMetricPersistenceDAO; import org.apache.skywalking.apm.collector.storage.dao.srmp.IServiceReferenceMonthMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationComponentUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMappingUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationReferenceMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.ICpuMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IGCMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IGlobalTraceUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceMetricUIDAO; +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.ISegmentDurationUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.ISegmentUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceNameServiceUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceReferenceMetricUIDAO; /** * @author peng-yongsheng @@ -195,7 +198,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); @@ -232,6 +235,9 @@ public class StorageModule extends Module { private void addUiDAO(List classes) { classes.add(IInstanceUIDAO.class); + classes.add(INetworkAddressUIDAO.class); + classes.add(IServiceNameServiceUIDAO.class); + classes.add(IServiceMetricUIDAO.class); classes.add(ICpuMetricUIDAO.class); classes.add(IGCMetricUIDAO.class); @@ -243,9 +249,9 @@ 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); + classes.add(IServiceReferenceMetricUIDAO.class); } private void addAlarmDAO(List classes) { diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceMetricUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceMetricUIDAO.java deleted file mode 100644 index e1b1d850b..000000000 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceMetricUIDAO.java +++ /dev/null @@ -1,61 +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.dao; - -import com.google.gson.JsonArray; -import org.apache.skywalking.apm.collector.storage.base.dao.DAO; - -/** - * @author peng-yongsheng - */ -public interface IInstanceMetricUIDAO extends DAO { - InstanceMetric get(long[] timeBuckets, int instanceId); - - long getTpsMetric(int instanceId, long timeBucket); - - JsonArray getTpsMetric(int instanceId, long startTimeBucket, long endTimeBucket); - - long getRespTimeMetric(int instanceId, long timeBucket); - - JsonArray getRespTimeMetric(int instanceId, long startTimeBucket, long endTimeBucket); - - class InstanceMetric { - private final int instanceId; - private final long calls; - private final long durationSum; - - public InstanceMetric(int instanceId, long calls, long durationSum) { - this.instanceId = instanceId; - this.calls = calls; - this.durationSum = durationSum; - } - - public int getInstanceId() { - return instanceId; - } - - public long getCalls() { - return calls; - } - - public long getDurationSum() { - return durationSum; - } - } -} 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/cache/IApplicationCacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/cache/IApplicationCacheDAO.java index 3b766ef99..972f22905 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/cache/IApplicationCacheDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/cache/IApplicationCacheDAO.java @@ -19,6 +19,7 @@ package org.apache.skywalking.apm.collector.storage.dao.cache; import org.apache.skywalking.apm.collector.storage.base.dao.DAO; +import org.apache.skywalking.apm.collector.storage.table.register.Application; /** * @author peng-yongsheng @@ -26,7 +27,7 @@ import org.apache.skywalking.apm.collector.storage.base.dao.DAO; public interface IApplicationCacheDAO extends DAO { int getApplicationIdByCode(String applicationCode); - String getApplicationCode(int applicationId); + Application getApplication(int applicationId); int getApplicationIdByAddressId(int addressId); } diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/cache/IServiceNameCacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/cache/IServiceNameCacheDAO.java index 9e9ba334b..d9b34d828 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/cache/IServiceNameCacheDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/cache/IServiceNameCacheDAO.java @@ -19,12 +19,13 @@ package org.apache.skywalking.apm.collector.storage.dao.cache; import org.apache.skywalking.apm.collector.storage.base.dao.DAO; +import org.apache.skywalking.apm.collector.storage.table.register.ServiceName; /** * @author peng-yongsheng */ public interface IServiceNameCacheDAO extends DAO { - String getServiceName(int serviceId); + ServiceName get(int serviceId); int getServiceId(int applicationId, String serviceName); } diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IApplicationComponentUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IApplicationComponentUIDAO.java new file mode 100644 index 000000000..cfcf1dfb2 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IApplicationComponentUIDAO.java @@ -0,0 +1,52 @@ +/* + * 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.dao.ui; + +import java.util.List; +import org.apache.skywalking.apm.collector.storage.base.dao.DAO; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; + +/** + * @author peng-yongsheng + */ +public interface IApplicationComponentUIDAO extends DAO { + + List load(Step step, long startTime, long endTime); + + class ApplicationComponent { + private int componentId; + private int applicationId; + + public int getComponentId() { + return componentId; + } + + public void setComponentId(int componentId) { + this.componentId = componentId; + } + + public int getApplicationId() { + return applicationId; + } + + public void setApplicationId(int applicationId) { + this.applicationId = applicationId; + } + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IGCMetricUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IApplicationMappingUIDAO.java similarity index 53% rename from apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IGCMetricUIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IApplicationMappingUIDAO.java index 823a0f20a..d98ca7339 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IGCMetricUIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IApplicationMappingUIDAO.java @@ -16,49 +16,36 @@ * */ -package org.apache.skywalking.apm.collector.storage.dao; +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.common.Step; /** * @author peng-yongsheng */ -public interface IGCMetricUIDAO extends DAO { +public interface IApplicationMappingUIDAO extends DAO { + List load(Step step, long startTime, long endTime); - GCCount getGCCount(long[] timeBuckets, int instanceId); + class ApplicationMapping { + private int applicationId; + private int mappingApplicationId; - JsonObject getMetric(int instanceId, long timeBucket); - - JsonObject getMetric(int instanceId, long startTimeBucket, long endTimeBucket); - - class GCCount { - private int young; - private int old; - private int full; - - public int getYoung() { - return young; + public int getApplicationId() { + return applicationId; } - public int getOld() { - return old; + public void setApplicationId(int applicationId) { + this.applicationId = applicationId; } - public int getFull() { - return full; + public int getMappingApplicationId() { + return mappingApplicationId; } - public void setYoung(int young) { - this.young = young; - } - - public void setOld(int old) { - this.old = old; - } - - public void setFull(int full) { - this.full = full; + public void setMappingApplicationId(int mappingApplicationId) { + this.mappingApplicationId = mappingApplicationId; } } } diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IApplicationReferenceMetricUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IApplicationReferenceMetricUIDAO.java new file mode 100644 index 000000000..64c984c71 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IApplicationReferenceMetricUIDAO.java @@ -0,0 +1,38 @@ +/* + * 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.dao.ui; + +import java.util.List; +import org.apache.skywalking.apm.collector.storage.base.dao.DAO; +import org.apache.skywalking.apm.collector.storage.table.MetricSource; +import org.apache.skywalking.apm.collector.storage.ui.common.Call; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; + +/** + * @author peng-yongsheng + */ +public interface IApplicationReferenceMetricUIDAO extends DAO { + List getFrontApplications(Step step, int applicationId, long startTime, long endTime, + MetricSource metricSource); + + List getBehindApplications(Step step, int applicationId, long startTime, long endTime, + MetricSource metricSource); + + List getApplications(Step step, long startTime, long endTime, MetricSource metricSource); +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ICpuMetricUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/ICpuMetricUIDAO.java similarity index 75% rename from apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ICpuMetricUIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/ICpuMetricUIDAO.java index e1d3f9672..30c5f4ce3 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ICpuMetricUIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/ICpuMetricUIDAO.java @@ -16,16 +16,16 @@ * */ -package org.apache.skywalking.apm.collector.storage.dao; +package org.apache.skywalking.apm.collector.storage.dao.ui; -import com.google.gson.JsonArray; +import java.util.List; import org.apache.skywalking.apm.collector.storage.base.dao.DAO; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.storage.utils.DurationPoint; /** * @author peng-yongsheng */ public interface ICpuMetricUIDAO extends DAO { - int getMetric(int instanceId, long timeBucket); - - JsonArray getMetric(int instanceId, long startTimeBucket, long endTimeBucket); + List getCPUTrend(int instanceId, Step step, List durationPoints); } diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ISegmentCostUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IGCMetricUIDAO.java similarity index 68% rename from apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ISegmentCostUIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IGCMetricUIDAO.java index 101cf3715..062ee6814 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ISegmentCostUIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IGCMetricUIDAO.java @@ -16,24 +16,18 @@ * */ -package org.apache.skywalking.apm.collector.storage.dao; +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.common.Step; +import org.apache.skywalking.apm.collector.storage.utils.DurationPoint; /** * @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); +public interface IGCMetricUIDAO extends DAO { + List getYoungGCTrend(int instanceId, Step step, List durationPoints); - enum Sort { - Cost, Time - } - - enum Error { - All, True, False - } + List getOldGCTrend(int instanceId, Step step, List durationPoints); } diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IGlobalTraceUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IGlobalTraceUIDAO.java similarity index 94% rename from apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IGlobalTraceUIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IGlobalTraceUIDAO.java index 731c8bbb6..9a95a81b3 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IGlobalTraceUIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IGlobalTraceUIDAO.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.collector.storage.dao; +package org.apache.skywalking.apm.collector.storage.dao.ui; import java.util.List; import org.apache.skywalking.apm.collector.storage.base.dao.DAO; diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IInstanceMetricUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IInstanceMetricUIDAO.java new file mode 100644 index 000000000..0e605ae67 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IInstanceMetricUIDAO.java @@ -0,0 +1,40 @@ +/* + * 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.dao.ui; + +import java.util.List; +import org.apache.skywalking.apm.collector.storage.base.dao.DAO; +import org.apache.skywalking.apm.collector.storage.table.MetricSource; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo; +import org.apache.skywalking.apm.collector.storage.utils.DurationPoint; + +/** + * @author peng-yongsheng + */ +public interface IInstanceMetricUIDAO extends DAO { + + List getTopNServerThroughput(int applicationId, Step step, long start, long end, long secondBetween, + int topN, + MetricSource metricSource); + + List getServerTPSTrend(int instanceId, Step step, List durationPoints); + + List getResponseTimeTrend(int instanceId, Step step, List durationPoints); +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IInstanceUIDAO.java similarity index 65% rename from apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceUIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IInstanceUIDAO.java index be7fe7e14..2f713e654 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IInstanceUIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IInstanceUIDAO.java @@ -16,12 +16,13 @@ * */ -package org.apache.skywalking.apm.collector.storage.dao; +package org.apache.skywalking.apm.collector.storage.dao.ui; -import com.google.gson.JsonArray; import java.util.List; import org.apache.skywalking.apm.collector.storage.base.dao.DAO; import org.apache.skywalking.apm.collector.storage.table.register.Instance; +import org.apache.skywalking.apm.collector.storage.ui.application.Application; +import org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo; /** * @author peng-yongsheng @@ -31,27 +32,11 @@ public interface IInstanceUIDAO extends DAO { Long instanceLastHeartBeatTime(long applicationInstanceId); - JsonArray getApplications(long startTime, long endTime); + List getApplications(long startTime, long endTime, int... applicationIds); Instance getInstance(int instanceId); - List getInstances(int applicationId, long timeBucket); + List searchServer(String keyword, long start, long end); - class Application { - private final int applicationId; - private final long count; - - public Application(int applicationId, long count) { - this.applicationId = applicationId; - this.count = count; - } - - public int getApplicationId() { - return applicationId; - } - - public long getCount() { - return count; - } - } + List getAllServer(int applicationId, long start, long end); } diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IMemoryMetricUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IMemoryMetricUIDAO.java new file mode 100644 index 000000000..e1da59f8b --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IMemoryMetricUIDAO.java @@ -0,0 +1,60 @@ +/* + * 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.dao.ui; + +import java.util.LinkedList; +import java.util.List; +import org.apache.skywalking.apm.collector.storage.base.dao.DAO; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.storage.utils.DurationPoint; + +/** + * @author peng-yongsheng + */ +public interface IMemoryMetricUIDAO extends DAO { + Trend getHeapMemoryTrend(int instanceId, Step step, List durationPoints); + + Trend getNoHeapMemoryTrend(int instanceId, Step step, List durationPoints); + + class Trend { + private List metrics; + private List maxMetrics; + + public Trend() { + this.metrics = new LinkedList<>(); + this.maxMetrics = new LinkedList<>(); + } + + public List getMetrics() { + return metrics; + } + + public void setMetrics(List metrics) { + this.metrics = metrics; + } + + public List getMaxMetrics() { + return maxMetrics; + } + + public void setMaxMetrics(List maxMetrics) { + this.maxMetrics = maxMetrics; + } + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IMemoryPoolMetricUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IMemoryPoolMetricUIDAO.java similarity index 95% rename from apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IMemoryPoolMetricUIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IMemoryPoolMetricUIDAO.java index 2c09d124a..f643299b8 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IMemoryPoolMetricUIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IMemoryPoolMetricUIDAO.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.collector.storage.dao; +package org.apache.skywalking.apm.collector.storage.dao.ui; import com.google.gson.JsonObject; import org.apache.skywalking.apm.collector.storage.base.dao.DAO; diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationMappingUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/INetworkAddressUIDAO.java similarity index 82% rename from apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationMappingUIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/INetworkAddressUIDAO.java index 5f8e454a4..7ec591128 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationMappingUIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/INetworkAddressUIDAO.java @@ -16,14 +16,13 @@ * */ -package org.apache.skywalking.apm.collector.storage.dao; +package org.apache.skywalking.apm.collector.storage.dao.ui; -import com.google.gson.JsonArray; import org.apache.skywalking.apm.collector.storage.base.dao.DAO; /** * @author peng-yongsheng */ -public interface IApplicationMappingUIDAO extends DAO { - JsonArray load(long startTime, long endTime); +public interface INetworkAddressUIDAO extends DAO { + int getNumOfSpanLayer(int spanLayer); } diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IMemoryMetricUIDAO.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 71% rename from apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IMemoryMetricUIDAO.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 d2932f314..a1660a417 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IMemoryMetricUIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/ISegmentDurationUIDAO.java @@ -16,16 +16,15 @@ * */ -package org.apache.skywalking.apm.collector.storage.dao; +package org.apache.skywalking.apm.collector.storage.dao.ui; -import com.google.gson.JsonObject; 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 IMemoryMetricUIDAO extends DAO { - JsonObject getMetric(int instanceId, long timeBucket, boolean isHeap); - - JsonObject getMetric(int instanceId, long startTimeBucket, long endTimeBucket, boolean isHeap); +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/dao/ISegmentUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/ISegmentUIDAO.java similarity index 94% rename from apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ISegmentUIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/ISegmentUIDAO.java index ba10c4ddb..4dbd59768 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ISegmentUIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/ISegmentUIDAO.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.collector.storage.dao; +package org.apache.skywalking.apm.collector.storage.dao.ui; import org.apache.skywalking.apm.collector.storage.base.dao.DAO; import org.apache.skywalking.apm.network.proto.TraceSegmentObject; diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IServiceMetricUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IServiceMetricUIDAO.java new file mode 100644 index 000000000..0ca4c752a --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IServiceMetricUIDAO.java @@ -0,0 +1,43 @@ +/* + * 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.dao.ui; + +import java.util.Collection; +import java.util.List; +import org.apache.skywalking.apm.collector.storage.base.dao.DAO; +import org.apache.skywalking.apm.collector.storage.table.MetricSource; +import org.apache.skywalking.apm.collector.storage.ui.common.Node; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric; +import org.apache.skywalking.apm.collector.storage.utils.DurationPoint; + +/** + * @author peng-yongsheng + */ +public interface IServiceMetricUIDAO extends DAO { + List getServiceResponseTimeTrend(int serviceId, Step step, List durationPoints); + + List getServiceSLATrend(int serviceId, Step step, List durationPoints); + + List getServicesMetric(Step step, long startTime, long endTime, + MetricSource metricSource, Collection serviceIds); + + List getSlowService(int applicationId, Step step, long start, long end, + Integer top, MetricSource metricSource); +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IServiceReferenceUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IServiceNameServiceUIDAO.java similarity index 75% rename from apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IServiceReferenceUIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IServiceNameServiceUIDAO.java index 1ba320d82..0d8fe4859 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IServiceReferenceUIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IServiceNameServiceUIDAO.java @@ -16,15 +16,17 @@ * */ -package org.apache.skywalking.apm.collector.storage.dao; +package org.apache.skywalking.apm.collector.storage.dao.ui; -import com.google.gson.JsonObject; -import java.util.Map; +import java.util.List; import org.apache.skywalking.apm.collector.storage.base.dao.DAO; +import org.apache.skywalking.apm.collector.storage.ui.service.ServiceInfo; /** * @author peng-yongsheng */ -public interface IServiceReferenceUIDAO extends DAO { - Map load(int entryServiceId, long startTime, long endTime); +public interface IServiceNameServiceUIDAO extends DAO { + int getCount(); + + List searchService(String keyword, int topN); } diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IServiceReferenceMetricUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IServiceReferenceMetricUIDAO.java new file mode 100644 index 000000000..8aba521d2 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IServiceReferenceMetricUIDAO.java @@ -0,0 +1,43 @@ +/* + * 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.dao.ui; + +import java.util.List; +import org.apache.skywalking.apm.collector.storage.base.dao.DAO; +import org.apache.skywalking.apm.collector.storage.table.MetricSource; +import org.apache.skywalking.apm.collector.storage.ui.common.Call; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; + +/** + * @author peng-yongsheng + */ +public interface IServiceReferenceMetricUIDAO extends DAO { + + List getFrontServices(Step step, long startTime, long endTime, + MetricSource metricSource, int behindServiceId); + + List getBehindServices(Step step, long startTime, long endTime, + MetricSource metricSource, int frontServiceId); + + List getFrontServices(Step step, long startTime, long endTime, + MetricSource metricSource, List behindServiceIds); + + List getBehindServices(Step step, long startTime, long endTime, + MetricSource metricSource, List frontServiceIds); +} diff --git a/apm-collector/apm-collector-analysis/analysis-metric/metric-define/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/define/MetricSource.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/MetricSource.java similarity index 93% rename from apm-collector/apm-collector-analysis/analysis-metric/metric-define/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/define/MetricSource.java rename to apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/MetricSource.java index 7757e13ec..26af12fda 100644 --- a/apm-collector/apm-collector-analysis/analysis-metric/metric-define/src/main/java/org/apache/skywalking/apm/collector/analysis/metric/define/MetricSource.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/MetricSource.java @@ -16,7 +16,7 @@ * */ -package org.apache.skywalking.apm.collector.analysis.metric.define; +package org.apache.skywalking.apm.collector.storage.table; /** * @author peng-yongsheng diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationComponent.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationComponent.java index 4f18fbbd1..cf6e09e69 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationComponent.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationComponent.java @@ -41,7 +41,7 @@ public class ApplicationComponent extends StreamData { private static final Column[] INTEGER_COLUMNS = { new Column(ApplicationComponentTable.COLUMN_COMPONENT_ID, new CoverOperation()), - new Column(ApplicationComponentTable.COLUMN_PEER_ID, new CoverOperation()), + new Column(ApplicationComponentTable.COLUMN_APPLICATION_ID, new CoverOperation()), }; private static final Column[] BYTE_COLUMNS = {}; @@ -82,11 +82,11 @@ public class ApplicationComponent extends StreamData { setDataInteger(0, componentId); } - public Integer getPeerId() { + public Integer getApplicationId() { return getDataInteger(1); } - public void setPeerId(Integer peerId) { - setDataInteger(1, peerId); + public void setApplicationId(Integer applicationId) { + setDataInteger(1, applicationId); } } diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationComponentTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationComponentTable.java index 10b39796d..921398cdf 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationComponentTable.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationComponentTable.java @@ -16,7 +16,6 @@ * */ - package org.apache.skywalking.apm.collector.storage.table.application; import org.apache.skywalking.apm.collector.core.data.CommonTable; @@ -27,5 +26,5 @@ import org.apache.skywalking.apm.collector.core.data.CommonTable; public class ApplicationComponentTable extends CommonTable { public static final String TABLE = "application_component"; public static final String COLUMN_COMPONENT_ID = "component_id"; - public static final String COLUMN_PEER_ID = "peer_id"; + public static final String COLUMN_APPLICATION_ID = "application_id"; } diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationMapping.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationMapping.java index 0d777426c..e1b3fff77 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationMapping.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationMapping.java @@ -41,7 +41,7 @@ public class ApplicationMapping extends StreamData { private static final Column[] INTEGER_COLUMNS = { new Column(ApplicationMappingTable.COLUMN_APPLICATION_ID, new CoverOperation()), - new Column(ApplicationMappingTable.COLUMN_ADDRESS_ID, new CoverOperation()), + new Column(ApplicationMappingTable.COLUMN_MAPPING_APPLICATION_ID, new CoverOperation()), }; private static final Column[] BYTE_COLUMNS = {}; @@ -74,12 +74,12 @@ public class ApplicationMapping extends StreamData { setDataInteger(0, applicationId); } - public int getAddressId() { + public int getMappingApplicationId() { return getDataInteger(1); } - public void setAddressId(int addressId) { - setDataInteger(1, addressId); + public void setMappingApplicationId(int mappingApplicationId) { + setDataInteger(1, mappingApplicationId); } public long getTimeBucket() { diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationMappingTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationMappingTable.java index df9fbbb1d..fbaa49e24 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationMappingTable.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/application/ApplicationMappingTable.java @@ -16,7 +16,6 @@ * */ - package org.apache.skywalking.apm.collector.storage.table.application; import org.apache.skywalking.apm.collector.core.data.CommonTable; @@ -27,5 +26,5 @@ import org.apache.skywalking.apm.collector.core.data.CommonTable; public class ApplicationMappingTable extends CommonTable { public static final String TABLE = "application_mapping"; public static final String COLUMN_APPLICATION_ID = "application_id"; - public static final String COLUMN_ADDRESS_ID = "address_id"; + public static final String COLUMN_MAPPING_APPLICATION_ID = "mapping_application_id"; } diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/Application.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/Application.java index 3b68ddbce..f5107a163 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/Application.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/Application.java @@ -39,6 +39,7 @@ public class Application extends StreamData { private static final Column[] INTEGER_COLUMNS = { new Column(ApplicationTable.COLUMN_APPLICATION_ID, new CoverOperation()), + new Column(ApplicationTable.COLUMN_LAYER, new CoverOperation()), new Column(ApplicationTable.COLUMN_ADDRESS_ID, new CoverOperation()), new Column(ApplicationTable.COLUMN_IS_ADDRESS, new CoverOperation()), }; @@ -81,19 +82,27 @@ public class Application extends StreamData { setDataInteger(0, applicationId); } - public int getAddressId() { + public int getLayer() { return getDataInteger(1); } - public void setAddressId(int addressId) { - setDataInteger(1, addressId); + public void setLayer(int layer) { + setDataInteger(1, layer); } - public int getIsAddress() { + public int getAddressId() { return getDataInteger(2); } + public void setAddressId(int addressId) { + setDataInteger(2, addressId); + } + + public int getIsAddress() { + return getDataInteger(3); + } + public void setIsAddress(int isAddress) { - setDataInteger(2, isAddress); + setDataInteger(3, isAddress); } } diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/ApplicationTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/ApplicationTable.java index abb5b5905..faa33741b 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/ApplicationTable.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/ApplicationTable.java @@ -27,6 +27,7 @@ public class ApplicationTable extends CommonTable { public static final String TABLE = "application"; public static final String COLUMN_APPLICATION_CODE = "application_code"; public static final String COLUMN_APPLICATION_ID = "application_id"; + public static final String COLUMN_LAYER = "layer"; public static final String COLUMN_IS_ADDRESS = "is_address"; public static final String COLUMN_ADDRESS_ID = "address_id"; } diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/NetworkAddress.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/NetworkAddress.java index d20c29a44..b6e6c7129 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/NetworkAddress.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/NetworkAddress.java @@ -39,6 +39,7 @@ public class NetworkAddress extends StreamData { private static final Column[] INTEGER_COLUMNS = { new Column(NetworkAddressTable.COLUMN_ADDRESS_ID, new NonOperation()), + new Column(NetworkAddressTable.COLUMN_SPAN_LAYER, new NonOperation()), }; private static final Column[] BYTE_COLUMNS = {}; @@ -78,4 +79,12 @@ public class NetworkAddress extends StreamData { public void setAddressId(Integer addressId) { setDataInteger(0, addressId); } + + public Integer getSpanLayer() { + return getDataInteger(1); + } + + public void setSpanLayer(Integer spanLayer) { + setDataInteger(1, spanLayer); + } } diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/NetworkAddressTable.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/NetworkAddressTable.java index 97ffe2e76..5374fb34b 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/NetworkAddressTable.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/table/register/NetworkAddressTable.java @@ -26,5 +26,6 @@ import org.apache.skywalking.apm.collector.core.data.CommonTable; public class NetworkAddressTable extends CommonTable { public static final String TABLE = "network_address"; public static final String COLUMN_NETWORK_ADDRESS = "network_address"; + public static final String COLUMN_SPAN_LAYER = "span_layer"; public static final String COLUMN_ADDRESS_ID = "address_id"; } 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/alarm/Alarm.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/alarm/Alarm.java new file mode 100644 index 000000000..001024a27 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/alarm/Alarm.java @@ -0,0 +1,45 @@ +/* + * 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.ui.alarm; + +import java.util.List; + +/** + * @author peng-yongsheng + */ +public class Alarm { + private List items; + private int total; + + public List getItems() { + return items; + } + + public void setItems(List items) { + this.items = items; + } + + 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/alarm/AlarmItem.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/alarm/AlarmItem.java new file mode 100644 index 000000000..bdd9f6ff9 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/alarm/AlarmItem.java @@ -0,0 +1,31 @@ +/* + * 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.ui.alarm; + +/** + * @author peng-yongsheng + */ +public class AlarmItem { + private String id; + private String title; + private String content; + private String startTime; + private AlarmType alarmType; + private CauseType causeType; +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/alarm/AlarmType.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/alarm/AlarmType.java new file mode 100644 index 000000000..75986a5da --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/alarm/AlarmType.java @@ -0,0 +1,28 @@ +/* + * 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.ui.alarm; + +/** + * @author peng-yongsheng + */ +public enum AlarmType { + APPLICATION, + SERVER, + SERVICE +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/alarm/CauseType.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/alarm/CauseType.java new file mode 100644 index 000000000..908ff6482 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/alarm/CauseType.java @@ -0,0 +1,27 @@ +/* + * 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.ui.alarm; + +/** + * @author peng-yongsheng + */ +public enum CauseType { + LOW_SUCCESS_RATE, + SLOW_RESPONSE +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/application/Application.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/application/Application.java new file mode 100644 index 000000000..354efb2cf --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/application/Application.java @@ -0,0 +1,52 @@ +/* + * 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.ui.application; + +/** + * @author peng-yongsheng + */ +public class Application { + private int id; + private String name; + private int numOfServer; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getNumOfServer() { + return numOfServer; + } + + public void setNumOfServer(int numOfServer) { + this.numOfServer = numOfServer; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/application/ApplicationNode.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/application/ApplicationNode.java new file mode 100644 index 000000000..66f3a8d82 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/application/ApplicationNode.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.ui.application; + +import org.apache.skywalking.apm.collector.storage.ui.common.Node; + +/** + * @author peng-yongsheng + */ +public class ApplicationNode extends Node { + + private Float sla; + private Long callsPerSec; + private Long responseTimePerSec; + private Float apdex; + private Boolean isAlarm; + private Integer numOfServer; + private Integer numOfServerAlarm; + private Integer numOfServiceAlarm; + + public Float getSla() { + return sla; + } + + public void setSla(Float sla) { + this.sla = sla; + } + + public Long getCallsPerSec() { + return callsPerSec; + } + + public void setCallsPerSec(Long callsPerSec) { + this.callsPerSec = callsPerSec; + } + + public Long getResponseTimePerSec() { + return responseTimePerSec; + } + + public void setResponseTimePerSec(Long responseTimePerSec) { + this.responseTimePerSec = responseTimePerSec; + } + + public Float getApdex() { + return apdex; + } + + public void setApdex(Float apdex) { + this.apdex = apdex; + } + + public Boolean getAlarm() { + return isAlarm; + } + + public void setAlarm(Boolean alarm) { + isAlarm = alarm; + } + + public Integer getNumOfServer() { + return numOfServer; + } + + public void setNumOfServer(Integer numOfServer) { + this.numOfServer = numOfServer; + } + + public Integer getNumOfServerAlarm() { + return numOfServerAlarm; + } + + public void setNumOfServerAlarm(Integer numOfServerAlarm) { + this.numOfServerAlarm = numOfServerAlarm; + } + + public Integer getNumOfServiceAlarm() { + return numOfServiceAlarm; + } + + public void setNumOfServiceAlarm(Integer numOfServiceAlarm) { + this.numOfServiceAlarm = numOfServiceAlarm; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationReferenceMetricUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/application/ConjecturalNode.java similarity index 75% rename from apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationReferenceMetricUIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/application/ConjecturalNode.java index 1c32a17cf..c77c36955 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationReferenceMetricUIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/application/ConjecturalNode.java @@ -16,14 +16,12 @@ * */ -package org.apache.skywalking.apm.collector.storage.dao; +package org.apache.skywalking.apm.collector.storage.ui.application; -import com.google.gson.JsonArray; -import org.apache.skywalking.apm.collector.storage.base.dao.DAO; +import org.apache.skywalking.apm.collector.storage.ui.common.Node; /** * @author peng-yongsheng */ -public interface IApplicationReferenceMetricUIDAO extends DAO { - JsonArray load(long startTime, long endTime); +public class ConjecturalNode extends Node { } diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/Call.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/Call.java new file mode 100644 index 000000000..70956ef73 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/Call.java @@ -0,0 +1,115 @@ +/* + * 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.ui.common; + +/** + * @author peng-yongsheng + */ +public class Call { + private int source; + private String sourceName; + private int target; + private String targetName; + private boolean isAlert; + private String callType; + private long calls; + private long callsPerSec; + private long responseTimes; + private long responseTimePerSec; + + public int getSource() { + return source; + } + + public void setSource(int source) { + this.source = source; + } + + public String getSourceName() { + return sourceName; + } + + public void setSourceName(String sourceName) { + this.sourceName = sourceName; + } + + public int getTarget() { + return target; + } + + public void setTarget(int target) { + this.target = target; + } + + public String getTargetName() { + return targetName; + } + + public void setTargetName(String targetName) { + this.targetName = targetName; + } + + public boolean isAlert() { + return isAlert; + } + + public void setAlert(boolean alert) { + isAlert = alert; + } + + public String getCallType() { + return callType; + } + + public void setCallType(String callType) { + this.callType = callType; + } + + public long getCalls() { + return calls; + } + + public void setCalls(long calls) { + this.calls = calls; + } + + public long getCallsPerSec() { + return callsPerSec; + } + + public void setCallsPerSec(long callsPerSec) { + this.callsPerSec = callsPerSec; + } + + public long getResponseTimes() { + return responseTimes; + } + + public void setResponseTimes(long responseTimes) { + this.responseTimes = responseTimes; + } + + public long getResponseTimePerSec() { + return responseTimePerSec; + } + + public void setResponseTimePerSec(long responseTimePerSec) { + this.responseTimePerSec = responseTimePerSec; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/Duration.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/Duration.java new file mode 100644 index 000000000..88ef2fa7f --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/Duration.java @@ -0,0 +1,53 @@ +/* + * 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.ui.common; + +/** + * @author peng-yongsheng + */ +public class Duration { + + private String start; + private String end; + private Step step; + + public String getStart() { + return start; + } + + public void setStart(String start) { + this.start = start; + } + + public String getEnd() { + return end; + } + + public void setEnd(String end) { + this.end = end; + } + + public Step getStep() { + return step; + } + + public void setStep(Step step) { + this.step = step; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/Node.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/Node.java new file mode 100644 index 000000000..b4cf19254 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/Node.java @@ -0,0 +1,52 @@ +/* + * 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.ui.common; + +/** + * @author peng-yongsheng + */ +public abstract class Node { + private int id; + private String name; + private String type; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/Pagination.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/Pagination.java new file mode 100644 index 000000000..dc4904807 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/Pagination.java @@ -0,0 +1,52 @@ +/* + * 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.ui.common; + +/** + * @author peng-yongsheng + */ +public class Pagination { + private Integer pageNum; + private Integer pageSize; + private Boolean needTotal; + + public Integer getPageNum() { + return pageNum; + } + + public void setPageNum(Integer pageNum) { + this.pageNum = pageNum; + } + + public Integer getPageSize() { + return pageSize; + } + + public void setPageSize(Integer pageSize) { + this.pageSize = pageSize; + } + + public Boolean getNeedTotal() { + return needTotal; + } + + public void setNeedTotal(Boolean needTotal) { + this.needTotal = needTotal; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/ResponseTimeTrend.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/ResponseTimeTrend.java new file mode 100644 index 000000000..dc08516c0 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/ResponseTimeTrend.java @@ -0,0 +1,36 @@ +/* + * 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.ui.common; + +import java.util.List; + +/** + * @author peng-yongsheng + */ +public class ResponseTimeTrend { + private List trendList; + + public List getTrendList() { + return trendList; + } + + public void setTrendList(List trendList) { + this.trendList = trendList; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/SLATrend.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/SLATrend.java new file mode 100644 index 000000000..ed75ddac8 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/SLATrend.java @@ -0,0 +1,36 @@ +/* + * 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.ui.common; + +import java.util.List; + +/** + * @author peng-yongsheng + */ +public class SLATrend { + private List trendList; + + public List getTrendList() { + return trendList; + } + + public void setTrendList(List trendList) { + this.trendList = trendList; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/Step.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/Step.java new file mode 100644 index 000000000..6a4d83a0b --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/Step.java @@ -0,0 +1,30 @@ +/* + * 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.ui.common; + +/** + * @author peng-yongsheng + */ +public enum Step { + MONTH, + DAY, + HOUR, + MINUTE, + SECOND +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/ThroughputTrend.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/ThroughputTrend.java new file mode 100644 index 000000000..f20866964 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/ThroughputTrend.java @@ -0,0 +1,36 @@ +/* + * 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.ui.common; + +import java.util.List; + +/** + * @author peng-yongsheng + */ +public class ThroughputTrend { + private List trendList; + + public List getTrendList() { + return trendList; + } + + public void setTrendList(List trendList) { + this.trendList = trendList; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/Topology.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/Topology.java new file mode 100644 index 000000000..a019a97b7 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/Topology.java @@ -0,0 +1,52 @@ +/* + * 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.ui.common; + +import java.util.LinkedList; +import java.util.List; + +/** + * @author peng-yongsheng + */ +public class Topology { + + private List nodes; + private List calls; + + public Topology() { + this.nodes = new LinkedList<>(); + this.calls = new LinkedList<>(); + } + + public List getNodes() { + return nodes; + } + + public void setNodes(List nodes) { + this.nodes = nodes; + } + + public List getCalls() { + return calls; + } + + public void setCalls(List calls) { + this.calls = calls; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/VisualUserNode.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/VisualUserNode.java new file mode 100644 index 000000000..8207acda2 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/VisualUserNode.java @@ -0,0 +1,25 @@ +/* + * 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.ui.common; + +/** + * @author peng-yongsheng + */ +public class VisualUserNode extends Node { +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/config/AlarmThreshold.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/config/AlarmThreshold.java new file mode 100644 index 000000000..e96d329ec --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/config/AlarmThreshold.java @@ -0,0 +1,31 @@ +/* + * 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.ui.config; + +import org.apache.skywalking.apm.collector.storage.ui.alarm.AlarmType; +import org.apache.skywalking.apm.collector.storage.ui.alarm.CauseType; + +/** + * @author peng-yongsheng + */ +public class AlarmThreshold { + private AlarmType type; + private Integer threshold; + private CauseType causeType; +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/config/ExistedAlarmThresholdItem.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/config/ExistedAlarmThresholdItem.java new file mode 100644 index 000000000..e42e70d96 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/config/ExistedAlarmThresholdItem.java @@ -0,0 +1,29 @@ +/* + * 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.ui.config; + +import org.apache.skywalking.apm.collector.storage.ui.alarm.CauseType; + +/** + * @author peng-yongsheng + */ +public class ExistedAlarmThresholdItem { + private Integer threshold; + private CauseType causeType; +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/config/ExistedAlarmThresholds.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/config/ExistedAlarmThresholds.java new file mode 100644 index 000000000..f4d094547 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/config/ExistedAlarmThresholds.java @@ -0,0 +1,28 @@ +/* + * 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.ui.config; + +import java.util.List; + +/** + * @author peng-yongsheng + */ +public class ExistedAlarmThresholds { + private List items; +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/config/ExistedTTLConfigs.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/config/ExistedTTLConfigs.java new file mode 100644 index 000000000..32b29cbe2 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/config/ExistedTTLConfigs.java @@ -0,0 +1,28 @@ +/* + * 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.ui.config; + +import java.util.List; + +/** + * @author peng-yongsheng + */ +public class ExistedTTLConfigs { + private List ttl; +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/config/TTL.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/config/TTL.java new file mode 100644 index 000000000..3da100ed4 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/config/TTL.java @@ -0,0 +1,29 @@ +/* + * 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.ui.config; + +import org.apache.skywalking.apm.collector.storage.ui.common.Step; + +/** + * @author peng-yongsheng + */ +public class TTL { + private Step unit; + private Integer value; +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/config/TTLConfigItem.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/config/TTLConfigItem.java new file mode 100644 index 000000000..8984f1616 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/config/TTLConfigItem.java @@ -0,0 +1,29 @@ +/* + * 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.ui.config; + +import org.apache.skywalking.apm.collector.storage.ui.common.Step; + +/** + * @author peng-yongsheng + */ +public class TTLConfigItem { + private Step unit; + private Integer value; +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationComponentUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/overview/AlarmTrend.java similarity index 76% rename from apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationComponentUIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/overview/AlarmTrend.java index a003e5ff2..025d27df8 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/IApplicationComponentUIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/overview/AlarmTrend.java @@ -16,14 +16,13 @@ * */ -package org.apache.skywalking.apm.collector.storage.dao; +package org.apache.skywalking.apm.collector.storage.ui.overview; -import com.google.gson.JsonArray; -import org.apache.skywalking.apm.collector.storage.base.dao.DAO; +import java.util.List; /** * @author peng-yongsheng */ -public interface IApplicationComponentUIDAO extends DAO { - JsonArray load(long startTime, long endTime); +public class AlarmTrend { + public List numOfAlarmRate; } diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/overview/ClusterBrief.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/overview/ClusterBrief.java new file mode 100644 index 000000000..0dce69e8c --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/overview/ClusterBrief.java @@ -0,0 +1,70 @@ +/* + * 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.ui.overview; + +/** + * @author peng-yongsheng + */ +public class ClusterBrief { + private int numOfApplication; + private int numOfService; + private int numOfDatabase; + private int numOfCache; + private int numOfMQ; + + public int getNumOfApplication() { + return numOfApplication; + } + + public void setNumOfApplication(int numOfApplication) { + this.numOfApplication = numOfApplication; + } + + public int getNumOfService() { + return numOfService; + } + + public void setNumOfService(int numOfService) { + this.numOfService = numOfService; + } + + public int getNumOfDatabase() { + return numOfDatabase; + } + + public void setNumOfDatabase(int numOfDatabase) { + this.numOfDatabase = numOfDatabase; + } + + public int getNumOfCache() { + return numOfCache; + } + + public void setNumOfCache(int numOfCache) { + this.numOfCache = numOfCache; + } + + public int getNumOfMQ() { + return numOfMQ; + } + + public void setNumOfMQ(int numOfMQ) { + this.numOfMQ = numOfMQ; + } +} 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 new file mode 100644 index 000000000..5085e8926 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/overview/ConjecturalApp.java @@ -0,0 +1,43 @@ +/* + * 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.ui.overview; + +/** + * @author peng-yongsheng + */ +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 new file mode 100644 index 000000000..0d561359b --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/overview/ConjecturalAppBrief.java @@ -0,0 +1,36 @@ +/* + * 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.ui.overview; + +import java.util.List; + +/** + * @author peng-yongsheng + */ +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/server/AppServerInfo.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/server/AppServerInfo.java new file mode 100644 index 000000000..c1ee6f307 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/server/AppServerInfo.java @@ -0,0 +1,108 @@ +/* + * 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.ui.server; + +import java.util.List; + +/** + * @author peng-yongsheng + */ +public class AppServerInfo { + private int id; + private int applicationId; + private String applicationCode; + private String osInfo; + private String name; + private int tps; + private String host; + private int pid; + private List ipv4; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public int getApplicationId() { + return applicationId; + } + + public void setApplicationId(int applicationId) { + this.applicationId = applicationId; + } + + public String getApplicationCode() { + return applicationCode; + } + + public void setApplicationCode(String applicationCode) { + this.applicationCode = applicationCode; + } + + public String getOsInfo() { + return osInfo; + } + + public void setOsInfo(String osInfo) { + this.osInfo = osInfo; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getTps() { + return tps; + } + + public void setTps(int tps) { + this.tps = tps; + } + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public int getPid() { + return pid; + } + + public void setPid(int pid) { + this.pid = pid; + } + + public List getIpv4() { + return ipv4; + } + + public void setIpv4(List ipv4) { + this.ipv4 = ipv4; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/server/CPUTrend.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/server/CPUTrend.java new file mode 100644 index 000000000..5f894f76c --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/server/CPUTrend.java @@ -0,0 +1,36 @@ +/* + * 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.ui.server; + +import java.util.List; + +/** + * @author peng-yongsheng + */ +public class CPUTrend { + private List cost; + + public List getCost() { + return cost; + } + + public void setCost(List cost) { + this.cost = cost; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/server/GCTrend.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/server/GCTrend.java new file mode 100644 index 000000000..458319479 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/server/GCTrend.java @@ -0,0 +1,45 @@ +/* + * 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.ui.server; + +import java.util.List; + +/** + * @author peng-yongsheng + */ +public class GCTrend { + private List youngGC; + private List oldGC; + + public List getYoungGC() { + return youngGC; + } + + public void setYoungGC(List youngGC) { + this.youngGC = youngGC; + } + + public List getOldGC() { + return oldGC; + } + + public void setOldGC(List oldGC) { + this.oldGC = oldGC; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/server/MemoryTrend.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/server/MemoryTrend.java new file mode 100644 index 000000000..5b7027c02 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/server/MemoryTrend.java @@ -0,0 +1,63 @@ +/* + * 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.ui.server; + +import java.util.List; + +/** + * @author peng-yongsheng + */ +public class MemoryTrend { + private List heap; + private List maxHeap; + private List noheap; + private List maxNoheap; + + public List getHeap() { + return heap; + } + + public void setHeap(List heap) { + this.heap = heap; + } + + public List getMaxHeap() { + return maxHeap; + } + + public void setMaxHeap(List maxHeap) { + this.maxHeap = maxHeap; + } + + public List getNoheap() { + return noheap; + } + + public void setNoheap(List noheap) { + this.noheap = noheap; + } + + public List getMaxNoheap() { + return maxNoheap; + } + + public void setMaxNoheap(List maxNoheap) { + this.maxNoheap = maxNoheap; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/service/ServiceInfo.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/service/ServiceInfo.java new file mode 100644 index 000000000..808fe25f3 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/service/ServiceInfo.java @@ -0,0 +1,43 @@ +/* + * 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.ui.service; + +/** + * @author peng-yongsheng + */ +public class ServiceInfo { + private int id; + private String name; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/service/ServiceMetric.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/service/ServiceMetric.java new file mode 100644 index 000000000..7db67f8b4 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/service/ServiceMetric.java @@ -0,0 +1,61 @@ +/* + * 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.ui.service; + +/** + * @author peng-yongsheng + */ +public class ServiceMetric { + private int id; + private String name; + private int avgResponseTime; + private int tps; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAvgResponseTime() { + return avgResponseTime; + } + + public void setAvgResponseTime(int avgResponseTime) { + this.avgResponseTime = avgResponseTime; + } + + public int getTps() { + return tps; + } + + public void setTps(int tps) { + this.tps = tps; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/service/ServiceNode.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/service/ServiceNode.java new file mode 100644 index 000000000..b935f9250 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/service/ServiceNode.java @@ -0,0 +1,63 @@ +/* + * 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.ui.service; + +import org.apache.skywalking.apm.collector.storage.ui.common.Node; + +/** + * @author peng-yongsheng + */ +public class ServiceNode extends Node { + private int sla; + private long calls; + private int numOfServiceAlarm; + private int applicationId; + + public int getSla() { + return sla; + } + + public void setSla(int sla) { + this.sla = sla; + } + + public long getCalls() { + return calls; + } + + public void setCalls(long calls) { + this.calls = calls; + } + + public int getNumOfServiceAlarm() { + return numOfServiceAlarm; + } + + public void setNumOfServiceAlarm(int numOfServiceAlarm) { + this.numOfServiceAlarm = numOfServiceAlarm; + } + + public int getApplicationId() { + return applicationId; + } + + public void setApplicationId(int applicationId) { + this.applicationId = applicationId; + } +} 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 new file mode 100644 index 000000000..127157bab --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/BasicTrace.java @@ -0,0 +1,70 @@ +/* + * 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.ui.trace; + +/** + * @author peng-yongsheng + */ +public class BasicTrace { + private String operationName; + private int duration; + 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/KeyValue.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/KeyValue.java new file mode 100644 index 000000000..deac45f07 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/KeyValue.java @@ -0,0 +1,43 @@ +/* + * 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.ui.trace; + +/** + * @author peng-yongsheng + */ +public class KeyValue { + private String key; + private String value; + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/LogEntity.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/LogEntity.java new file mode 100644 index 000000000..a7988702e --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/LogEntity.java @@ -0,0 +1,50 @@ +/* + * 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.ui.trace; + +import java.util.LinkedList; +import java.util.List; + +/** + * @author peng-yongsheng + */ +public class LogEntity { + private long time; + private List data; + + public LogEntity() { + this.data = new LinkedList<>(); + } + + public long getTime() { + return time; + } + + public void setTime(long time) { + this.time = time; + } + + public List getData() { + return data; + } + + public void setData(List data) { + this.data = data; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/Ref.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/Ref.java new file mode 100644 index 000000000..7f189e765 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/Ref.java @@ -0,0 +1,61 @@ +/* + * 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.ui.trace; + +/** + * @author peng-yongsheng + */ +public class Ref { + private String traceId; + private String parentSegmentId; + private Integer parentSpanId; + private RefType type; + + public String getTraceId() { + return traceId; + } + + public void setTraceId(String traceId) { + this.traceId = traceId; + } + + public String getParentSegmentId() { + return parentSegmentId; + } + + public void setParentSegmentId(String parentSegmentId) { + this.parentSegmentId = parentSegmentId; + } + + public Integer getParentSpanId() { + return parentSpanId; + } + + public void setParentSpanId(Integer parentSpanId) { + this.parentSpanId = parentSpanId; + } + + public RefType getType() { + return type; + } + + public void setType(RefType type) { + this.type = type; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/RefType.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/RefType.java new file mode 100644 index 000000000..00eca2080 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/RefType.java @@ -0,0 +1,27 @@ +/* + * 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.ui.trace; + +/** + * @author peng-yongsheng + */ +public enum RefType { + CROSS_PROCESS, + CROSS_THREAD +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/Segment.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/Segment.java new file mode 100644 index 000000000..62fc6ab3d --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/Segment.java @@ -0,0 +1,31 @@ +/* + * 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.ui.trace; + +import java.util.List; + +/** + * @author peng-yongsheng + */ +public class Segment { + private int segmentId; + private String appName; + private Boolean isSizeLimited; + private List spans; +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/Span.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/Span.java new file mode 100644 index 000000000..9d56c39ce --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/Span.java @@ -0,0 +1,205 @@ +/* + * 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.ui.trace; + +import java.util.LinkedList; +import java.util.List; + +/** + * @author peng-yongsheng + */ +public class Span { + private String traceId; + private String segmentId; + private int spanId; + private int parentSpanId; + private List refs; + private String applicationCode; + private long startTime; + private long endTime; + private String operationName; + private String type; + private String peer; + private String component; + private Boolean isError; + private String layer; + private List tags; + private List logs; + private boolean isRoot; + private String segmentSpanId; + private String segmentParentSpanId; + + public Span() { + this.refs = new LinkedList<>(); + this.tags = new LinkedList<>(); + this.logs = new LinkedList<>(); + } + + public String getTraceId() { + return traceId; + } + + public void setTraceId(String traceId) { + this.traceId = traceId; + } + + public String getSegmentId() { + return segmentId; + } + + public void setSegmentId(String segmentId) { + this.segmentId = segmentId; + } + + public int getSpanId() { + return spanId; + } + + public void setSpanId(int spanId) { + this.spanId = spanId; + } + + public int getParentSpanId() { + return parentSpanId; + } + + public void setParentSpanId(int parentSpanId) { + this.parentSpanId = parentSpanId; + } + + public List getRefs() { + return refs; + } + + public void setRefs(List refs) { + this.refs = refs; + } + + public String getApplicationCode() { + return applicationCode; + } + + public void setApplicationCode(String applicationCode) { + this.applicationCode = applicationCode; + } + + public long getStartTime() { + return startTime; + } + + public void setStartTime(long startTime) { + this.startTime = startTime; + } + + public long getEndTime() { + return endTime; + } + + public void setEndTime(long endTime) { + this.endTime = endTime; + } + + public String getOperationName() { + return operationName; + } + + public void setOperationName(String operationName) { + this.operationName = operationName; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getPeer() { + return peer; + } + + public void setPeer(String peer) { + this.peer = peer; + } + + public String getComponent() { + return component; + } + + public void setComponent(String component) { + this.component = component; + } + + public Boolean getError() { + return isError; + } + + public void setError(Boolean error) { + isError = error; + } + + public String getLayer() { + return layer; + } + + public void setLayer(String layer) { + this.layer = layer; + } + + public List getTags() { + return tags; + } + + public void setTags(List tags) { + this.tags = tags; + } + + public List getLogs() { + return logs; + } + + public void setLogs(List logs) { + this.logs = logs; + } + + public boolean isRoot() { + return isRoot; + } + + public void setRoot(boolean root) { + isRoot = root; + } + + public String getSegmentParentSpanId() { + return segmentParentSpanId; + } + + public void setSegmentParentSpanId(String segmentParentSpanId) { + this.segmentParentSpanId = segmentParentSpanId; + } + + public String getSegmentSpanId() { + return segmentSpanId; + } + + public void setSegmentSpanId(String segmentSpanId) { + this.segmentSpanId = segmentSpanId; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/Trace.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/Trace.java new file mode 100644 index 000000000..a3524aa44 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/Trace.java @@ -0,0 +1,42 @@ +/* + * 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.ui.trace; + +import java.util.LinkedList; +import java.util.List; + +/** + * @author peng-yongsheng + */ +public class Trace { + + private List spans; + + public Trace() { + this.spans = new LinkedList<>(); + } + + public List getSpans() { + return spans; + } + + public void setSpans(List spans) { + this.spans = spans; + } +} 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 new file mode 100644 index 000000000..df1963487 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/TraceBrief.java @@ -0,0 +1,50 @@ +/* + * 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.ui.trace; + +import java.util.LinkedList; +import java.util.List; + +/** + * @author peng-yongsheng + */ +public class TraceBrief { + private List traces; + 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 new file mode 100644 index 000000000..86bea1abe --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/trace/TraceQueryCondition.java @@ -0,0 +1,91 @@ +/* + * 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.ui.trace; + +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 int applicationId; + private String traceId; + private String operationName; + private Duration queryDuration; + private int minTraceDuration; + private int maxTraceDuration; + 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-define/src/main/java/org/apache/skywalking/apm/collector/storage/utils/DurationPoint.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/utils/DurationPoint.java new file mode 100644 index 000000000..a8f5ecebf --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/utils/DurationPoint.java @@ -0,0 +1,40 @@ +/* + * 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.utils; + +/** + * @author peng-yongsheng + */ +public class DurationPoint { + private long point; + private long secondsBetween; + + public DurationPoint(long point, long secondsBetween) { + this.point = point; + this.secondsBetween = secondsBetween; + } + + public long getPoint() { + return point; + } + + public long getSecondsBetween() { + return secondsBetween; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/utils/TimePyramidTableNameBuilder.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/utils/TimePyramidTableNameBuilder.java new file mode 100644 index 000000000..6bfd365ee --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/utils/TimePyramidTableNameBuilder.java @@ -0,0 +1,50 @@ +/* + * 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.utils; + +import org.apache.skywalking.apm.collector.core.storage.TimePyramid; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; + +/** + * @author peng-yongsheng + */ +public class TimePyramidTableNameBuilder { + + private TimePyramidTableNameBuilder() { + } + + public static String build(Step step, String tableName) { + switch (step) { + case MONTH: + tableName = tableName + Const.ID_SPLIT + TimePyramid.Month.getName(); + break; + case DAY: + tableName = tableName + Const.ID_SPLIT + TimePyramid.Day.getName(); + break; + case HOUR: + tableName = tableName + Const.ID_SPLIT + TimePyramid.Day.getName(); + break; + case MINUTE: + tableName = tableName + Const.ID_SPLIT + TimePyramid.Minute.getName(); + break; + } + return tableName; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module b/apm-collector/apm-collector-storage/collector-storage-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module index b1217c903..e872625d2 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/resources/META-INF/services/org.apache.skywalking.apm.collector.core.module.Module @@ -16,5 +16,4 @@ # # - -org.apache.skywalking.apm.collector.storage.StorageModule +org.apache.skywalking.apm.collector.storage.StorageModule \ No newline at end of file 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/StorageModuleEsNamingListener.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/StorageModuleEsNamingListener.java index ab0f7f6fe..a4e689c4e 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/StorageModuleEsNamingListener.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/StorageModuleEsNamingListener.java @@ -16,7 +16,6 @@ * */ - package org.apache.skywalking.apm.collector.storage.es; import org.apache.skywalking.apm.collector.cluster.ClusterModuleListener; @@ -27,7 +26,7 @@ import org.apache.skywalking.apm.collector.storage.StorageModule; */ public class StorageModuleEsNamingListener extends ClusterModuleListener { - public static final String PATH = "/" + StorageModule.NAME + "/" + StorageModuleEsProvider.NAME; + private static final String PATH = "/" + StorageModule.NAME + "/" + StorageModuleEsProvider.NAME; @Override public String path() { return PATH; 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 ffe10f056..943af2af3 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 @@ -31,23 +31,10 @@ import org.apache.skywalking.apm.collector.core.module.ServiceNotProvidedExcepti import org.apache.skywalking.apm.collector.storage.StorageException; 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.IApplicationComponentUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.IApplicationMappingUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.ICpuMetricUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.IGCMetricUIDAO; import org.apache.skywalking.apm.collector.storage.dao.IGlobalTracePersistenceDAO; -import org.apache.skywalking.apm.collector.storage.dao.IGlobalTraceUIDAO; import org.apache.skywalking.apm.collector.storage.dao.IInstanceHeartBeatPersistenceDAO; -import org.apache.skywalking.apm.collector.storage.dao.IInstanceMetricUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.IInstanceUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.IMemoryMetricUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.IMemoryPoolMetricUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.ISegmentCostPersistenceDAO; -import org.apache.skywalking.apm.collector.storage.dao.ISegmentCostUIDAO; +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.ISegmentUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.IServiceReferenceUIDAO; import org.apache.skywalking.apm.collector.storage.dao.acp.IApplicationComponentDayPersistenceDAO; import org.apache.skywalking.apm.collector.storage.dao.acp.IApplicationComponentHourPersistenceDAO; import org.apache.skywalking.apm.collector.storage.dao.acp.IApplicationComponentMinutePersistenceDAO; @@ -124,25 +111,28 @@ import org.apache.skywalking.apm.collector.storage.dao.srmp.IServiceReferenceDay import org.apache.skywalking.apm.collector.storage.dao.srmp.IServiceReferenceHourMetricPersistenceDAO; import org.apache.skywalking.apm.collector.storage.dao.srmp.IServiceReferenceMinuteMetricPersistenceDAO; import org.apache.skywalking.apm.collector.storage.dao.srmp.IServiceReferenceMonthMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationComponentUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMappingUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationReferenceMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.ICpuMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IGCMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IGlobalTraceUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceMetricUIDAO; +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.ISegmentDurationUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.ISegmentUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceNameServiceUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceReferenceMetricUIDAO; 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.ApplicationComponentEsUIDAO; -import org.apache.skywalking.apm.collector.storage.es.dao.ApplicationMappingEsUIDAO; -import org.apache.skywalking.apm.collector.storage.es.dao.ApplicationReferenceMetricEsUIDAO; -import org.apache.skywalking.apm.collector.storage.es.dao.CpuMetricEsUIDAO; -import org.apache.skywalking.apm.collector.storage.es.dao.GCMetricEsUIDAO; import org.apache.skywalking.apm.collector.storage.es.dao.GlobalTraceEsPersistenceDAO; -import org.apache.skywalking.apm.collector.storage.es.dao.GlobalTraceEsUIDAO; -import org.apache.skywalking.apm.collector.storage.es.dao.InstanceEsUIDAO; import org.apache.skywalking.apm.collector.storage.es.dao.InstanceHeartBeatEsPersistenceDAO; -import org.apache.skywalking.apm.collector.storage.es.dao.InstanceMetricEsUIDAO; -import org.apache.skywalking.apm.collector.storage.es.dao.MemoryMetricEsUIDAO; -import org.apache.skywalking.apm.collector.storage.es.dao.MemoryPoolMetricEsUIDAO; -import org.apache.skywalking.apm.collector.storage.es.dao.SegmentCostEsPersistenceDAO; -import org.apache.skywalking.apm.collector.storage.es.dao.SegmentCostEsUIDAO; +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.SegmentEsUIDAO; -import org.apache.skywalking.apm.collector.storage.es.dao.ServiceReferenceEsUIDAO; import org.apache.skywalking.apm.collector.storage.es.dao.acp.ApplicationComponentDayEsPersistenceDAO; import org.apache.skywalking.apm.collector.storage.es.dao.acp.ApplicationComponentHourEsPersistenceDAO; import org.apache.skywalking.apm.collector.storage.es.dao.acp.ApplicationComponentMinuteEsPersistenceDAO; @@ -219,6 +209,22 @@ import org.apache.skywalking.apm.collector.storage.es.dao.srmp.ServiceReferenceD import org.apache.skywalking.apm.collector.storage.es.dao.srmp.ServiceReferenceHourMetricEsPersistenceDAO; import org.apache.skywalking.apm.collector.storage.es.dao.srmp.ServiceReferenceMinuteMetricEsPersistenceDAO; import org.apache.skywalking.apm.collector.storage.es.dao.srmp.ServiceReferenceMonthMetricEsPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.ui.ApplicationComponentEsUIDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.ui.ApplicationMappingEsUIDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.ui.ApplicationReferenceMetricEsUIDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.ui.CpuMetricEsUIDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.ui.GCMetricEsUIDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.ui.GlobalTraceEsUIDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.ui.InstanceEsUIDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.ui.InstanceMetricEsUIDAO; +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.SegmentDurationEsUIDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.ui.SegmentEsUIDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.ui.ServiceMetricEsUIDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.ui.ServiceNameServiceEsUIDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.ui.ServiceReferenceEsMetricUIDAO; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -229,7 +235,7 @@ public class StorageModuleEsProvider extends ModuleProvider { private final Logger logger = LoggerFactory.getLogger(StorageModuleEsProvider.class); - public static final String NAME = "elasticsearch"; + static final String NAME = "elasticsearch"; private static final String CLUSTER_NAME = "cluster_name"; private static final String CLUSTER_TRANSPORT_SNIFFER = "cluster_transport_sniffer"; private static final String CLUSTER_NODES = "cluster_nodes"; @@ -360,7 +366,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)); @@ -388,6 +394,9 @@ public class StorageModuleEsProvider extends ModuleProvider { private void registerUiDAO() throws ServiceNotProvidedException { this.registerServiceImplementation(IInstanceUIDAO.class, new InstanceEsUIDAO(elasticSearchClient)); + this.registerServiceImplementation(INetworkAddressUIDAO.class, new NetworkAddressEsUIDAO(elasticSearchClient)); + this.registerServiceImplementation(IServiceNameServiceUIDAO.class, new ServiceNameServiceEsUIDAO(elasticSearchClient)); + this.registerServiceImplementation(IServiceMetricUIDAO.class, new ServiceMetricEsUIDAO(elasticSearchClient)); this.registerServiceImplementation(ICpuMetricUIDAO.class, new CpuMetricEsUIDAO(elasticSearchClient)); this.registerServiceImplementation(IGCMetricUIDAO.class, new GCMetricEsUIDAO(elasticSearchClient)); @@ -399,9 +408,9 @@ 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)); + this.registerServiceImplementation(IServiceReferenceMetricUIDAO.class, new ServiceReferenceEsMetricUIDAO(elasticSearchClient)); } private void registerAlarmDAO() throws ServiceNotProvidedException { diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationReferenceMetricEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationReferenceMetricEsUIDAO.java deleted file mode 100644 index a7011b111..000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationReferenceMetricEsUIDAO.java +++ /dev/null @@ -1,99 +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; - -import com.google.gson.JsonArray; -import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.apache.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricUIDAO; -import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.apache.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetricTable; -import org.elasticsearch.action.search.SearchRequestBuilder; -import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.action.search.SearchType; -import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.search.aggregations.AggregationBuilders; -import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class ApplicationReferenceMetricEsUIDAO extends EsDAO implements IApplicationReferenceMetricUIDAO { - - private final Logger logger = LoggerFactory.getLogger(ApplicationReferenceMetricEsUIDAO.class); - - public ApplicationReferenceMetricEsUIDAO(ElasticSearchClient client) { - super(client); - } - - @Override public JsonArray load(long startTime, long endTime) { - SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(ApplicationReferenceMetricTable.TABLE); - searchRequestBuilder.setTypes(ApplicationReferenceMetricTable.TABLE_TYPE); - searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); - searchRequestBuilder.setQuery(QueryBuilders.rangeQuery(ApplicationReferenceMetricTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime)); - searchRequestBuilder.setSize(0); - - TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID).field(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID).size(100); -// aggregationBuilder.subAggregation(AggregationBuilders.terms(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID).field(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID).size(100) -// .subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_S1_LTE).field(ApplicationReferenceMetricTable.COLUMN_S1_LTE)) -// .subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_S3_LTE).field(ApplicationReferenceMetricTable.COLUMN_S3_LTE)) -// .subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_S5_LTE).field(ApplicationReferenceMetricTable.COLUMN_S5_LTE)) -// .subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_S5_GT).field(ApplicationReferenceMetricTable.COLUMN_S5_GT)) -// .subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_SUMMARY).field(ApplicationReferenceMetricTable.COLUMN_SUMMARY)) -// .subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_ERROR).field(ApplicationReferenceMetricTable.COLUMN_ERROR))); - - searchRequestBuilder.addAggregation(aggregationBuilder); - SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); - - JsonArray applicationReferenceMetricArray = new JsonArray(); -// Terms frontApplicationIdTerms = searchResponse.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID); -// for (Terms.Bucket frontApplicationIdBucket : frontApplicationIdTerms.getBuckets()) { -// int frontApplicationId = frontApplicationIdBucket.getKeyAsNumber().intValue(); -// Terms behindApplicationIdTerms = frontApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID); -// for (Terms.Bucket behindApplicationIdBucket : behindApplicationIdTerms.getBuckets()) { -// int behindApplicationId = behindApplicationIdBucket.getKeyAsNumber().intValue(); -// -// if (behindApplicationId != 0) { -// Sum s1LTE = behindApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_S1_LTE); -// Sum s3LTE = behindApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_S3_LTE); -// Sum s5LTE = behindApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_S5_LTE); -// Sum s5GT = behindApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_S5_GT); -// Sum summary = behindApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_SUMMARY); -// Sum error = behindApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_ERROR); -// logger.debug("frontApplicationId: {}, behindApplicationId: {}, s1LTE: {}, s3LTE: {}, s5LTE: {}, s5GT: {}, error: {}, summary: {}", frontApplicationId, -// behindApplicationId, s1LTE.getValue(), s3LTE.getValue(), s5LTE.getValue(), s5GT.getValue(), error.getValue(), summary.getValue()); -// -// JsonObject nodeRefResSumObj = new JsonObject(); -// nodeRefResSumObj.addProperty(ColumnNameUtils.INSTANCE.rename(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID), frontApplicationId); -// nodeRefResSumObj.addProperty(ColumnNameUtils.INSTANCE.rename(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID), behindApplicationId); -// nodeRefResSumObj.addProperty(ColumnNameUtils.INSTANCE.rename(ApplicationReferenceMetricTable.COLUMN_S1_LTE), s1LTE.getValue()); -// nodeRefResSumObj.addProperty(ColumnNameUtils.INSTANCE.rename(ApplicationReferenceMetricTable.COLUMN_S3_LTE), s3LTE.getValue()); -// nodeRefResSumObj.addProperty(ColumnNameUtils.INSTANCE.rename(ApplicationReferenceMetricTable.COLUMN_S5_LTE), s5LTE.getValue()); -// nodeRefResSumObj.addProperty(ColumnNameUtils.INSTANCE.rename(ApplicationReferenceMetricTable.COLUMN_S5_GT), s5GT.getValue()); -// nodeRefResSumObj.addProperty(ColumnNameUtils.INSTANCE.rename(ApplicationReferenceMetricTable.COLUMN_ERROR), error.getValue()); -// nodeRefResSumObj.addProperty(ColumnNameUtils.INSTANCE.rename(ApplicationReferenceMetricTable.COLUMN_SUMMARY), summary.getValue()); -// nodeRefResSumArray.add(nodeRefResSumObj); -// } -// } -// } - - return applicationReferenceMetricArray; - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/GCMetricEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/GCMetricEsUIDAO.java deleted file mode 100644 index 068955095..000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/GCMetricEsUIDAO.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.es.dao; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.apache.skywalking.apm.collector.core.util.Const; -import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.apache.skywalking.apm.collector.storage.dao.IGCMetricUIDAO; -import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetricTable; -import org.apache.skywalking.apm.network.proto.GCPhrase; -import org.elasticsearch.action.get.GetResponse; -import org.elasticsearch.action.get.MultiGetItemResponse; -import org.elasticsearch.action.get.MultiGetRequestBuilder; -import org.elasticsearch.action.get.MultiGetResponse; -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.QueryBuilders; -import org.elasticsearch.search.aggregations.AggregationBuilders; -import org.elasticsearch.search.aggregations.bucket.terms.Terms; -import org.elasticsearch.search.aggregations.metrics.sum.Sum; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class GCMetricEsUIDAO extends EsDAO implements IGCMetricUIDAO { - - private final Logger logger = LoggerFactory.getLogger(GCMetricEsUIDAO.class); - - public GCMetricEsUIDAO(ElasticSearchClient client) { - super(client); - } - - @Override public GCCount getGCCount(long[] timeBuckets, int instanceId) { - logger.debug("get gc count, timeBuckets: {}, instanceId: {}", timeBuckets, instanceId); - SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(GCMetricTable.TABLE); - searchRequestBuilder.setTypes(GCMetricTable.TABLE_TYPE); - searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); - - BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); - boolQuery.must().add(QueryBuilders.termQuery(GCMetricTable.COLUMN_INSTANCE_ID, instanceId)); - boolQuery.must().add(QueryBuilders.termsQuery(GCMetricTable.COLUMN_TIME_BUCKET, timeBuckets)); - - searchRequestBuilder.setQuery(boolQuery); - searchRequestBuilder.setSize(0); - searchRequestBuilder.addAggregation( - AggregationBuilders.terms(GCMetricTable.COLUMN_PHRASE).field(GCMetricTable.COLUMN_PHRASE) - .subAggregation(AggregationBuilders.sum(GCMetricTable.COLUMN_COUNT).field(GCMetricTable.COLUMN_COUNT))); - - SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); - - GCCount gcCount = new GCCount(); - Terms phraseAggregation = searchResponse.getAggregations().get(GCMetricTable.COLUMN_PHRASE); - for (Terms.Bucket phraseBucket : phraseAggregation.getBuckets()) { - int phrase = phraseBucket.getKeyAsNumber().intValue(); - Sum sumAggregation = phraseBucket.getAggregations().get(GCMetricTable.COLUMN_COUNT); - int count = (int)sumAggregation.getValue(); - - if (phrase == GCPhrase.NEW_VALUE) { - gcCount.setYoung(count); - } else if (phrase == GCPhrase.OLD_VALUE) { - gcCount.setOld(count); - } - } - - return gcCount; - } - - @Override public JsonObject getMetric(int instanceId, long timeBucket) { - JsonObject response = new JsonObject(); - - String youngId = timeBucket + Const.ID_SPLIT + GCPhrase.NEW_VALUE + instanceId; - GetResponse youngResponse = getClient().prepareGet(GCMetricTable.TABLE, youngId).get(); - if (youngResponse.isExists()) { - response.addProperty("ygc", ((Number)youngResponse.getSource().get(GCMetricTable.COLUMN_COUNT)).intValue()); - } - - String oldId = timeBucket + Const.ID_SPLIT + GCPhrase.OLD_VALUE + instanceId; - GetResponse oldResponse = getClient().prepareGet(GCMetricTable.TABLE, oldId).get(); - if (oldResponse.isExists()) { - response.addProperty("ogc", ((Number)oldResponse.getSource().get(GCMetricTable.COLUMN_COUNT)).intValue()); - } - - return response; - } - - @Override public JsonObject getMetric(int instanceId, long startTimeBucket, long endTimeBucket) { - JsonObject response = new JsonObject(); - - MultiGetRequestBuilder youngPrepareMultiGet = getClient().prepareMultiGet(); - long timeBucket = startTimeBucket; - do { - timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1); - String youngId = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + GCPhrase.NEW_VALUE; - youngPrepareMultiGet.add(GCMetricTable.TABLE, GCMetricTable.TABLE_TYPE, youngId); - } - while (timeBucket <= endTimeBucket); - - JsonArray youngArray = new JsonArray(); - MultiGetResponse multiGetResponse = youngPrepareMultiGet.get(); - for (MultiGetItemResponse itemResponse : multiGetResponse.getResponses()) { - if (itemResponse.getResponse().isExists()) { - youngArray.add(((Number)itemResponse.getResponse().getSource().get(GCMetricTable.COLUMN_COUNT)).intValue()); - } else { - youngArray.add(0); - } - } - response.add("ygc", youngArray); - - MultiGetRequestBuilder oldPrepareMultiGet = getClient().prepareMultiGet(); - timeBucket = startTimeBucket; - do { - timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1); - String oldId = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + GCPhrase.OLD_VALUE; - oldPrepareMultiGet.add(GCMetricTable.TABLE, GCMetricTable.TABLE_TYPE, oldId); - } - while (timeBucket <= endTimeBucket); - - JsonArray oldArray = new JsonArray(); - - multiGetResponse = oldPrepareMultiGet.get(); - for (MultiGetItemResponse itemResponse : multiGetResponse.getResponses()) { - if (itemResponse.getResponse().isExists()) { - oldArray.add(((Number)itemResponse.getResponse().getSource().get(GCMetricTable.COLUMN_COUNT)).intValue()); - } else { - oldArray.add(0); - } - } - response.add("ogc", oldArray); - - return response; - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/InstanceMetricEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/InstanceMetricEsUIDAO.java deleted file mode 100644 index de6657339..000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/InstanceMetricEsUIDAO.java +++ /dev/null @@ -1,143 +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; - -import com.google.gson.JsonArray; -import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.apache.skywalking.apm.collector.core.util.Const; -import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.apache.skywalking.apm.collector.storage.dao.IInstanceMetricUIDAO; -import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.apache.skywalking.apm.collector.storage.table.instance.InstanceMetricTable; -import org.elasticsearch.action.get.GetResponse; -import org.elasticsearch.action.get.MultiGetItemResponse; -import org.elasticsearch.action.get.MultiGetRequestBuilder; -import org.elasticsearch.action.get.MultiGetResponse; -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.QueryBuilders; -import org.elasticsearch.search.aggregations.AggregationBuilders; -import org.elasticsearch.search.aggregations.metrics.sum.Sum; -import org.elasticsearch.search.sort.SortOrder; - -/** - * @author peng-yongsheng - */ -public class InstanceMetricEsUIDAO extends EsDAO implements IInstanceMetricUIDAO { - - public InstanceMetricEsUIDAO(ElasticSearchClient client) { - super(client); - } - - @Override public InstanceMetric get(long[] timeBuckets, int instanceId) { - SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(InstanceMetricTable.TABLE); - searchRequestBuilder.setTypes(InstanceMetricTable.TABLE_TYPE); - searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); - - BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); - boolQuery.must().add(QueryBuilders.termQuery(InstanceMetricTable.COLUMN_INSTANCE_ID, instanceId)); - boolQuery.must().add(QueryBuilders.termsQuery(InstanceMetricTable.COLUMN_TIME_BUCKET, timeBuckets)); - - searchRequestBuilder.setQuery(boolQuery); - searchRequestBuilder.setSize(0); - searchRequestBuilder.addSort(InstanceMetricTable.COLUMN_INSTANCE_ID, SortOrder.ASC); - - searchRequestBuilder.addAggregation(AggregationBuilders.sum(InstanceMetricTable.COLUMN_TRANSACTION_CALLS).field(InstanceMetricTable.COLUMN_TRANSACTION_CALLS)); - searchRequestBuilder.addAggregation(AggregationBuilders.sum(InstanceMetricTable.COLUMN_TRANSACTION_DURATION_SUM).field(InstanceMetricTable.COLUMN_TRANSACTION_DURATION_SUM)); - - SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); - Sum sumCalls = searchResponse.getAggregations().get(InstanceMetricTable.COLUMN_TRANSACTION_CALLS); - Sum sumCostTotal = searchResponse.getAggregations().get(InstanceMetricTable.COLUMN_TRANSACTION_DURATION_SUM); - return new InstanceMetric(instanceId, (long)sumCalls.getValue(), (long)sumCostTotal.getValue()); - } - - @Override public long getTpsMetric(int instanceId, long timeBucket) { - String id = timeBucket + Const.ID_SPLIT + instanceId; - GetResponse getResponse = getClient().prepareGet(InstanceMetricTable.TABLE, id).get(); - - if (getResponse.isExists()) { - return ((Number)getResponse.getSource().get(InstanceMetricTable.COLUMN_TRANSACTION_CALLS)).longValue(); - } - return 0; - } - - @Override public JsonArray getTpsMetric(int instanceId, long startTimeBucket, long endTimeBucket) { - MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet(); - - long timeBucket = startTimeBucket; - do { - String id = timeBucket + Const.ID_SPLIT + instanceId; - prepareMultiGet.add(InstanceMetricTable.TABLE, InstanceMetricTable.TABLE_TYPE, id); - timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1); - } - while (timeBucket <= endTimeBucket); - - JsonArray metrics = new JsonArray(); - MultiGetResponse multiGetResponse = prepareMultiGet.get(); - for (MultiGetItemResponse response : multiGetResponse.getResponses()) { - if (response.getResponse().isExists()) { - metrics.add(((Number)response.getResponse().getSource().get(InstanceMetricTable.COLUMN_TRANSACTION_CALLS)).longValue()); - } else { - metrics.add(0); - } - } - return metrics; - } - - @Override public long getRespTimeMetric(int instanceId, long timeBucket) { - String id = timeBucket + Const.ID_SPLIT + instanceId; - GetResponse getResponse = getClient().prepareGet(InstanceMetricTable.TABLE, id).get(); - - if (getResponse.isExists()) { - long callTimes = ((Number)getResponse.getSource().get(InstanceMetricTable.COLUMN_TRANSACTION_CALLS)).longValue(); - long costTotal = ((Number)getResponse.getSource().get(InstanceMetricTable.COLUMN_TRANSACTION_DURATION_SUM)).longValue(); - return costTotal / callTimes; - } - return 0; - } - - @Override public JsonArray getRespTimeMetric(int instanceId, long startTimeBucket, long endTimeBucket) { - MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet(); - - int i = 0; - long timeBucket; - do { - timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), startTimeBucket, i); - String id = timeBucket + Const.ID_SPLIT + instanceId; - prepareMultiGet.add(InstanceMetricTable.TABLE, InstanceMetricTable.TABLE_TYPE, id); - i++; - } - while (timeBucket <= endTimeBucket); - - JsonArray metrics = new JsonArray(); - MultiGetResponse multiGetResponse = prepareMultiGet.get(); - for (MultiGetItemResponse response : multiGetResponse.getResponses()) { - if (response.getResponse().isExists()) { - long callTimes = ((Number)response.getResponse().getSource().get(InstanceMetricTable.COLUMN_TRANSACTION_CALLS)).longValue(); - long costTotal = ((Number)response.getResponse().getSource().get(InstanceMetricTable.COLUMN_TRANSACTION_DURATION_SUM)).longValue(); - metrics.add(costTotal / callTimes); - } else { - metrics.add(0); - } - } - return metrics; - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/MemoryMetricEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/MemoryMetricEsUIDAO.java deleted file mode 100644 index 8caa326e7..000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/MemoryMetricEsUIDAO.java +++ /dev/null @@ -1,89 +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; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.apache.skywalking.apm.collector.core.util.Const; -import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.apache.skywalking.apm.collector.storage.dao.IMemoryMetricUIDAO; -import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.apache.skywalking.apm.collector.storage.table.jvm.MemoryMetricTable; -import org.elasticsearch.action.get.GetResponse; -import org.elasticsearch.action.get.MultiGetItemResponse; -import org.elasticsearch.action.get.MultiGetRequestBuilder; -import org.elasticsearch.action.get.MultiGetResponse; - -/** - * @author peng-yongsheng - */ -public class MemoryMetricEsUIDAO extends EsDAO implements IMemoryMetricUIDAO { - - public MemoryMetricEsUIDAO(ElasticSearchClient client) { - super(client); - } - - @Override public JsonObject getMetric(int instanceId, long timeBucket, boolean isHeap) { - String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + isHeap; - GetResponse getResponse = getClient().prepareGet(MemoryMetricTable.TABLE, id).get(); - - JsonObject metric = new JsonObject(); - if (getResponse.isExists()) { - metric.addProperty("max", ((Number)getResponse.getSource().get(MemoryMetricTable.COLUMN_MAX)).intValue()); - metric.addProperty("init", ((Number)getResponse.getSource().get(MemoryMetricTable.COLUMN_INIT)).intValue()); - metric.addProperty("used", ((Number)getResponse.getSource().get(MemoryMetricTable.COLUMN_USED)).intValue()); - } else { - metric.addProperty("max", 0); - metric.addProperty("init", 0); - metric.addProperty("used", 0); - } - return metric; - } - - @Override public JsonObject getMetric(int instanceId, long startTimeBucket, long endTimeBucket, boolean isHeap) { - MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet(); - - int i = 0; - long timeBucket = startTimeBucket; - do { - timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1); - String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + isHeap; - prepareMultiGet.add(MemoryMetricTable.TABLE, MemoryMetricTable.TABLE_TYPE, id); - } - while (timeBucket <= endTimeBucket); - - JsonObject metric = new JsonObject(); - JsonArray usedMetric = new JsonArray(); - MultiGetResponse multiGetResponse = prepareMultiGet.get(); - for (MultiGetItemResponse response : multiGetResponse.getResponses()) { - if (response.getResponse().isExists()) { - metric.addProperty("max", ((Number)response.getResponse().getSource().get(MemoryMetricTable.COLUMN_MAX)).longValue()); - metric.addProperty("init", ((Number)response.getResponse().getSource().get(MemoryMetricTable.COLUMN_INIT)).longValue()); - usedMetric.add(((Number)response.getResponse().getSource().get(MemoryMetricTable.COLUMN_USED)).longValue()); - } else { - metric.addProperty("max", 0); - metric.addProperty("init", 0); - usedMetric.add(0); - } - } - metric.add("used", usedMetric); - return metric; - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/SegmentCostEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/SegmentCostEsUIDAO.java deleted file mode 100644 index a99c8bbbb..000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/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; - -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.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/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/ServiceReferenceEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ServiceReferenceEsUIDAO.java deleted file mode 100644 index ff24c32d3..000000000 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ServiceReferenceEsUIDAO.java +++ /dev/null @@ -1,115 +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; - -import com.google.gson.JsonObject; -import java.util.LinkedHashMap; -import java.util.Map; -import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.apache.skywalking.apm.collector.core.util.ColumnNameUtils; -import org.apache.skywalking.apm.collector.core.util.Const; -import org.apache.skywalking.apm.collector.storage.dao.IServiceReferenceUIDAO; -import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.apache.skywalking.apm.collector.storage.table.service.ServiceReferenceMetricTable; -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.QueryBuilders; -import org.elasticsearch.search.aggregations.AggregationBuilders; -import org.elasticsearch.search.aggregations.bucket.terms.Terms; -import org.elasticsearch.search.aggregations.metrics.sum.Sum; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class ServiceReferenceEsUIDAO extends EsDAO implements IServiceReferenceUIDAO { - - private final Logger logger = LoggerFactory.getLogger(ServiceReferenceEsUIDAO.class); - - public ServiceReferenceEsUIDAO(ElasticSearchClient client) { - super(client); - } - - @Override - public Map load(int entryServiceId, long startTime, long endTime) { - SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(ServiceReferenceMetricTable.TABLE); - searchRequestBuilder.setTypes(ServiceReferenceMetricTable.TABLE_TYPE); - searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); - - BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); - boolQuery.must().add(QueryBuilders.rangeQuery(ServiceReferenceMetricTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime)); - boolQuery.must().add(QueryBuilders.rangeQuery(ServiceReferenceMetricTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime)); - - searchRequestBuilder.setQuery(boolQuery); - searchRequestBuilder.setSize(0); - - return load(searchRequestBuilder); - } - - private Map load(SearchRequestBuilder searchRequestBuilder) { - searchRequestBuilder.addAggregation(AggregationBuilders.terms(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID).field(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID).size(100) - .subAggregation(AggregationBuilders.terms(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID).field(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID).size(100) - .subAggregation(AggregationBuilders.sum(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS).field(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS)) - .subAggregation(AggregationBuilders.sum(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS).field(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS)) - .subAggregation(AggregationBuilders.sum(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM).field(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM)) - .subAggregation(AggregationBuilders.sum(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM).field(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM)))); - - Map serviceReferenceMap = new LinkedHashMap<>(); - - SearchResponse searchResponse = searchRequestBuilder.get(); - Terms frontServiceIdTerms = searchResponse.getAggregations().get(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID); - for (Terms.Bucket frontServiceBucket : frontServiceIdTerms.getBuckets()) { - int frontServiceId = frontServiceBucket.getKeyAsNumber().intValue(); - if (frontServiceId != 0) { - parseSubAggregate(serviceReferenceMap, frontServiceBucket, frontServiceId); - } - } - - return serviceReferenceMap; - } - - private void parseSubAggregate(Map serviceReferenceMap, - Terms.Bucket frontServiceBucket, - int frontServiceId) { - Terms behindServiceIdTerms = frontServiceBucket.getAggregations().get(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID); - for (Terms.Bucket behindServiceIdBucket : behindServiceIdTerms.getBuckets()) { - int behindServiceId = behindServiceIdBucket.getKeyAsNumber().intValue(); - if (behindServiceId != 0) { - Sum calls = behindServiceIdBucket.getAggregations().get(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS); - Sum errorCalls = behindServiceIdBucket.getAggregations().get(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS); - Sum durationSum = behindServiceIdBucket.getAggregations().get(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM); - Sum errorDurationSum = behindServiceIdBucket.getAggregations().get(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM); - - JsonObject serviceReference = new JsonObject(); - serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID), frontServiceId); - serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID), behindServiceId); - serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS), (long)calls.getValue()); - serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS), (long)errorCalls.getValue()); - serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM), (long)durationSum.getValue()); - serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM), (long)errorDurationSum.getValue()); - - String id = serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID)) + Const.ID_SPLIT + serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID)); - serviceReferenceMap.put(id, serviceReference); - } - } - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/acp/AbstractApplicationComponentEsPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/acp/AbstractApplicationComponentEsPersistenceDAO.java index e729b4b78..bd405e2ff 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/acp/AbstractApplicationComponentEsPersistenceDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/acp/AbstractApplicationComponentEsPersistenceDAO.java @@ -44,7 +44,7 @@ public abstract class AbstractApplicationComponentEsPersistenceDAO extends Abstr applicationComponent.setMetricId((String)source.get(ApplicationComponentTable.COLUMN_METRIC_ID)); applicationComponent.setComponentId(((Number)source.get(ApplicationComponentTable.COLUMN_COMPONENT_ID)).intValue()); - applicationComponent.setPeerId(((Number)source.get(ApplicationComponentTable.COLUMN_PEER_ID)).intValue()); + applicationComponent.setApplicationId(((Number)source.get(ApplicationComponentTable.COLUMN_APPLICATION_ID)).intValue()); applicationComponent.setTimeBucket(((Number)source.get(ApplicationComponentTable.COLUMN_TIME_BUCKET)).longValue()); return applicationComponent; } @@ -55,7 +55,7 @@ public abstract class AbstractApplicationComponentEsPersistenceDAO extends Abstr source.put(ApplicationComponentTable.COLUMN_METRIC_ID, streamData.getMetricId()); source.put(ApplicationComponentTable.COLUMN_COMPONENT_ID, streamData.getComponentId()); - source.put(ApplicationComponentTable.COLUMN_PEER_ID, streamData.getPeerId()); + source.put(ApplicationComponentTable.COLUMN_APPLICATION_ID, streamData.getApplicationId()); source.put(ApplicationComponentTable.COLUMN_TIME_BUCKET, streamData.getTimeBucket()); return source; diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ampp/AbstractApplicationMappingEsPersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ampp/AbstractApplicationMappingEsPersistenceDAO.java index 4bea4052e..c53681248 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ampp/AbstractApplicationMappingEsPersistenceDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ampp/AbstractApplicationMappingEsPersistenceDAO.java @@ -44,7 +44,7 @@ public abstract class AbstractApplicationMappingEsPersistenceDAO extends Abstrac applicationMapping.setMetricId((String)source.get(ApplicationMappingTable.COLUMN_METRIC_ID)); applicationMapping.setApplicationId(((Number)source.get(ApplicationMappingTable.COLUMN_APPLICATION_ID)).intValue()); - applicationMapping.setAddressId(((Number)source.get(ApplicationMappingTable.COLUMN_ADDRESS_ID)).intValue()); + applicationMapping.setMappingApplicationId(((Number)source.get(ApplicationMappingTable.COLUMN_MAPPING_APPLICATION_ID)).intValue()); applicationMapping.setTimeBucket(((Number)source.get(ApplicationMappingTable.COLUMN_TIME_BUCKET)).longValue()); return applicationMapping; } @@ -55,7 +55,7 @@ public abstract class AbstractApplicationMappingEsPersistenceDAO extends Abstrac source.put(ApplicationMappingTable.COLUMN_METRIC_ID, streamData.getMetricId()); source.put(ApplicationMappingTable.COLUMN_APPLICATION_ID, streamData.getApplicationId()); - source.put(ApplicationMappingTable.COLUMN_ADDRESS_ID, streamData.getAddressId()); + source.put(ApplicationMappingTable.COLUMN_MAPPING_APPLICATION_ID, streamData.getMappingApplicationId()); source.put(ApplicationMappingTable.COLUMN_TIME_BUCKET, streamData.getTimeBucket()); return source; diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/cache/ApplicationEsCacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/cache/ApplicationEsCacheDAO.java index f886b0ff0..ded51ed6c 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/cache/ApplicationEsCacheDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/cache/ApplicationEsCacheDAO.java @@ -20,9 +20,9 @@ package org.apache.skywalking.apm.collector.storage.es.dao.cache; 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.Const; import org.apache.skywalking.apm.collector.storage.dao.cache.IApplicationCacheDAO; import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.register.Application; import org.apache.skywalking.apm.collector.storage.table.register.ApplicationTable; import org.elasticsearch.action.get.GetRequestBuilder; import org.elasticsearch.action.get.GetResponse; @@ -68,16 +68,20 @@ public class ApplicationEsCacheDAO extends EsDAO implements IApplicationCacheDAO return 0; } - @Override public String getApplicationCode(int applicationId) { + @Override public Application getApplication(int applicationId) { logger.debug("get application code, applicationId: {}", applicationId); ElasticSearchClient client = getClient(); GetRequestBuilder getRequestBuilder = client.prepareGet(ApplicationTable.TABLE, String.valueOf(applicationId)); GetResponse getResponse = getRequestBuilder.get(); if (getResponse.isExists()) { - return (String)getResponse.getSource().get(ApplicationTable.COLUMN_APPLICATION_CODE); + Application application = new Application(); + application.setApplicationId(applicationId); + application.setApplicationCode((String)getResponse.getSource().get(ApplicationTable.COLUMN_APPLICATION_CODE)); + application.setIsAddress(((Number)getResponse.getSource().get(ApplicationTable.COLUMN_IS_ADDRESS)).intValue()); + return application; } - return Const.EMPTY_STRING; + return null; } @Override public int getApplicationIdByAddressId(int addressId) { diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/cache/ServiceNameEsCacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/cache/ServiceNameEsCacheDAO.java index 5a4fb8aef..1d157667b 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/cache/ServiceNameEsCacheDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/cache/ServiceNameEsCacheDAO.java @@ -19,9 +19,9 @@ package org.apache.skywalking.apm.collector.storage.es.dao.cache; import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.apache.skywalking.apm.collector.core.util.Const; import org.apache.skywalking.apm.collector.storage.dao.cache.IServiceNameCacheDAO; import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.register.ServiceName; import org.apache.skywalking.apm.collector.storage.table.register.ServiceNameTable; import org.elasticsearch.action.get.GetRequestBuilder; import org.elasticsearch.action.get.GetResponse; @@ -41,16 +41,19 @@ public class ServiceNameEsCacheDAO extends EsDAO implements IServiceNameCacheDAO super(client); } - @Override public String getServiceName(int serviceId) { + @Override public ServiceName get(int serviceId) { GetRequestBuilder getRequestBuilder = getClient().prepareGet(ServiceNameTable.TABLE, String.valueOf(serviceId)); GetResponse getResponse = getRequestBuilder.get(); + if (getResponse.isExists()) { - String serviceName = (String)getResponse.getSource().get(ServiceNameTable.COLUMN_SERVICE_NAME); - int applicationId = ((Number)getResponse.getSource().get(ServiceNameTable.COLUMN_APPLICATION_ID)).intValue(); - return applicationId + Const.ID_SPLIT + serviceName; + ServiceName serviceName = new ServiceName(); + serviceName.setApplicationId(((Number)getResponse.getSource().get(ServiceNameTable.COLUMN_APPLICATION_ID)).intValue()); + serviceName.setServiceId(serviceId); + serviceName.setServiceName((String)getResponse.getSource().get(ServiceNameTable.COLUMN_SERVICE_NAME)); + return serviceName; } - return Const.EMPTY_STRING; + return null; } @Override public int getServiceId(int applicationId, String serviceName) { diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/register/InstanceRegisterEsDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/register/InstanceRegisterEsDAO.java index c9b54be66..460b3e3fe 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/register/InstanceRegisterEsDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/register/InstanceRegisterEsDAO.java @@ -21,6 +21,7 @@ package org.apache.skywalking.apm.collector.storage.es.dao.register; 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.register.IInstanceRegisterDAO; import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; import org.apache.skywalking.apm.collector.storage.table.register.Instance; @@ -57,8 +58,8 @@ public class InstanceRegisterEsDAO extends EsDAO implements IInstanceRegisterDAO source.put(InstanceTable.COLUMN_INSTANCE_ID, instance.getInstanceId()); source.put(InstanceTable.COLUMN_APPLICATION_ID, instance.getApplicationId()); source.put(InstanceTable.COLUMN_AGENT_UUID, instance.getAgentUUID()); - source.put(InstanceTable.COLUMN_REGISTER_TIME, instance.getRegisterTime()); - source.put(InstanceTable.COLUMN_HEARTBEAT_TIME, instance.getHeartBeatTime()); + source.put(InstanceTable.COLUMN_REGISTER_TIME, TimeBucketUtils.INSTANCE.getSecondTimeBucket(instance.getRegisterTime())); + source.put(InstanceTable.COLUMN_HEARTBEAT_TIME, TimeBucketUtils.INSTANCE.getSecondTimeBucket(instance.getHeartBeatTime())); source.put(InstanceTable.COLUMN_OS_INFO, instance.getOsInfo()); source.put(InstanceTable.COLUMN_ADDRESS_ID, instance.getAddressId()); source.put(InstanceTable.COLUMN_IS_ADDRESS, instance.getIsAddress()); @@ -76,7 +77,7 @@ public class InstanceRegisterEsDAO extends EsDAO implements IInstanceRegisterDAO updateRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); Map source = new HashMap<>(); - source.put(InstanceTable.COLUMN_HEARTBEAT_TIME, heartbeatTime); + source.put(InstanceTable.COLUMN_HEARTBEAT_TIME, TimeBucketUtils.INSTANCE.getSecondTimeBucket(heartbeatTime)); updateRequest.doc(source); client.update(updateRequest); diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/register/NetworkAddressRegisterEsDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/register/NetworkAddressRegisterEsDAO.java index 051a8ea30..a59b6c66b 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/register/NetworkAddressRegisterEsDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/register/NetworkAddressRegisterEsDAO.java @@ -55,6 +55,7 @@ public class NetworkAddressRegisterEsDAO extends EsDAO implements INetworkAddres Map source = new HashMap<>(); source.put(NetworkAddressTable.COLUMN_NETWORK_ADDRESS, networkAddress.getNetworkAddress()); source.put(NetworkAddressTable.COLUMN_ADDRESS_ID, networkAddress.getAddressId()); + source.put(NetworkAddressTable.COLUMN_SPAN_LAYER, networkAddress.getSpanLayer()); IndexResponse response = client.prepareIndex(NetworkAddressTable.TABLE, networkAddress.getId()).setSource(source).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get(); logger.debug("save network address register info, address getId: {}, network address code: {}, status: {}", networkAddress.getAddressId(), networkAddress.getNetworkAddress(), response.status().name()); diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationComponentEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/ApplicationComponentEsUIDAO.java similarity index 65% rename from apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationComponentEsUIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/ApplicationComponentEsUIDAO.java index d77825ec2..be40e5ee2 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationComponentEsUIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/ApplicationComponentEsUIDAO.java @@ -16,15 +16,16 @@ * */ -package org.apache.skywalking.apm.collector.storage.es.dao; +package org.apache.skywalking.apm.collector.storage.es.dao.ui; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; +import java.util.LinkedList; +import java.util.List; import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.apache.skywalking.apm.collector.storage.dao.IApplicationComponentUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationComponentUIDAO; import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; -import org.apache.skywalking.apm.collector.storage.es.dao.acp.ApplicationComponentMinuteEsPersistenceDAO; import org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponentTable; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder; import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchType; @@ -39,51 +40,47 @@ import org.slf4j.LoggerFactory; */ public class ApplicationComponentEsUIDAO extends EsDAO implements IApplicationComponentUIDAO { - private final Logger logger = LoggerFactory.getLogger(ApplicationComponentMinuteEsPersistenceDAO.class); + private final Logger logger = LoggerFactory.getLogger(ApplicationComponentEsUIDAO.class); public ApplicationComponentEsUIDAO(ElasticSearchClient client) { super(client); } - @Override public JsonArray load(long startTime, long endTime) { + @Override public List load(Step step, long startTime, long endTime) { logger.debug("application component load, start time: {}, end time: {}", startTime, endTime); - JsonArray applicationComponentArray = new JsonArray(); - applicationComponentArray.addAll(aggregationByComponentId(startTime, endTime)); - return applicationComponentArray; - } - - private JsonArray aggregationByComponentId(long startTime, long endTime) { - SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(ApplicationComponentTable.TABLE); + String tableName = TimePyramidTableNameBuilder.build(step, ApplicationComponentTable.TABLE); + SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName); searchRequestBuilder.setTypes(ApplicationComponentTable.TABLE_TYPE); searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); searchRequestBuilder.setQuery(QueryBuilders.rangeQuery(ApplicationComponentTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime)); searchRequestBuilder.setSize(0); searchRequestBuilder.addAggregation(AggregationBuilders.terms(ApplicationComponentTable.COLUMN_COMPONENT_ID).field(ApplicationComponentTable.COLUMN_COMPONENT_ID).size(100) - .subAggregation(AggregationBuilders.terms(ApplicationComponentTable.COLUMN_PEER_ID).field(ApplicationComponentTable.COLUMN_PEER_ID).size(100))); + .subAggregation(AggregationBuilders.terms(ApplicationComponentTable.COLUMN_APPLICATION_ID).field(ApplicationComponentTable.COLUMN_APPLICATION_ID).size(100))); SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); Terms componentIdTerms = searchResponse.getAggregations().get(ApplicationComponentTable.COLUMN_COMPONENT_ID); - JsonArray applicationComponentArray = new JsonArray(); + + List applicationComponents = new LinkedList<>(); for (Terms.Bucket componentIdBucket : componentIdTerms.getBuckets()) { int componentId = componentIdBucket.getKeyAsNumber().intValue(); - buildComponentArray(componentIdBucket, componentId, applicationComponentArray); + buildApplicationComponents(componentIdBucket, componentId, applicationComponents); } - return applicationComponentArray; + return applicationComponents; } - private void buildComponentArray(Terms.Bucket componentBucket, int componentId, - JsonArray applicationComponentArray) { - Terms peerIdTerms = componentBucket.getAggregations().get(ApplicationComponentTable.COLUMN_PEER_ID); + private void buildApplicationComponents(Terms.Bucket componentBucket, int componentId, + List applicationComponents) { + Terms peerIdTerms = componentBucket.getAggregations().get(ApplicationComponentTable.COLUMN_APPLICATION_ID); for (Terms.Bucket peerIdBucket : peerIdTerms.getBuckets()) { - int peerId = peerIdBucket.getKeyAsNumber().intValue(); + int applicationId = peerIdBucket.getKeyAsNumber().intValue(); - JsonObject applicationComponentObj = new JsonObject(); - applicationComponentObj.addProperty(ApplicationComponentTable.COLUMN_COMPONENT_ID, componentId); - applicationComponentObj.addProperty(ApplicationComponentTable.COLUMN_PEER_ID, peerId); - applicationComponentArray.add(applicationComponentObj); + ApplicationComponent applicationComponent = new ApplicationComponent(); + applicationComponent.setComponentId(componentId); + applicationComponent.setApplicationId(applicationId); + applicationComponents.add(applicationComponent); } } } diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationMappingEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/ApplicationMappingEsUIDAO.java similarity index 72% rename from apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationMappingEsUIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/ApplicationMappingEsUIDAO.java index 4bb7ae6fa..227e1094f 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ApplicationMappingEsUIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/ApplicationMappingEsUIDAO.java @@ -16,14 +16,16 @@ * */ -package org.apache.skywalking.apm.collector.storage.es.dao; +package org.apache.skywalking.apm.collector.storage.es.dao.ui; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; +import java.util.LinkedList; +import java.util.List; import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.apache.skywalking.apm.collector.storage.dao.IApplicationMappingUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMappingUIDAO; import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMappingTable; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder; import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchType; @@ -44,8 +46,10 @@ public class ApplicationMappingEsUIDAO extends EsDAO implements IApplicationMapp super(client); } - @Override public JsonArray load(long startTime, long endTime) { - SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(ApplicationMappingTable.TABLE); + @Override public List load(Step step, long startTime, long endTime) { + String tableName = TimePyramidTableNameBuilder.build(step, ApplicationMappingTable.TABLE); + + SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName); searchRequestBuilder.setTypes(ApplicationMappingTable.TABLE_TYPE); searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); searchRequestBuilder.setQuery(QueryBuilders.rangeQuery(ApplicationMappingTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime)); @@ -53,24 +57,25 @@ public class ApplicationMappingEsUIDAO extends EsDAO implements IApplicationMapp searchRequestBuilder.addAggregation( AggregationBuilders.terms(ApplicationMappingTable.COLUMN_APPLICATION_ID).field(ApplicationMappingTable.COLUMN_APPLICATION_ID).size(100) - .subAggregation(AggregationBuilders.terms(ApplicationMappingTable.COLUMN_ADDRESS_ID).field(ApplicationMappingTable.COLUMN_ADDRESS_ID).size(100))); + .subAggregation(AggregationBuilders.terms(ApplicationMappingTable.COLUMN_MAPPING_APPLICATION_ID).field(ApplicationMappingTable.COLUMN_MAPPING_APPLICATION_ID).size(100))); SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); Terms applicationIdTerms = searchResponse.getAggregations().get(ApplicationMappingTable.COLUMN_APPLICATION_ID); - JsonArray applicationMappingArray = new JsonArray(); + List applicationMappings = new LinkedList<>(); for (Terms.Bucket applicationIdBucket : applicationIdTerms.getBuckets()) { int applicationId = applicationIdBucket.getKeyAsNumber().intValue(); - Terms addressIdTerms = applicationIdBucket.getAggregations().get(ApplicationMappingTable.COLUMN_ADDRESS_ID); + Terms addressIdTerms = applicationIdBucket.getAggregations().get(ApplicationMappingTable.COLUMN_MAPPING_APPLICATION_ID); for (Terms.Bucket addressIdBucket : addressIdTerms.getBuckets()) { int addressId = addressIdBucket.getKeyAsNumber().intValue(); - JsonObject applicationMappingObj = new JsonObject(); - applicationMappingObj.addProperty(ApplicationMappingTable.COLUMN_APPLICATION_ID, applicationId); - applicationMappingObj.addProperty(ApplicationMappingTable.COLUMN_ADDRESS_ID, addressId); - applicationMappingArray.add(applicationMappingObj); + + ApplicationMapping applicationMapping = new ApplicationMapping(); + applicationMapping.setApplicationId(applicationId); + applicationMapping.setMappingApplicationId(addressId); + applicationMappings.add(applicationMapping); } } - logger.debug("application mapping data: {}", applicationMappingArray.toString()); - return applicationMappingArray; + logger.debug("application mapping data: {}", applicationMappings.toString()); + return applicationMappings; } } diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/ApplicationReferenceMetricEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/ApplicationReferenceMetricEsUIDAO.java new file mode 100644 index 000000000..8ea887e85 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/ApplicationReferenceMetricEsUIDAO.java @@ -0,0 +1,177 @@ +/* + * 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.LinkedList; +import java.util.List; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationReferenceMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.MetricSource; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetricTable; +import org.apache.skywalking.apm.collector.storage.ui.common.Call; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder; +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.QueryBuilders; +import org.elasticsearch.search.aggregations.AggregationBuilders; +import org.elasticsearch.search.aggregations.bucket.terms.Terms; +import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder; +import org.elasticsearch.search.aggregations.metrics.sum.Sum; + +/** + * @author peng-yongsheng + */ +public class ApplicationReferenceMetricEsUIDAO extends EsDAO implements IApplicationReferenceMetricUIDAO { + + public ApplicationReferenceMetricEsUIDAO(ElasticSearchClient client) { + super(client); + } + + @Override public List getFrontApplications(Step step, int applicationId, long startTime, long endTime, + MetricSource metricSource) { + String tableName = TimePyramidTableNameBuilder.build(step, ApplicationReferenceMetricTable.TABLE); + + SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName); + searchRequestBuilder.setTypes(ApplicationReferenceMetricTable.TABLE_TYPE); + searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); + + BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); + boolQuery.must().add(QueryBuilders.rangeQuery(ApplicationReferenceMetricTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime)); + boolQuery.must().add(QueryBuilders.termQuery(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID, applicationId)); + boolQuery.must().add(QueryBuilders.termQuery(ApplicationReferenceMetricTable.COLUMN_SOURCE_VALUE, metricSource.getValue())); + + searchRequestBuilder.setQuery(boolQuery); + searchRequestBuilder.setSize(0); + + TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID).field(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID).size(100); + aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS).field(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS)); + aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM).field(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM)); + + searchRequestBuilder.addAggregation(aggregationBuilder); + SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); + + List nodes = new LinkedList<>(); + Terms frontApplicationIdTerms = searchResponse.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID); + for (Terms.Bucket frontApplicationIdBucket : frontApplicationIdTerms.getBuckets()) { + int frontApplicationId = frontApplicationIdBucket.getKeyAsNumber().intValue(); + Sum calls = frontApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS); + Sum responseTimes = frontApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM); + + Call call = new Call(); + call.setSource(frontApplicationId); + call.setTarget(applicationId); + call.setCalls((int)calls.getValue()); + call.setResponseTimes((int)responseTimes.getValue()); + nodes.add(call); + } + + return nodes; + } + + @Override public List getBehindApplications(Step step, int applicationId, long startTime, long endTime, + MetricSource metricSource) { + String tableName = TimePyramidTableNameBuilder.build(step, ApplicationReferenceMetricTable.TABLE); + + SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName); + searchRequestBuilder.setTypes(ApplicationReferenceMetricTable.TABLE_TYPE); + searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); + + BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); + boolQuery.must().add(QueryBuilders.rangeQuery(ApplicationReferenceMetricTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime)); + boolQuery.must().add(QueryBuilders.termQuery(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID, applicationId)); + boolQuery.must().add(QueryBuilders.termQuery(ApplicationReferenceMetricTable.COLUMN_SOURCE_VALUE, metricSource.getValue())); + + searchRequestBuilder.setQuery(boolQuery); + searchRequestBuilder.setSize(0); + + TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID).field(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID).size(100); + aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS).field(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS)); + aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM).field(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM)); + + searchRequestBuilder.addAggregation(aggregationBuilder); + SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); + + List nodes = new LinkedList<>(); + Terms behindApplicationIdTerms = searchResponse.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID); + for (Terms.Bucket behindApplicationIdBucket : behindApplicationIdTerms.getBuckets()) { + int behindApplicationId = behindApplicationIdBucket.getKeyAsNumber().intValue(); + Sum calls = behindApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS); + Sum responseTimes = behindApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM); + + Call call = new Call(); + call.setTarget(behindApplicationId); + call.setSource(applicationId); + call.setCalls((int)calls.getValue()); + call.setResponseTimes((int)responseTimes.getValue()); + nodes.add(call); + } + + return nodes; + } + + @Override public List getApplications(Step step, long startTime, long endTime, MetricSource metricSource) { + String tableName = TimePyramidTableNameBuilder.build(step, ApplicationReferenceMetricTable.TABLE); + + SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName); + searchRequestBuilder.setTypes(ApplicationReferenceMetricTable.TABLE_TYPE); + searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); + + BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); + boolQuery.must().add(QueryBuilders.rangeQuery(ApplicationReferenceMetricTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime)); + boolQuery.must().add(QueryBuilders.termQuery(ApplicationReferenceMetricTable.COLUMN_SOURCE_VALUE, metricSource.getValue())); + + searchRequestBuilder.setQuery(boolQuery); + searchRequestBuilder.setSize(0); + + TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID).field(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID).size(100) + .subAggregation(AggregationBuilders.terms(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID).field(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID)); + aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS).field(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS)); + aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM).field(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM)); + + searchRequestBuilder.addAggregation(aggregationBuilder); + SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); + + List nodes = new LinkedList<>(); + Terms frontApplicationIdTerms = searchResponse.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID); + for (Terms.Bucket frontApplicationIdBucket : frontApplicationIdTerms.getBuckets()) { + int frontApplicationId = frontApplicationIdBucket.getKeyAsNumber().intValue(); + + Terms behindApplicationIdTerms = frontApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID); + for (Terms.Bucket behindApplicationIdBucket : behindApplicationIdTerms.getBuckets()) { + int behindApplicationId = behindApplicationIdBucket.getKeyAsNumber().intValue(); + + Sum calls = behindApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS); + Sum responseTimes = behindApplicationIdBucket.getAggregations().get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM); + + Call call = new Call(); + call.setResponseTimes((int)responseTimes.getValue()); + call.setSource(frontApplicationId); + call.setTarget(behindApplicationId); + call.setCalls((int)calls.getValue()); + nodes.add(call); + } + } + + return nodes; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/CpuMetricEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/CpuMetricEsUIDAO.java similarity index 59% rename from apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/CpuMetricEsUIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/CpuMetricEsUIDAO.java index 9ca846133..bd07a4862 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/CpuMetricEsUIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/CpuMetricEsUIDAO.java @@ -16,16 +16,18 @@ * */ -package org.apache.skywalking.apm.collector.storage.es.dao; +package org.apache.skywalking.apm.collector.storage.es.dao.ui; -import com.google.gson.JsonArray; +import java.util.LinkedList; +import java.util.List; import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; import org.apache.skywalking.apm.collector.core.util.Const; -import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.apache.skywalking.apm.collector.storage.dao.ICpuMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.ICpuMetricUIDAO; import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; import org.apache.skywalking.apm.collector.storage.table.jvm.CpuMetricTable; -import org.elasticsearch.action.get.GetResponse; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.storage.utils.DurationPoint; +import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder; import org.elasticsearch.action.get.MultiGetItemResponse; import org.elasticsearch.action.get.MultiGetRequestBuilder; import org.elasticsearch.action.get.MultiGetResponse; @@ -39,37 +41,26 @@ public class CpuMetricEsUIDAO extends EsDAO implements ICpuMetricUIDAO { super(client); } - @Override public int getMetric(int instanceId, long timeBucket) { - String id = timeBucket + Const.ID_SPLIT + instanceId; - GetResponse getResponse = getClient().prepareGet(CpuMetricTable.TABLE, id).get(); - - if (getResponse.isExists()) { - return ((Number)getResponse.getSource().get(CpuMetricTable.COLUMN_USAGE_PERCENT)).intValue(); - } - return 0; - } - - @Override public JsonArray getMetric(int instanceId, long startTimeBucket, long endTimeBucket) { + @Override public List getCPUTrend(int instanceId, Step step, List durationPoints) { MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet(); + String tableName = TimePyramidTableNameBuilder.build(step, CpuMetricTable.TABLE); - long timeBucket = startTimeBucket; - do { - timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1); - String id = timeBucket + Const.ID_SPLIT + instanceId; - prepareMultiGet.add(CpuMetricTable.TABLE, CpuMetricTable.TABLE_TYPE, id); - } - while (timeBucket <= endTimeBucket); + durationPoints.forEach(durationPoint -> { + String id = durationPoint.getPoint() + Const.ID_SPLIT + instanceId; + prepareMultiGet.add(tableName, CpuMetricTable.TABLE_TYPE, id); + }); - JsonArray metrics = new JsonArray(); + List cpuTrends = new LinkedList<>(); MultiGetResponse multiGetResponse = prepareMultiGet.get(); for (MultiGetItemResponse response : multiGetResponse.getResponses()) { if (response.getResponse().isExists()) { double cpuUsed = ((Number)response.getResponse().getSource().get(CpuMetricTable.COLUMN_USAGE_PERCENT)).doubleValue(); - metrics.add((int)(cpuUsed * 100)); + long times = ((Number)response.getResponse().getSource().get(CpuMetricTable.COLUMN_TIMES)).longValue(); + cpuTrends.add((int)((cpuUsed / times) * 100)); } else { - metrics.add(0); + cpuTrends.add(0); } } - return metrics; + return cpuTrends; } } diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/GCMetricEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/GCMetricEsUIDAO.java new file mode 100644 index 000000000..d983bcd7e --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/GCMetricEsUIDAO.java @@ -0,0 +1,76 @@ +/* + * 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.LinkedList; +import java.util.List; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.storage.dao.ui.IGCMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetricTable; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.storage.utils.DurationPoint; +import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder; +import org.apache.skywalking.apm.network.proto.GCPhrase; +import org.elasticsearch.action.get.MultiGetItemResponse; +import org.elasticsearch.action.get.MultiGetRequestBuilder; +import org.elasticsearch.action.get.MultiGetResponse; + +/** + * @author peng-yongsheng + */ +public class GCMetricEsUIDAO extends EsDAO implements IGCMetricUIDAO { + + public GCMetricEsUIDAO(ElasticSearchClient client) { + super(client); + } + + @Override public List getYoungGCTrend(int instanceId, Step step, List durationPoints) { + return getGCTrend(instanceId, step, durationPoints, GCPhrase.NEW_VALUE); + } + + @Override public List getOldGCTrend(int instanceId, Step step, List durationPoints) { + return getGCTrend(instanceId, step, durationPoints, GCPhrase.OLD_VALUE); + } + + private List getGCTrend(int instanceId, Step step, List durationPoints, int gcPhrase) { + String tableName = TimePyramidTableNameBuilder.build(step, GCMetricTable.TABLE); + + MultiGetRequestBuilder youngPrepareMultiGet = getClient().prepareMultiGet(); + durationPoints.forEach(durationPoint -> { + String id = durationPoint.getPoint() + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + gcPhrase; + youngPrepareMultiGet.add(tableName, GCMetricTable.TABLE_TYPE, id); + }); + + List gcTrends = new LinkedList<>(); + MultiGetResponse multiGetResponse = youngPrepareMultiGet.get(); + for (MultiGetItemResponse itemResponse : multiGetResponse.getResponses()) { + if (itemResponse.getResponse().isExists()) { + long count = ((Number)itemResponse.getResponse().getSource().get(GCMetricTable.COLUMN_COUNT)).longValue(); + long times = ((Number)itemResponse.getResponse().getSource().get(GCMetricTable.COLUMN_TIMES)).intValue(); + gcTrends.add((int)(count / times)); + } else { + gcTrends.add(0); + } + } + + return gcTrends; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/GlobalTraceEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/GlobalTraceEsUIDAO.java similarity index 96% rename from apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/GlobalTraceEsUIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/GlobalTraceEsUIDAO.java index fdf2cc661..f5a8bb2a9 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/GlobalTraceEsUIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/GlobalTraceEsUIDAO.java @@ -16,12 +16,12 @@ * */ -package org.apache.skywalking.apm.collector.storage.es.dao; +package org.apache.skywalking.apm.collector.storage.es.dao.ui; import java.util.ArrayList; import java.util.List; import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; -import org.apache.skywalking.apm.collector.storage.dao.IGlobalTraceUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IGlobalTraceUIDAO; import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; import org.apache.skywalking.apm.collector.storage.table.global.GlobalTraceTable; import org.elasticsearch.action.search.SearchRequestBuilder; diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/InstanceEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/InstanceEsUIDAO.java similarity index 69% rename from apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/InstanceEsUIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/InstanceEsUIDAO.java index 358650a76..e60da8b00 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/InstanceEsUIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/InstanceEsUIDAO.java @@ -16,18 +16,20 @@ * */ -package org.apache.skywalking.apm.collector.storage.es.dao; +package org.apache.skywalking.apm.collector.storage.es.dao.ui; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; import java.util.LinkedList; 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.core.util.TimeBucketUtils; -import org.apache.skywalking.apm.collector.storage.dao.IInstanceUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceUIDAO; import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; import org.apache.skywalking.apm.collector.storage.table.register.Instance; import org.apache.skywalking.apm.collector.storage.table.register.InstanceTable; +import org.apache.skywalking.apm.collector.storage.ui.application.Application; +import org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo; import org.elasticsearch.action.get.GetRequestBuilder; import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.search.SearchRequestBuilder; @@ -95,12 +97,20 @@ public class InstanceEsUIDAO extends EsDAO implements IInstanceUIDAO { return heartBeatTime; } - @Override public JsonArray getApplications(long startTime, long endTime) { + @Override public List getApplications(long startTime, long endTime, int... applicationIds) { logger.debug("application list get, start time: {}, end time: {}", startTime, endTime); SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(InstanceTable.TABLE); searchRequestBuilder.setTypes(InstanceTable.TABLE_TYPE); searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); - searchRequestBuilder.setQuery(QueryBuilders.rangeQuery(InstanceTable.COLUMN_HEARTBEAT_TIME).gte(startTime)); + + BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); + boolQueryBuilder.must().add(QueryBuilders.rangeQuery(InstanceTable.COLUMN_HEARTBEAT_TIME).gte(startTime)); + boolQueryBuilder.must().add(QueryBuilders.termQuery(InstanceTable.COLUMN_IS_ADDRESS, BooleanUtils.FALSE)); + if (applicationIds.length > 0) { + boolQueryBuilder.must().add(QueryBuilders.termsQuery(InstanceTable.COLUMN_APPLICATION_ID, applicationIds)); + } + + searchRequestBuilder.setQuery(boolQueryBuilder); searchRequestBuilder.setSize(0); searchRequestBuilder.addAggregation(AggregationBuilders.terms(InstanceTable.COLUMN_APPLICATION_ID).field(InstanceTable.COLUMN_APPLICATION_ID).size(100) .subAggregation(AggregationBuilders.count(InstanceTable.COLUMN_INSTANCE_ID).field(InstanceTable.COLUMN_INSTANCE_ID))); @@ -108,16 +118,16 @@ public class InstanceEsUIDAO extends EsDAO implements IInstanceUIDAO { SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); Terms genders = searchResponse.getAggregations().get(InstanceTable.COLUMN_APPLICATION_ID); - JsonArray applications = new JsonArray(); + List applications = new LinkedList<>(); for (Terms.Bucket applicationsBucket : genders.getBuckets()) { Integer applicationId = applicationsBucket.getKeyAsNumber().intValue(); logger.debug("applicationId: {}", applicationId); ValueCount instanceCount = applicationsBucket.getAggregations().get(InstanceTable.COLUMN_INSTANCE_ID); - JsonObject application = new JsonObject(); - application.addProperty("applicationId", applicationId); - application.addProperty("instanceCount", instanceCount.getValue()); + Application application = new Application(); + application.setId(applicationId); + application.setNumOfServer((int)instanceCount.getValue()); applications.add(application); } return applications; @@ -140,30 +150,54 @@ public class InstanceEsUIDAO extends EsDAO implements IInstanceUIDAO { return null; } - @Override public List getInstances(int applicationId, long timeBucket) { - logger.debug("get instances info, application id: {}, timeBucket: {}", applicationId, timeBucket); + @Override public List searchServer(String keyword, long start, long end) { + logger.debug("get instances info, keyword: {}, start: {}, end: {}", keyword, start, end); SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(InstanceTable.TABLE); searchRequestBuilder.setTypes(InstanceTable.TABLE_TYPE); searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); searchRequestBuilder.setSize(1000); BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); - boolQuery.must().add(QueryBuilders.rangeQuery(InstanceTable.COLUMN_HEARTBEAT_TIME).gte(timeBucket)); - boolQuery.must().add(QueryBuilders.termQuery(InstanceTable.COLUMN_APPLICATION_ID, applicationId)); + boolQuery.must().add(QueryBuilders.rangeQuery(InstanceTable.COLUMN_HEARTBEAT_TIME).gte(start).lte(end)); + if (StringUtils.isNotEmpty(keyword)) { + boolQuery.must().add(QueryBuilders.queryStringQuery(keyword)); + } + boolQuery.must().add(QueryBuilders.termQuery(InstanceTable.COLUMN_IS_ADDRESS, BooleanUtils.FALSE)); searchRequestBuilder.setQuery(boolQuery); SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); SearchHit[] searchHits = searchResponse.getHits().getHits(); - List instanceList = new LinkedList<>(); + return buildAppServerInfo(searchHits); + } + + @Override public List getAllServer(int applicationId, long start, long end) { + logger.debug("get instances info, applicationId: {}, start: {}, end: {}", applicationId, start, end); + SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(InstanceTable.TABLE); + searchRequestBuilder.setTypes(InstanceTable.TABLE_TYPE); + searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); + searchRequestBuilder.setSize(1000); + + BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); + boolQuery.must().add(QueryBuilders.rangeQuery(InstanceTable.COLUMN_HEARTBEAT_TIME).gte(start).lte(end)); + boolQuery.must().add(QueryBuilders.termQuery(InstanceTable.COLUMN_APPLICATION_ID, applicationId)); + boolQuery.must().add(QueryBuilders.termQuery(InstanceTable.COLUMN_IS_ADDRESS, BooleanUtils.FALSE)); + searchRequestBuilder.setQuery(boolQuery); + + SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); + SearchHit[] searchHits = searchResponse.getHits().getHits(); + + return buildAppServerInfo(searchHits); + } + + private List buildAppServerInfo(SearchHit[] searchHits) { + List appServerInfos = new LinkedList<>(); for (SearchHit searchHit : searchHits) { - Instance instance = new Instance(); - instance.setId(searchHit.getId()); - instance.setApplicationId(((Number)searchHit.getSource().get(InstanceTable.COLUMN_APPLICATION_ID)).intValue()); - instance.setHeartBeatTime(((Number)searchHit.getSource().get(InstanceTable.COLUMN_HEARTBEAT_TIME)).longValue()); - instance.setInstanceId(((Number)searchHit.getSource().get(InstanceTable.COLUMN_INSTANCE_ID)).intValue()); - instanceList.add(instance); + AppServerInfo appServerInfo = new AppServerInfo(); + appServerInfo.setId(((Number)searchHit.getSource().get(InstanceTable.COLUMN_INSTANCE_ID)).intValue()); + appServerInfo.setOsInfo((String)searchHit.getSource().get(InstanceTable.COLUMN_OS_INFO)); + appServerInfos.add(appServerInfo); } - return instanceList; + return appServerInfos; } } diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/InstanceMetricEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/InstanceMetricEsUIDAO.java new file mode 100644 index 000000000..fc32f5b24 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/InstanceMetricEsUIDAO.java @@ -0,0 +1,159 @@ +/* + * 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.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.MetricSource; +import org.apache.skywalking.apm.collector.storage.table.instance.InstanceMetricTable; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo; +import org.apache.skywalking.apm.collector.storage.utils.DurationPoint; +import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder; +import org.elasticsearch.action.get.MultiGetItemResponse; +import org.elasticsearch.action.get.MultiGetRequestBuilder; +import org.elasticsearch.action.get.MultiGetResponse; +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.QueryBuilders; +import org.elasticsearch.script.Script; +import org.elasticsearch.search.aggregations.AggregationBuilders; +import org.elasticsearch.search.aggregations.bucket.terms.Terms; +import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder; +import org.elasticsearch.search.aggregations.pipeline.InternalSimpleValue; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilders; + +/** + * @author peng-yongsheng + */ +public class InstanceMetricEsUIDAO extends EsDAO implements IInstanceMetricUIDAO { + + private static final String AVG_TPS = "avg_tps"; + + public InstanceMetricEsUIDAO(ElasticSearchClient client) { + super(client); + } + + @Override public List getTopNServerThroughput(int applicationId, Step step, long start, long end, + long secondBetween, int topN, MetricSource metricSource) { + String tableName = TimePyramidTableNameBuilder.build(step, InstanceMetricTable.TABLE); + + SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName); + searchRequestBuilder.setTypes(InstanceMetricTable.TABLE_TYPE); + searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); + + BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); + boolQuery.must().add(QueryBuilders.rangeQuery(InstanceMetricTable.COLUMN_TIME_BUCKET).gte(start).lte(end)); + if (applicationId != 0) { + boolQuery.must().add(QueryBuilders.termQuery(InstanceMetricTable.COLUMN_APPLICATION_ID, applicationId)); + } + boolQuery.must().add(QueryBuilders.termQuery(InstanceMetricTable.COLUMN_SOURCE_VALUE, metricSource.getValue())); + + searchRequestBuilder.setQuery(boolQuery); + searchRequestBuilder.setSize(0); + + TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(InstanceMetricTable.COLUMN_INSTANCE_ID).field(InstanceMetricTable.COLUMN_INSTANCE_ID).size(topN); + aggregationBuilder.subAggregation(AggregationBuilders.sum(InstanceMetricTable.COLUMN_TRANSACTION_CALLS).field(InstanceMetricTable.COLUMN_TRANSACTION_CALLS)); + aggregationBuilder.subAggregation(AggregationBuilders.sum(InstanceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS).field(InstanceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS)); + + Map bucketsPathsMap = new HashMap<>(); + bucketsPathsMap.put(InstanceMetricTable.COLUMN_TRANSACTION_CALLS, InstanceMetricTable.COLUMN_TRANSACTION_CALLS); + bucketsPathsMap.put(InstanceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS, InstanceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS); + + String idOrCode = "(params." + InstanceMetricTable.COLUMN_TRANSACTION_CALLS + " - params." + InstanceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS + ")" + + " / " + + "( " + secondBetween + " )"; + Script script = new Script(idOrCode); + aggregationBuilder.subAggregation(PipelineAggregatorBuilders.bucketScript(AVG_TPS, bucketsPathsMap, script)); + + searchRequestBuilder.addAggregation(aggregationBuilder); + SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); + + List appServerInfos = new LinkedList<>(); + Terms serviceIdTerms = searchResponse.getAggregations().get(InstanceMetricTable.COLUMN_INSTANCE_ID); + serviceIdTerms.getBuckets().forEach(serviceIdTerm -> { + int instanceId = serviceIdTerm.getKeyAsNumber().intValue(); + + AppServerInfo appServerInfo = new AppServerInfo(); + InternalSimpleValue simpleValue = serviceIdTerm.getAggregations().get(AVG_TPS); + + appServerInfo.setId(instanceId); + appServerInfo.setTps((int)simpleValue.getValue()); + appServerInfos.add(appServerInfo); + }); + return appServerInfos; + } + + @Override public List getServerTPSTrend(int instanceId, Step step, List durationPoints) { + MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet(); + String tableName = TimePyramidTableNameBuilder.build(step, InstanceMetricTable.TABLE); + + durationPoints.forEach(durationPoint -> { + String id = durationPoint.getPoint() + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + MetricSource.Callee.getValue(); + prepareMultiGet.add(tableName, InstanceMetricTable.TABLE_TYPE, id); + }); + + List throughputTrend = new LinkedList<>(); + MultiGetResponse multiGetResponse = prepareMultiGet.get(); + + for (int i = 0; i < multiGetResponse.getResponses().length; i++) { + MultiGetItemResponse response = multiGetResponse.getResponses()[i]; + if (response.getResponse().isExists()) { + long callTimes = ((Number)response.getResponse().getSource().get(InstanceMetricTable.COLUMN_TRANSACTION_CALLS)).longValue(); + throughputTrend.add((int)(callTimes / durationPoints.get(i).getSecondsBetween())); + } else { + throughputTrend.add(0); + } + } + return throughputTrend; + } + + @Override public List getResponseTimeTrend(int instanceId, Step step, List durationPoints) { + MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet(); + String tableName = TimePyramidTableNameBuilder.build(step, InstanceMetricTable.TABLE); + + durationPoints.forEach(durationPoint -> { + String id = durationPoint.getPoint() + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + MetricSource.Callee.getValue(); + prepareMultiGet.add(tableName, InstanceMetricTable.TABLE_TYPE, id); + }); + + List responseTimeTrends = new LinkedList<>(); + MultiGetResponse multiGetResponse = prepareMultiGet.get(); + for (MultiGetItemResponse response : multiGetResponse.getResponses()) { + if (response.getResponse().isExists()) { + long callTimes = ((Number)response.getResponse().getSource().get(InstanceMetricTable.COLUMN_TRANSACTION_CALLS)).longValue(); + long errorCallTimes = ((Number)response.getResponse().getSource().get(InstanceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS)).longValue(); + long durationSum = ((Number)response.getResponse().getSource().get(InstanceMetricTable.COLUMN_TRANSACTION_DURATION_SUM)).longValue(); + long errorDurationSum = ((Number)response.getResponse().getSource().get(InstanceMetricTable.COLUMN_BUSINESS_TRANSACTION_ERROR_DURATION_SUM)).longValue(); + responseTimeTrends.add((int)((durationSum - errorDurationSum) / (callTimes - errorCallTimes))); + } else { + responseTimeTrends.add(0); + } + } + return responseTimeTrends; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/MemoryMetricEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/MemoryMetricEsUIDAO.java new file mode 100644 index 000000000..66f2290d4 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/MemoryMetricEsUIDAO.java @@ -0,0 +1,79 @@ +/* + * 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.Const; +import org.apache.skywalking.apm.collector.storage.dao.ui.IMemoryMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.jvm.MemoryMetricTable; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.storage.utils.DurationPoint; +import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder; +import org.elasticsearch.action.get.MultiGetItemResponse; +import org.elasticsearch.action.get.MultiGetRequestBuilder; +import org.elasticsearch.action.get.MultiGetResponse; + +/** + * @author peng-yongsheng + */ +public class MemoryMetricEsUIDAO extends EsDAO implements IMemoryMetricUIDAO { + + public MemoryMetricEsUIDAO(ElasticSearchClient client) { + super(client); + } + + @Override public Trend getHeapMemoryTrend(int instanceId, Step step, List durationPoints) { + return getMemoryTrend(instanceId, step, durationPoints, true); + } + + @Override public Trend getNoHeapMemoryTrend(int instanceId, Step step, List durationPoints) { + return getMemoryTrend(instanceId, step, durationPoints, false); + } + + private Trend getMemoryTrend(int instanceId, Step step, List durationPoints, + boolean isHeap) { + String tableName = TimePyramidTableNameBuilder.build(step, MemoryMetricTable.TABLE); + MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet(); + + durationPoints.forEach(durationPoint -> { + String id = durationPoint.getPoint() + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + BooleanUtils.booleanToValue(isHeap); + prepareMultiGet.add(tableName, MemoryMetricTable.TABLE_TYPE, id); + }); + + Trend trend = new Trend(); + MultiGetResponse multiGetResponse = prepareMultiGet.get(); + for (MultiGetItemResponse response : multiGetResponse.getResponses()) { + if (response.getResponse().isExists()) { + long max = ((Number)response.getResponse().getSource().get(MemoryMetricTable.COLUMN_MAX)).longValue(); + long used = ((Number)response.getResponse().getSource().get(MemoryMetricTable.COLUMN_USED)).longValue(); + long times = ((Number)response.getResponse().getSource().get(MemoryMetricTable.COLUMN_TIMES)).longValue(); + trend.getMetrics().add((int)(used / times)); + trend.getMaxMetrics().add((int)(max / times)); + } else { + trend.getMetrics().add(0); + trend.getMaxMetrics().add(0); + } + } + + return trend; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/MemoryPoolMetricEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/MemoryPoolMetricEsUIDAO.java similarity index 91% rename from apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/MemoryPoolMetricEsUIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/MemoryPoolMetricEsUIDAO.java index dc5b4b333..2201b436f 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/MemoryPoolMetricEsUIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/MemoryPoolMetricEsUIDAO.java @@ -16,14 +16,13 @@ * */ -package org.apache.skywalking.apm.collector.storage.es.dao; +package org.apache.skywalking.apm.collector.storage.es.dao.ui; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; import org.apache.skywalking.apm.collector.core.util.Const; -import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.apache.skywalking.apm.collector.storage.dao.IMemoryPoolMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IMemoryPoolMetricUIDAO; import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; import org.apache.skywalking.apm.collector.storage.table.jvm.MemoryPoolMetricTable; import org.elasticsearch.action.get.GetResponse; @@ -62,7 +61,7 @@ public class MemoryPoolMetricEsUIDAO extends EsDAO implements IMemoryPoolMetricU long timeBucket = startTimeBucket; do { - timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1); +// timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND, timeBucket, 1); String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + poolType; prepareMultiGet.add(MemoryPoolMetricTable.TABLE, MemoryPoolMetricTable.TABLE_TYPE, id); } diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/NetworkAddressEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/NetworkAddressEsUIDAO.java new file mode 100644 index 000000000..fa93aca55 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/NetworkAddressEsUIDAO.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.dao.ui; + +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.storage.dao.ui.INetworkAddressUIDAO; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.register.NetworkAddressTable; +import org.elasticsearch.action.search.SearchRequestBuilder; +import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.action.search.SearchType; +import org.elasticsearch.index.query.QueryBuilders; + +/** + * @author peng-yongsheng + */ +public class NetworkAddressEsUIDAO extends EsDAO implements INetworkAddressUIDAO { + + public NetworkAddressEsUIDAO(ElasticSearchClient client) { + super(client); + } + + @Override public int getNumOfSpanLayer(int spanLayer) { + SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(NetworkAddressTable.TABLE); + searchRequestBuilder.setTypes(NetworkAddressTable.TABLE_TYPE); + searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); + searchRequestBuilder.setQuery(QueryBuilders.termQuery(NetworkAddressTable.COLUMN_SPAN_LAYER, spanLayer)); + searchRequestBuilder.setSize(0); + + SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); + return (int)searchResponse.getHits().getTotalHits(); + } +} 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/dao/SegmentEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/SegmentEsUIDAO.java similarity index 94% rename from apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/SegmentEsUIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/SegmentEsUIDAO.java index 22c20683f..1158ff759 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/SegmentEsUIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/SegmentEsUIDAO.java @@ -16,14 +16,14 @@ * */ -package org.apache.skywalking.apm.collector.storage.es.dao; +package org.apache.skywalking.apm.collector.storage.es.dao.ui; import com.google.protobuf.InvalidProtocolBufferException; import java.util.Base64; import java.util.Map; import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; import org.apache.skywalking.apm.collector.core.util.StringUtils; -import org.apache.skywalking.apm.collector.storage.dao.ISegmentUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.ISegmentUIDAO; import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; import org.apache.skywalking.apm.collector.storage.table.segment.SegmentTable; import org.apache.skywalking.apm.network.proto.TraceSegmentObject; diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/ServiceMetricEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/ServiceMetricEsUIDAO.java new file mode 100644 index 000000000..e8f6fd81d --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/ServiceMetricEsUIDAO.java @@ -0,0 +1,208 @@ +/* + * 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.Collection; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.MetricSource; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceMetricTable; +import org.apache.skywalking.apm.collector.storage.ui.common.Node; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric; +import org.apache.skywalking.apm.collector.storage.ui.service.ServiceNode; +import org.apache.skywalking.apm.collector.storage.utils.DurationPoint; +import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder; +import org.elasticsearch.action.get.MultiGetItemResponse; +import org.elasticsearch.action.get.MultiGetRequestBuilder; +import org.elasticsearch.action.get.MultiGetResponse; +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.QueryBuilders; +import org.elasticsearch.script.Script; +import org.elasticsearch.search.aggregations.AggregationBuilders; +import org.elasticsearch.search.aggregations.bucket.terms.Terms; +import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder; +import org.elasticsearch.search.aggregations.metrics.sum.Sum; +import org.elasticsearch.search.aggregations.pipeline.InternalSimpleValue; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilders; + +/** + * @author peng-yongsheng + */ +public class ServiceMetricEsUIDAO extends EsDAO implements IServiceMetricUIDAO { + + private static final String AVG_DURATION = "avg_duration"; + + public ServiceMetricEsUIDAO(ElasticSearchClient client) { + super(client); + } + + @Override + public List getServiceResponseTimeTrend(int serviceId, Step step, List durationPoints) { + MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet(); + String tableName = TimePyramidTableNameBuilder.build(step, ServiceMetricTable.TABLE); + + durationPoints.forEach(durationPoint -> { + String id = durationPoint.getPoint() + Const.ID_SPLIT + serviceId + Const.ID_SPLIT + MetricSource.Callee.getValue(); + prepareMultiGet.add(tableName, ServiceMetricTable.TABLE_TYPE, id); + }); + + List trends = new LinkedList<>(); + MultiGetResponse multiGetResponse = prepareMultiGet.get(); + for (MultiGetItemResponse response : multiGetResponse.getResponses()) { + if (response.getResponse().isExists()) { + long calls = ((Number)response.getResponse().getSource().get(ServiceMetricTable.COLUMN_TRANSACTION_CALLS)).longValue(); + long errorCalls = ((Number)response.getResponse().getSource().get(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS)).longValue(); + long durationSum = ((Number)response.getResponse().getSource().get(ServiceMetricTable.COLUMN_TRANSACTION_DURATION_SUM)).longValue(); + long errorDurationSum = ((Number)response.getResponse().getSource().get(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM)).longValue(); + trends.add((int)((durationSum - errorDurationSum) / (calls - errorCalls))); + } else { + trends.add(0); + } + } + return trends; + } + + @Override public List getServiceSLATrend(int serviceId, Step step, List durationPoints) { + MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet(); + String tableName = TimePyramidTableNameBuilder.build(step, ServiceMetricTable.TABLE); + + durationPoints.forEach(durationPoint -> { + String id = durationPoint.getPoint() + Const.ID_SPLIT + serviceId + Const.ID_SPLIT + MetricSource.Callee.getValue(); + prepareMultiGet.add(tableName, ServiceMetricTable.TABLE_TYPE, id); + }); + + List trends = new LinkedList<>(); + MultiGetResponse multiGetResponse = prepareMultiGet.get(); + for (MultiGetItemResponse response : multiGetResponse.getResponses()) { + if (response.getResponse().isExists()) { + long calls = ((Number)response.getResponse().getSource().get(ServiceMetricTable.COLUMN_TRANSACTION_CALLS)).longValue(); + long errorCalls = ((Number)response.getResponse().getSource().get(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS)).longValue(); + trends.add((int)(((calls - errorCalls) / calls)) * 10000); + } else { + trends.add(10000); + } + } + return trends; + } + + @Override + public List getServicesMetric(Step step, long startTime, long endTime, MetricSource metricSource, + Collection serviceIds) { + String tableName = TimePyramidTableNameBuilder.build(step, ServiceMetricTable.TABLE); + + SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName); + searchRequestBuilder.setTypes(ServiceMetricTable.TABLE_TYPE); + searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); + + BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); + boolQuery.must().add(QueryBuilders.rangeQuery(ServiceMetricTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime)); + boolQuery.must().add(QueryBuilders.termsQuery(ServiceMetricTable.COLUMN_SERVICE_ID, serviceIds)); + boolQuery.must().add(QueryBuilders.termQuery(ServiceMetricTable.COLUMN_SOURCE_VALUE, metricSource.getValue())); + + searchRequestBuilder.setQuery(boolQuery); + searchRequestBuilder.setSize(0); + + TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(ServiceMetricTable.COLUMN_SERVICE_ID).field(ServiceMetricTable.COLUMN_SERVICE_ID).size(100); + aggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceMetricTable.COLUMN_TRANSACTION_CALLS).field(ServiceMetricTable.COLUMN_TRANSACTION_CALLS)); + aggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS).field(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS)); + + searchRequestBuilder.addAggregation(aggregationBuilder); + SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); + + List nodes = new LinkedList<>(); + Terms serviceIdTerms = searchResponse.getAggregations().get(ServiceMetricTable.COLUMN_SERVICE_ID); + serviceIdTerms.getBuckets().forEach(serviceIdBucket -> { + int serviceId = serviceIdBucket.getKeyAsNumber().intValue(); + + Sum callsSum = serviceIdBucket.getAggregations().get(ServiceMetricTable.COLUMN_TRANSACTION_CALLS); + Sum errorCallsSum = serviceIdBucket.getAggregations().get(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS); + + ServiceNode serviceNode = new ServiceNode(); + serviceNode.setId(serviceId); + serviceNode.setCalls((long)callsSum.getValue()); + serviceNode.setSla((int)(((callsSum.getValue() - errorCallsSum.getValue()) / callsSum.getValue()) * 10000)); + nodes.add(serviceNode); + }); + return nodes; + } + + @Override public List getSlowService(int applicationId, Step step, long start, long end, Integer top, + MetricSource metricSource) { + String tableName = TimePyramidTableNameBuilder.build(step, ServiceMetricTable.TABLE); + + SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName); + searchRequestBuilder.setTypes(ServiceMetricTable.TABLE_TYPE); + searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); + + BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); + boolQuery.must().add(QueryBuilders.rangeQuery(ServiceMetricTable.COLUMN_TIME_BUCKET).gte(start).lte(end)); + if (applicationId != 0) { + boolQuery.must().add(QueryBuilders.termQuery(ServiceMetricTable.COLUMN_APPLICATION_ID, applicationId)); + } + boolQuery.must().add(QueryBuilders.termQuery(ServiceMetricTable.COLUMN_SOURCE_VALUE, metricSource.getValue())); + + searchRequestBuilder.setQuery(boolQuery); + searchRequestBuilder.setSize(0); + + TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(ServiceMetricTable.COLUMN_SERVICE_ID).field(ServiceMetricTable.COLUMN_SERVICE_ID).size(top); + aggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceMetricTable.COLUMN_TRANSACTION_CALLS).field(ServiceMetricTable.COLUMN_TRANSACTION_CALLS)); + aggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS).field(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS)); + aggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceMetricTable.COLUMN_TRANSACTION_DURATION_SUM).field(ServiceMetricTable.COLUMN_TRANSACTION_DURATION_SUM)); + aggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM).field(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM)); + + Map bucketsPathsMap = new HashMap<>(); + bucketsPathsMap.put(ServiceMetricTable.COLUMN_TRANSACTION_CALLS, ServiceMetricTable.COLUMN_TRANSACTION_CALLS); + bucketsPathsMap.put(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS, ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS); + bucketsPathsMap.put(ServiceMetricTable.COLUMN_TRANSACTION_DURATION_SUM, ServiceMetricTable.COLUMN_TRANSACTION_DURATION_SUM); + bucketsPathsMap.put(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM, ServiceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM); + + String idOrCode = "(params." + ServiceMetricTable.COLUMN_TRANSACTION_DURATION_SUM + " - params." + ServiceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM + ")" + + " / " + + "(params." + ServiceMetricTable.COLUMN_TRANSACTION_CALLS + " - params." + ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS + ")"; + Script script = new Script(idOrCode); + aggregationBuilder.subAggregation(PipelineAggregatorBuilders.bucketScript(AVG_DURATION, bucketsPathsMap, script)); + + searchRequestBuilder.addAggregation(aggregationBuilder); + SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); + + List serviceMetrics = new LinkedList<>(); + Terms serviceIdTerms = searchResponse.getAggregations().get(ServiceMetricTable.COLUMN_SERVICE_ID); + serviceIdTerms.getBuckets().forEach(serviceIdTerm -> { + int serviceId = serviceIdTerm.getKeyAsNumber().intValue(); + + ServiceMetric serviceMetric = new ServiceMetric(); + InternalSimpleValue simpleValue = serviceIdTerm.getAggregations().get(AVG_DURATION); + + serviceMetric.setId(serviceId); + serviceMetric.setAvgResponseTime((int)simpleValue.getValue()); + serviceMetrics.add(serviceMetric); + }); + return serviceMetrics; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/ServiceNameServiceEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/ServiceNameServiceEsUIDAO.java new file mode 100644 index 000000000..f050e0a16 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/ServiceNameServiceEsUIDAO.java @@ -0,0 +1,73 @@ +/* + * 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.LinkedList; +import java.util.List; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceNameServiceUIDAO; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.register.ServiceNameTable; +import org.apache.skywalking.apm.collector.storage.ui.service.ServiceInfo; +import org.elasticsearch.action.search.SearchRequestBuilder; +import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.action.search.SearchType; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.search.SearchHit; + +/** + * @author peng-yongsheng + */ +public class ServiceNameServiceEsUIDAO extends EsDAO implements IServiceNameServiceUIDAO { + + public ServiceNameServiceEsUIDAO(ElasticSearchClient client) { + super(client); + } + + @Override public int getCount() { + SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(ServiceNameTable.TABLE); + searchRequestBuilder.setTypes(ServiceNameTable.TABLE_TYPE); + searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); + searchRequestBuilder.setSize(0); + + SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); + return (int)searchResponse.getHits().getTotalHits(); + } + + @Override public List searchService(String keyword, int topN) { + SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(ServiceNameTable.TABLE); + searchRequestBuilder.setTypes(ServiceNameTable.TABLE_TYPE); + searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); + searchRequestBuilder.setSize(topN); + + searchRequestBuilder.setQuery(QueryBuilders.matchQuery(ServiceNameTable.COLUMN_SERVICE_NAME, keyword)); + + SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); + SearchHit[] searchHits = searchResponse.getHits().getHits(); + + List serviceInfos = new LinkedList<>(); + for (SearchHit searchHit : searchHits) { + ServiceInfo serviceInfo = new ServiceInfo(); + serviceInfo.setId(((Number)searchHit.getSource().get(ServiceNameTable.COLUMN_SERVICE_ID)).intValue()); + serviceInfo.setName((String)searchHit.getSource().get(ServiceNameTable.COLUMN_SERVICE_NAME)); + serviceInfos.add(serviceInfo); + } + return serviceInfos; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/ServiceReferenceEsMetricUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/ServiceReferenceEsMetricUIDAO.java new file mode 100644 index 000000000..879952282 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/ServiceReferenceEsMetricUIDAO.java @@ -0,0 +1,200 @@ +/* + * 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.LinkedList; +import java.util.List; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceReferenceMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.MetricSource; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceReferenceMetricTable; +import org.apache.skywalking.apm.collector.storage.ui.common.Call; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder; +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.QueryBuilders; +import org.elasticsearch.search.aggregations.AggregationBuilders; +import org.elasticsearch.search.aggregations.bucket.terms.Terms; +import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder; +import org.elasticsearch.search.aggregations.metrics.sum.Sum; + +/** + * @author peng-yongsheng + */ +public class ServiceReferenceEsMetricUIDAO extends EsDAO implements IServiceReferenceMetricUIDAO { + + public ServiceReferenceEsMetricUIDAO(ElasticSearchClient client) { + super(client); + } + + @Override public List getFrontServices(Step step, long startTime, long endTime, MetricSource metricSource, + int behindServiceId) { + String tableName = TimePyramidTableNameBuilder.build(step, ServiceReferenceMetricTable.TABLE); + + SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName); + searchRequestBuilder.setTypes(ServiceReferenceMetricTable.TABLE_TYPE); + searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); + + BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); + boolQuery.must().add(QueryBuilders.rangeQuery(ServiceReferenceMetricTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime)); + boolQuery.must().add(QueryBuilders.termQuery(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID, behindServiceId)); + boolQuery.must().add(QueryBuilders.termQuery(ServiceReferenceMetricTable.COLUMN_SOURCE_VALUE, metricSource.getValue())); + + searchRequestBuilder.setQuery(boolQuery); + searchRequestBuilder.setSize(0); + + TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID).field(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID).size(100); + aggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS).field(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS)); + aggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM).field(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM)); + + searchRequestBuilder.addAggregation(aggregationBuilder); + SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); + + List calls = new LinkedList<>(); + Terms frontServiceIdTerms = searchResponse.getAggregations().get(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID); + buildNodeByBehindServiceId(calls, frontServiceIdTerms, behindServiceId); + + return calls; + } + + @Override public List getBehindServices(Step step, long startTime, long endTime, MetricSource metricSource, + int frontServiceId) { + String tableName = TimePyramidTableNameBuilder.build(step, ServiceReferenceMetricTable.TABLE); + + SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName); + searchRequestBuilder.setTypes(ServiceReferenceMetricTable.TABLE_TYPE); + searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); + + BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); + boolQuery.must().add(QueryBuilders.rangeQuery(ServiceReferenceMetricTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime)); + boolQuery.must().add(QueryBuilders.termQuery(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID, frontServiceId)); + boolQuery.must().add(QueryBuilders.termQuery(ServiceReferenceMetricTable.COLUMN_SOURCE_VALUE, metricSource.getValue())); + + searchRequestBuilder.setQuery(boolQuery); + searchRequestBuilder.setSize(0); + + TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID).field(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID).size(100); + aggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS).field(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS)); + aggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM).field(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM)); + + searchRequestBuilder.addAggregation(aggregationBuilder); + SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); + + List calls = new LinkedList<>(); + Terms behindServiceIdTerms = searchResponse.getAggregations().get(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID); + buildNodeByFrontServiceId(calls, behindServiceIdTerms, frontServiceId); + + return calls; + } + + @Override public List getFrontServices(Step step, long startTime, long endTime, MetricSource metricSource, + List behindServiceIds) { + String tableName = TimePyramidTableNameBuilder.build(step, ServiceReferenceMetricTable.TABLE); + + SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName); + searchRequestBuilder.setTypes(ServiceReferenceMetricTable.TABLE_TYPE); + searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); + + BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); + boolQuery.must().add(QueryBuilders.rangeQuery(ServiceReferenceMetricTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime)); + boolQuery.must().add(QueryBuilders.termsQuery(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID, behindServiceIds)); + boolQuery.must().add(QueryBuilders.termQuery(ServiceReferenceMetricTable.COLUMN_SOURCE_VALUE, metricSource.getValue())); + + searchRequestBuilder.setQuery(boolQuery); + searchRequestBuilder.setSize(0); + + return executeAggregation(searchRequestBuilder); + } + + @Override public List getBehindServices(Step step, long startTime, long endTime, MetricSource metricSource, + List frontServiceIds) { + String tableName = TimePyramidTableNameBuilder.build(step, ServiceReferenceMetricTable.TABLE); + + SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName); + searchRequestBuilder.setTypes(ServiceReferenceMetricTable.TABLE_TYPE); + searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); + + BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); + boolQuery.must().add(QueryBuilders.rangeQuery(ServiceReferenceMetricTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime)); + boolQuery.must().add(QueryBuilders.termsQuery(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID, frontServiceIds)); + boolQuery.must().add(QueryBuilders.termQuery(ServiceReferenceMetricTable.COLUMN_SOURCE_VALUE, metricSource.getValue())); + + searchRequestBuilder.setQuery(boolQuery); + searchRequestBuilder.setSize(0); + + return executeAggregation(searchRequestBuilder); + } + + private List executeAggregation(SearchRequestBuilder searchRequestBuilder) { + TermsAggregationBuilder frontAggregationBuilder = AggregationBuilders.terms(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID).field(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID).size(100); + TermsAggregationBuilder behindAggregationBuilder = AggregationBuilders.terms(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID).field(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID).size(100); + behindAggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS).field(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS)); + behindAggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM).field(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM)); + frontAggregationBuilder.subAggregation(behindAggregationBuilder); + + searchRequestBuilder.addAggregation(frontAggregationBuilder); + SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); + + List nodes = new LinkedList<>(); + Terms frontServiceIdTerms = searchResponse.getAggregations().get(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID); + frontServiceIdTerms.getBuckets().forEach(frontServiceIdBucket -> { + int frontServiceId = frontServiceIdBucket.getKeyAsNumber().intValue(); + + Terms behindServiceIdTerms = frontServiceIdBucket.getAggregations().get(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID); + buildNodeByFrontServiceId(nodes, behindServiceIdTerms, frontServiceId); + }); + + return nodes; + } + + private void buildNodeByFrontServiceId(List calls, Terms behindServiceIdTerms, int frontServiceId) { + behindServiceIdTerms.getBuckets().forEach(behindServiceIdBucket -> { + int behindServiceId = behindServiceIdBucket.getKeyAsNumber().intValue(); + + Sum callsSum = behindServiceIdBucket.getAggregations().get(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS); + Sum responseTimes = behindServiceIdBucket.getAggregations().get(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM); + + Call call = new Call(); + call.setSource(frontServiceId); + call.setTarget(behindServiceId); + call.setCalls((int)callsSum.getValue()); + call.setResponseTimes((int)responseTimes.getValue()); + calls.add(call); + }); + } + + private void buildNodeByBehindServiceId(List calls, Terms frontServiceIdTerms, int behindServiceId) { + frontServiceIdTerms.getBuckets().forEach(frontServiceIdBucket -> { + int frontServiceId = frontServiceIdBucket.getKeyAsNumber().intValue(); + Sum callsSum = frontServiceIdBucket.getAggregations().get(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS); + Sum responseTimes = frontServiceIdBucket.getAggregations().get(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM); + + Call call = new Call(); + call.setTarget(behindServiceId); + call.setSource(frontServiceId); + call.setCalls((int)callsSum.getValue()); + call.setResponseTimes((int)responseTimes.getValue()); + calls.add(call); + }); + } +} 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/java/org/apache/skywalking/apm/collector/storage/es/define/appcomp/AbstractApplicationComponentEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/appcomp/AbstractApplicationComponentEsTableDefine.java index 1a7bb53d2..52cb83d5e 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/appcomp/AbstractApplicationComponentEsTableDefine.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/appcomp/AbstractApplicationComponentEsTableDefine.java @@ -34,7 +34,7 @@ public abstract class AbstractApplicationComponentEsTableDefine extends ElasticS @Override public final void initialize() { addColumn(new ElasticSearchColumnDefine(ApplicationComponentTable.COLUMN_METRIC_ID, ElasticSearchColumnDefine.Type.Keyword.name())); addColumn(new ElasticSearchColumnDefine(ApplicationComponentTable.COLUMN_COMPONENT_ID, ElasticSearchColumnDefine.Type.Integer.name())); - addColumn(new ElasticSearchColumnDefine(ApplicationComponentTable.COLUMN_PEER_ID, ElasticSearchColumnDefine.Type.Integer.name())); + addColumn(new ElasticSearchColumnDefine(ApplicationComponentTable.COLUMN_APPLICATION_ID, ElasticSearchColumnDefine.Type.Integer.name())); addColumn(new ElasticSearchColumnDefine(ApplicationComponentTable.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/appmapping/AbstractApplicationMappingEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/appmapping/AbstractApplicationMappingEsTableDefine.java index df044ef49..9eea4f1a7 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/appmapping/AbstractApplicationMappingEsTableDefine.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/appmapping/AbstractApplicationMappingEsTableDefine.java @@ -34,7 +34,7 @@ public abstract class AbstractApplicationMappingEsTableDefine extends ElasticSea @Override public final void initialize() { addColumn(new ElasticSearchColumnDefine(ApplicationMappingTable.COLUMN_METRIC_ID, ElasticSearchColumnDefine.Type.Keyword.name())); addColumn(new ElasticSearchColumnDefine(ApplicationMappingTable.COLUMN_APPLICATION_ID, ElasticSearchColumnDefine.Type.Integer.name())); - addColumn(new ElasticSearchColumnDefine(ApplicationMappingTable.COLUMN_ADDRESS_ID, ElasticSearchColumnDefine.Type.Integer.name())); + addColumn(new ElasticSearchColumnDefine(ApplicationMappingTable.COLUMN_MAPPING_APPLICATION_ID, ElasticSearchColumnDefine.Type.Integer.name())); addColumn(new ElasticSearchColumnDefine(ApplicationMappingTable.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/register/ApplicationEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/register/ApplicationEsTableDefine.java index 7b9beef54..7d84a7869 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/register/ApplicationEsTableDefine.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/register/ApplicationEsTableDefine.java @@ -38,6 +38,7 @@ public class ApplicationEsTableDefine extends ElasticSearchTableDefine { @Override public void initialize() { addColumn(new ElasticSearchColumnDefine(ApplicationTable.COLUMN_APPLICATION_CODE, ElasticSearchColumnDefine.Type.Keyword.name())); addColumn(new ElasticSearchColumnDefine(ApplicationTable.COLUMN_APPLICATION_ID, ElasticSearchColumnDefine.Type.Integer.name())); + addColumn(new ElasticSearchColumnDefine(ApplicationTable.COLUMN_LAYER, ElasticSearchColumnDefine.Type.Integer.name())); addColumn(new ElasticSearchColumnDefine(ApplicationTable.COLUMN_ADDRESS_ID, ElasticSearchColumnDefine.Type.Integer.name())); addColumn(new ElasticSearchColumnDefine(ApplicationTable.COLUMN_IS_ADDRESS, ElasticSearchColumnDefine.Type.Integer.name())); } diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/register/ServiceNameEsTableDefine.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/register/ServiceNameEsTableDefine.java index f15707bec..2a5dc39c0 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/register/ServiceNameEsTableDefine.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/define/register/ServiceNameEsTableDefine.java @@ -37,7 +37,7 @@ public class ServiceNameEsTableDefine extends ElasticSearchTableDefine { @Override public void initialize() { addColumn(new ElasticSearchColumnDefine(ServiceNameTable.COLUMN_APPLICATION_ID, ElasticSearchColumnDefine.Type.Integer.name())); - addColumn(new ElasticSearchColumnDefine(ServiceNameTable.COLUMN_SERVICE_NAME, ElasticSearchColumnDefine.Type.Keyword.name())); + addColumn(new ElasticSearchColumnDefine(ServiceNameTable.COLUMN_SERVICE_NAME, ElasticSearchColumnDefine.Type.Text.name())); addColumn(new ElasticSearchColumnDefine(ServiceNameTable.COLUMN_SERVICE_ID, ElasticSearchColumnDefine.Type.Integer.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 c7736d1c2..ba2512525 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 @@ -27,23 +27,10 @@ import org.apache.skywalking.apm.collector.core.module.ServiceNotProvidedExcepti import org.apache.skywalking.apm.collector.storage.StorageException; 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.IApplicationComponentUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.IApplicationMappingUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.ICpuMetricUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.IGCMetricUIDAO; import org.apache.skywalking.apm.collector.storage.dao.IGlobalTracePersistenceDAO; -import org.apache.skywalking.apm.collector.storage.dao.IGlobalTraceUIDAO; import org.apache.skywalking.apm.collector.storage.dao.IInstanceHeartBeatPersistenceDAO; -import org.apache.skywalking.apm.collector.storage.dao.IInstanceMetricUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.IInstanceUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.IMemoryMetricUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.IMemoryPoolMetricUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.ISegmentCostPersistenceDAO; -import org.apache.skywalking.apm.collector.storage.dao.ISegmentCostUIDAO; +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.ISegmentUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.IServiceReferenceUIDAO; import org.apache.skywalking.apm.collector.storage.dao.acp.IApplicationComponentDayPersistenceDAO; import org.apache.skywalking.apm.collector.storage.dao.acp.IApplicationComponentHourPersistenceDAO; import org.apache.skywalking.apm.collector.storage.dao.acp.IApplicationComponentMinutePersistenceDAO; @@ -120,25 +107,28 @@ import org.apache.skywalking.apm.collector.storage.dao.srmp.IServiceReferenceDay import org.apache.skywalking.apm.collector.storage.dao.srmp.IServiceReferenceHourMetricPersistenceDAO; import org.apache.skywalking.apm.collector.storage.dao.srmp.IServiceReferenceMinuteMetricPersistenceDAO; import org.apache.skywalking.apm.collector.storage.dao.srmp.IServiceReferenceMonthMetricPersistenceDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationComponentUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMappingUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationReferenceMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.ICpuMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IGCMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IGlobalTraceUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceMetricUIDAO; +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.ISegmentDurationUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.ISegmentUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceNameServiceUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceReferenceMetricUIDAO; 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.ApplicationComponentH2UIDAO; -import org.apache.skywalking.apm.collector.storage.h2.dao.ApplicationMappingH2UIDAO; -import org.apache.skywalking.apm.collector.storage.h2.dao.ApplicationReferenceMetricH2UIDAO; -import org.apache.skywalking.apm.collector.storage.h2.dao.CpuMetricH2UIDAO; -import org.apache.skywalking.apm.collector.storage.h2.dao.GCMetricH2UIDAO; import org.apache.skywalking.apm.collector.storage.h2.dao.GlobalTraceH2PersistenceDAO; -import org.apache.skywalking.apm.collector.storage.h2.dao.GlobalTraceH2UIDAO; -import org.apache.skywalking.apm.collector.storage.h2.dao.InstanceH2UIDAO; import org.apache.skywalking.apm.collector.storage.h2.dao.InstanceHeartBeatH2PersistenceDAO; -import org.apache.skywalking.apm.collector.storage.h2.dao.InstanceMetricH2UIDAO; -import org.apache.skywalking.apm.collector.storage.h2.dao.MemoryMetricH2UIDAO; -import org.apache.skywalking.apm.collector.storage.h2.dao.MemoryPoolMetricH2UIDAO; -import org.apache.skywalking.apm.collector.storage.h2.dao.SegmentCostH2PersistenceDAO; -import org.apache.skywalking.apm.collector.storage.h2.dao.SegmentCostH2UIDAO; +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.SegmentH2UIDAO; -import org.apache.skywalking.apm.collector.storage.h2.dao.ServiceReferenceH2UIDAO; import org.apache.skywalking.apm.collector.storage.h2.dao.acp.ApplicationComponentDayH2PersistenceDAO; import org.apache.skywalking.apm.collector.storage.h2.dao.acp.ApplicationComponentHourH2PersistenceDAO; import org.apache.skywalking.apm.collector.storage.h2.dao.acp.ApplicationComponentMinuteH2PersistenceDAO; @@ -215,6 +205,22 @@ import org.apache.skywalking.apm.collector.storage.h2.dao.srmp.ServiceReferenceD import org.apache.skywalking.apm.collector.storage.h2.dao.srmp.ServiceReferenceHourMetricH2PersistenceDAO; import org.apache.skywalking.apm.collector.storage.h2.dao.srmp.ServiceReferenceMinuteMetricH2PersistenceDAO; import org.apache.skywalking.apm.collector.storage.h2.dao.srmp.ServiceReferenceMonthMetricH2PersistenceDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.ui.ApplicationComponentH2UIDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.ui.ApplicationMappingH2UIDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.ui.ApplicationReferenceMetricH2UIDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.ui.CpuMetricH2UIDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.ui.GCMetricH2UIDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.ui.GlobalTraceH2UIDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.ui.InstanceH2UIDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.ui.InstanceMetricH2UIDAO; +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.SegmentDurationH2UIDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.ui.SegmentH2UIDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.ui.ServiceMetricH2UIDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.ui.ServiceNameServiceH2UIDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.ui.ServiceReferenceH2MetricUIDAO; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -312,7 +318,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)); @@ -364,6 +370,9 @@ public class StorageModuleH2Provider extends ModuleProvider { private void registerUiDAO() throws ServiceNotProvidedException { this.registerServiceImplementation(IInstanceUIDAO.class, new InstanceH2UIDAO(h2Client)); + this.registerServiceImplementation(INetworkAddressUIDAO.class, new NetworkAddressH2UIDAO(h2Client)); + this.registerServiceImplementation(IServiceNameServiceUIDAO.class, new ServiceNameServiceH2UIDAO(h2Client)); + this.registerServiceImplementation(IServiceMetricUIDAO.class, new ServiceMetricH2UIDAO(h2Client)); this.registerServiceImplementation(ICpuMetricUIDAO.class, new CpuMetricH2UIDAO(h2Client)); this.registerServiceImplementation(IGCMetricUIDAO.class, new GCMetricH2UIDAO(h2Client)); @@ -375,9 +384,9 @@ 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)); + this.registerServiceImplementation(IServiceReferenceMetricUIDAO.class, new ServiceReferenceH2MetricUIDAO(h2Client)); } private void registerAlarmDAO() throws ServiceNotProvidedException { diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/GCMetricH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/GCMetricH2UIDAO.java deleted file mode 100644 index 8cf181341..000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/GCMetricH2UIDAO.java +++ /dev/null @@ -1,161 +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; - -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.Const; -import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.apache.skywalking.apm.collector.storage.dao.IGCMetricUIDAO; -import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetricTable; -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.TimeBucketUtils; -import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.apache.skywalking.apm.network.proto.GCPhrase; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng, clevertension - */ -public class GCMetricH2UIDAO extends H2DAO implements IGCMetricUIDAO { - - private final Logger logger = LoggerFactory.getLogger(GCMetricH2UIDAO.class); - private static final String GET_GC_COUNT_SQL = "select {1}, sum({0}) as cnt, {1} from {2} where {3} = ? and {4} in ("; - private static final String GET_GC_METRIC_SQL = "select * from {0} where {1} = ?"; - - public GCMetricH2UIDAO(H2Client client) { - super(client); - } - - @Override public GCCount getGCCount(long[] timeBuckets, int instanceId) { - GCCount gcCount = new GCCount(); - H2Client client = getClient(); - String sql = GET_GC_COUNT_SQL; - StringBuilder builder = new StringBuilder(); - - for (int i = 0; i < timeBuckets.length; i++) { - builder.append("?,"); - } - builder.delete(builder.length() - 1, builder.length()); - builder.append(")"); - sql = sql + builder + " group by {1}"; - sql = SqlBuilder.buildSql(sql, GCMetricTable.COLUMN_COUNT, GCMetricTable.COLUMN_PHRASE, - GCMetricTable.TABLE, GCMetricTable.COLUMN_INSTANCE_ID, GCMetricTable.COLUMN_ID); - Object[] params = new Object[timeBuckets.length + 1]; - for (int i = 0; i < timeBuckets.length; i++) { - params[i + 1] = timeBuckets[i]; - } - params[0] = instanceId; - try (ResultSet rs = client.executeQuery(sql, params)) { - if (rs.next()) { - int phrase = rs.getInt(GCMetricTable.COLUMN_PHRASE); - int count = rs.getInt("cnt"); - - if (phrase == GCPhrase.NEW_VALUE) { - gcCount.setYoung(count); - } else if (phrase == GCPhrase.OLD_VALUE) { - gcCount.setOld(count); - } - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - return gcCount; - } - - @Override public JsonObject getMetric(int instanceId, long timeBucket) { - JsonObject response = new JsonObject(); - H2Client client = getClient(); - String sql = SqlBuilder.buildSql(GET_GC_METRIC_SQL, GCMetricTable.TABLE, GCMetricTable.COLUMN_ID); - String youngId = timeBucket + Const.ID_SPLIT + GCPhrase.NEW_VALUE + instanceId; - Object[] params = new Object[] {youngId}; - try (ResultSet rs = client.executeQuery(sql, params)) { - if (rs.next()) { - response.addProperty("ygc", rs.getInt(GCMetricTable.COLUMN_COUNT)); - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - String oldId = timeBucket + Const.ID_SPLIT + GCPhrase.OLD_VALUE + instanceId; - Object[] params1 = new Object[] {oldId}; - try (ResultSet rs = client.executeQuery(sql, params1)) { - if (rs.next()) { - response.addProperty("ogc", rs.getInt(GCMetricTable.COLUMN_COUNT)); - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - - return response; - } - - @Override public JsonObject getMetric(int instanceId, long startTimeBucket, long endTimeBucket) { - JsonObject response = new JsonObject(); - H2Client client = getClient(); - String sql = SqlBuilder.buildSql(GET_GC_METRIC_SQL, GCMetricTable.TABLE, GCMetricTable.COLUMN_ID); - long timeBucket = startTimeBucket; - List youngIdsList = new ArrayList<>(); - do { - timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1); - String youngId = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + GCPhrase.NEW_VALUE; - youngIdsList.add(youngId); - } - while (timeBucket <= endTimeBucket); - - JsonArray youngArray = new JsonArray(); - forEachRs(client, youngIdsList, sql, youngArray); - response.add("ygc", youngArray); - - List oldIdsList = new ArrayList<>(); - timeBucket = startTimeBucket; - do { - timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1); - String oldId = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + GCPhrase.OLD_VALUE; - oldIdsList.add(oldId); - } - while (timeBucket <= endTimeBucket); - - JsonArray oldArray = new JsonArray(); - forEachRs(client, oldIdsList, sql, oldArray); - response.add("ogc", oldArray); - - return response; - } - - private void forEachRs(H2Client client, List idsList, String sql, JsonArray metricArray) { - idsList.forEach(id -> { - try (ResultSet rs = client.executeQuery(sql, new String[] {id})) { - if (rs.next()) { - metricArray.add(rs.getInt(GCMetricTable.COLUMN_COUNT)); - } else { - metricArray.add(0); - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - }); - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/InstanceMetricH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/InstanceMetricH2UIDAO.java deleted file mode 100644 index 91c23d276..000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/InstanceMetricH2UIDAO.java +++ /dev/null @@ -1,169 +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; - -import com.google.gson.JsonArray; -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.core.util.Const; -import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.apache.skywalking.apm.collector.client.h2.H2ClientException; -import org.apache.skywalking.apm.collector.storage.dao.IInstanceMetricUIDAO; -import org.apache.skywalking.apm.collector.storage.table.instance.InstanceMetricTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng, clevertension - */ -public class InstanceMetricH2UIDAO extends H2DAO implements IInstanceMetricUIDAO { - - private final Logger logger = LoggerFactory.getLogger(InstanceMetricH2UIDAO.class); - private static final String GET_INSTANCE_METRIC_SQL = "select * from {0} where {1} = ? and {2} in ("; - private static final String GET_TPS_METRIC_SQL = "select * from {0} where {1} = ?"; - - public InstanceMetricH2UIDAO(H2Client client) { - super(client); - } - - @Override public InstanceMetric get(long[] timeBuckets, int instanceId) { - H2Client client = getClient(); - logger.info("the inst performance inst id = {}", instanceId); - String sql = SqlBuilder.buildSql(GET_INSTANCE_METRIC_SQL, InstanceMetricTable.TABLE, InstanceMetricTable.COLUMN_INSTANCE_ID, InstanceMetricTable.COLUMN_TIME_BUCKET); - StringBuilder builder = new StringBuilder(); - for (int i = 0; i < timeBuckets.length; i++) { - builder.append("?,"); - } - builder.delete(builder.length() - 1, builder.length()); - builder.append(")"); - sql = sql + builder; - Object[] params = new Object[timeBuckets.length + 1]; - for (int i = 0; i < timeBuckets.length; i++) { - params[i + 1] = timeBuckets[i]; - } - params[0] = instanceId; - try (ResultSet rs = client.executeQuery(sql, params)) { - if (rs.next()) { - long callTimes = rs.getInt(InstanceMetricTable.COLUMN_TRANSACTION_CALLS); - long costTotal = rs.getInt(InstanceMetricTable.COLUMN_TRANSACTION_DURATION_SUM); - return new InstanceMetric(instanceId, callTimes, costTotal); - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - return null; - } - - @Override public long getTpsMetric(int instanceId, long timeBucket) { - logger.info("getTpMetric instanceId = {}, startTimeBucket = {}", instanceId, timeBucket); - H2Client client = getClient(); - String sql = SqlBuilder.buildSql(GET_TPS_METRIC_SQL, InstanceMetricTable.TABLE, InstanceMetricTable.COLUMN_ID); - Object[] params = new Object[] {instanceId}; - try (ResultSet rs = client.executeQuery(sql, params)) { - if (rs.next()) { - return rs.getLong(InstanceMetricTable.COLUMN_TRANSACTION_CALLS); - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - return 0; - } - - @Override public JsonArray getTpsMetric(int instanceId, long startTimeBucket, long endTimeBucket) { - logger.info("getTpsMetric instanceId = {}, startTimeBucket = {}, endTimeBucket = {}", instanceId, startTimeBucket, endTimeBucket); - H2Client client = getClient(); - String sql = SqlBuilder.buildSql(GET_TPS_METRIC_SQL, InstanceMetricTable.TABLE, InstanceMetricTable.COLUMN_ID); - - long timeBucket = startTimeBucket; - List idList = new ArrayList<>(); - do { - String id = timeBucket + Const.ID_SPLIT + instanceId; - timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1); - idList.add(id); - } - while (timeBucket <= endTimeBucket); - - JsonArray metrics = new JsonArray(); - idList.forEach(id -> { - try (ResultSet rs = client.executeQuery(sql, new Object[] {id})) { - if (rs.next()) { - long calls = rs.getLong(InstanceMetricTable.COLUMN_TRANSACTION_CALLS); - metrics.add(calls); - } else { - metrics.add(0); - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - }); - return metrics; - } - - @Override public long getRespTimeMetric(int instanceId, long timeBucket) { - H2Client client = getClient(); - String sql = SqlBuilder.buildSql(GET_TPS_METRIC_SQL, InstanceMetricTable.TABLE, InstanceMetricTable.COLUMN_ID); - Object[] params = new Object[] {instanceId}; - try (ResultSet rs = client.executeQuery(sql, params)) { - if (rs.next()) { - long callTimes = rs.getLong(InstanceMetricTable.COLUMN_TRANSACTION_CALLS); - long costTotal = rs.getLong(InstanceMetricTable.COLUMN_TRANSACTION_DURATION_SUM); - return costTotal / callTimes; - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - return 0; - } - - @Override public JsonArray getRespTimeMetric(int instanceId, long startTimeBucket, long endTimeBucket) { - H2Client client = getClient(); - String sql = SqlBuilder.buildSql(GET_TPS_METRIC_SQL, InstanceMetricTable.TABLE, InstanceMetricTable.COLUMN_ID); - - long timeBucket = startTimeBucket; - List idList = new ArrayList<>(); - do { - String id = timeBucket + Const.ID_SPLIT + instanceId; - timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1); - idList.add(id); - } - while (timeBucket <= endTimeBucket); - - JsonArray metrics = new JsonArray(); - idList.forEach(id -> { - try (ResultSet rs = client.executeQuery(sql, new Object[] {id})) { - if (rs.next()) { - long callTimes = rs.getLong(InstanceMetricTable.COLUMN_TRANSACTION_CALLS); - long costTotal = rs.getLong(InstanceMetricTable.COLUMN_TRANSACTION_DURATION_SUM); - metrics.add(costTotal / callTimes); - } else { - metrics.add(0); - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - }); - return metrics; - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/MemoryMetricH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/MemoryMetricH2UIDAO.java deleted file mode 100644 index 26f7f5644..000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/MemoryMetricH2UIDAO.java +++ /dev/null @@ -1,107 +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; - -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.client.h2.H2Client; -import org.apache.skywalking.apm.collector.core.util.Const; -import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.apache.skywalking.apm.collector.storage.dao.IMemoryMetricUIDAO; -import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.apache.skywalking.apm.collector.client.h2.H2ClientException; -import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.apache.skywalking.apm.collector.storage.table.jvm.MemoryMetricTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author clevertension - */ -public class MemoryMetricH2UIDAO extends H2DAO implements IMemoryMetricUIDAO { - - private final Logger logger = LoggerFactory.getLogger(MemoryMetricH2UIDAO.class); - private static final String GET_MEMORY_METRIC_SQL = "select * from {0} where {1} =?"; - - public MemoryMetricH2UIDAO(H2Client client) { - super(client); - } - - @Override public JsonObject getMetric(int instanceId, long timeBucket, boolean isHeap) { - H2Client client = getClient(); - String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + isHeap; - String sql = SqlBuilder.buildSql(GET_MEMORY_METRIC_SQL, MemoryMetricTable.TABLE, MemoryMetricTable.COLUMN_ID); - Object[] params = new Object[] {id}; - JsonObject metric = new JsonObject(); - try (ResultSet rs = client.executeQuery(sql, params)) { - if (rs.next()) { - metric.addProperty("max", rs.getInt(MemoryMetricTable.COLUMN_MAX)); - metric.addProperty("init", rs.getInt(MemoryMetricTable.COLUMN_INIT)); - metric.addProperty("used", rs.getInt(MemoryMetricTable.COLUMN_USED)); - } else { - metric.addProperty("max", 0); - metric.addProperty("init", 0); - metric.addProperty("used", 0); - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - return metric; - } - - @Override public JsonObject getMetric(int instanceId, long startTimeBucket, long endTimeBucket, boolean isHeap) { - H2Client client = getClient(); - String sql = SqlBuilder.buildSql(GET_MEMORY_METRIC_SQL, MemoryMetricTable.TABLE, MemoryMetricTable.COLUMN_ID); - List idList = new ArrayList<>(); - long timeBucket = startTimeBucket; - do { - timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1); - String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + isHeap; - idList.add(id); - } - while (timeBucket <= endTimeBucket); - - JsonObject metric = new JsonObject(); - JsonArray usedMetric = new JsonArray(); - - idList.forEach(id -> { - try (ResultSet rs = client.executeQuery(sql, new String[] {id})) { - if (rs.next()) { - metric.addProperty("max", rs.getLong(MemoryMetricTable.COLUMN_MAX)); - metric.addProperty("init", rs.getLong(MemoryMetricTable.COLUMN_INIT)); - usedMetric.add(rs.getLong(MemoryMetricTable.COLUMN_USED)); - } else { - metric.addProperty("max", 0); - metric.addProperty("init", 0); - usedMetric.add(0); - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - }); - - metric.add("used", usedMetric); - return metric; - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/SegmentCostH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/SegmentCostH2UIDAO.java deleted file mode 100644 index 74baaa49c..000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/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; - -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.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/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/ServiceReferenceH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ServiceReferenceH2UIDAO.java deleted file mode 100644 index c78ea2fee..000000000 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ServiceReferenceH2UIDAO.java +++ /dev/null @@ -1,103 +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; - -import com.google.gson.JsonObject; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.LinkedHashMap; -import java.util.Map; -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.ColumnNameUtils; -import org.apache.skywalking.apm.collector.core.util.Const; -import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.apache.skywalking.apm.collector.storage.dao.IServiceReferenceUIDAO; -import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.apache.skywalking.apm.collector.storage.table.service.ServiceReferenceMetricTable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng, clevertension - */ -public class ServiceReferenceH2UIDAO extends H2DAO implements IServiceReferenceUIDAO { - - private final Logger logger = LoggerFactory.getLogger(ServiceReferenceH2UIDAO.class); - - public ServiceReferenceH2UIDAO(H2Client client) { - super(client); - } - - private static final String GET_SRV_REF_LOAD1 = "select {3}, {4}, sum({5}) as {5}, sum({6}) as {6}, sum({7}) as {7}" + - ",sum({8}) as {8} from {0} where {1} >= ? and {1} <= ? and {2} = ? group by {3}, {4}"; - - @Override - public Map load(int entryServiceId, long startTime, long endTime) { - H2Client client = getClient(); - String sql = SqlBuilder.buildSql(GET_SRV_REF_LOAD1, ServiceReferenceMetricTable.TABLE, - ServiceReferenceMetricTable.COLUMN_TIME_BUCKET, - ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID, ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID, - ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS, ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS, ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM, - ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM); - Object[] params = new Object[] {startTime, endTime, entryServiceId}; - - return load(client, params, sql); - } - - private Map load(H2Client client, Object[] params, String sql) { - Map serviceReferenceMap = new LinkedHashMap<>(); - - try (ResultSet rs = client.executeQuery(sql, params)) { - while (rs.next()) { - int frontServiceId = rs.getInt(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID); - parseSubAggregate(serviceReferenceMap, rs, frontServiceId); - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - return serviceReferenceMap; - } - - private void parseSubAggregate(Map serviceReferenceMap, ResultSet rs, - int frontServiceId) { - try { - int behindServiceId = rs.getInt(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID); - if (behindServiceId != 0) { - long calls = rs.getLong(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS); - long errorCalls = rs.getLong(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS); - long durationSum = rs.getLong(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM); - long errorDurationSum = rs.getLong(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM); - - JsonObject serviceReference = new JsonObject(); - serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID), frontServiceId); - serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID), behindServiceId); - serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS), calls); - serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS), errorCalls); - serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM), durationSum); - serviceReference.addProperty(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM), errorDurationSum); - - String id = serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID)) + Const.ID_SPLIT + serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID)); - serviceReferenceMap.put(id, serviceReference); - } - } catch (SQLException e) { - logger.error(e.getMessage(), e); - } - } -} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/acp/AbstractApplicationComponentH2PersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/acp/AbstractApplicationComponentH2PersistenceDAO.java index c08156682..25019b012 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/acp/AbstractApplicationComponentH2PersistenceDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/acp/AbstractApplicationComponentH2PersistenceDAO.java @@ -42,7 +42,7 @@ public abstract class AbstractApplicationComponentH2PersistenceDAO extends Abstr applicationComponent.setMetricId(resultSet.getString(ApplicationComponentTable.COLUMN_METRIC_ID)); applicationComponent.setComponentId(resultSet.getInt(ApplicationComponentTable.COLUMN_COMPONENT_ID)); - applicationComponent.setPeerId(resultSet.getInt(ApplicationComponentTable.COLUMN_PEER_ID)); + applicationComponent.setApplicationId(resultSet.getInt(ApplicationComponentTable.COLUMN_APPLICATION_ID)); applicationComponent.setTimeBucket(resultSet.getLong(ApplicationComponentTable.COLUMN_TIME_BUCKET)); return applicationComponent; } @@ -52,7 +52,7 @@ public abstract class AbstractApplicationComponentH2PersistenceDAO extends Abstr source.put(ApplicationComponentTable.COLUMN_METRIC_ID, streamData.getMetricId()); source.put(ApplicationComponentTable.COLUMN_COMPONENT_ID, streamData.getComponentId()); - source.put(ApplicationComponentTable.COLUMN_PEER_ID, streamData.getPeerId()); + source.put(ApplicationComponentTable.COLUMN_APPLICATION_ID, streamData.getApplicationId()); source.put(ApplicationComponentTable.COLUMN_TIME_BUCKET, streamData.getTimeBucket()); return source; diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ampp/AbstractApplicationMappingH2PersistenceDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ampp/AbstractApplicationMappingH2PersistenceDAO.java index a2d00ef39..3b6eb25c7 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ampp/AbstractApplicationMappingH2PersistenceDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ampp/AbstractApplicationMappingH2PersistenceDAO.java @@ -42,7 +42,7 @@ public abstract class AbstractApplicationMappingH2PersistenceDAO extends Abstrac applicationMapping.setMetricId(resultSet.getString(ApplicationMappingTable.COLUMN_METRIC_ID)); applicationMapping.setApplicationId(resultSet.getInt(ApplicationMappingTable.COLUMN_APPLICATION_ID)); - applicationMapping.setAddressId(resultSet.getInt(ApplicationMappingTable.COLUMN_ADDRESS_ID)); + applicationMapping.setMappingApplicationId(resultSet.getInt(ApplicationMappingTable.COLUMN_MAPPING_APPLICATION_ID)); applicationMapping.setTimeBucket(resultSet.getLong(ApplicationMappingTable.COLUMN_TIME_BUCKET)); return applicationMapping; } @@ -52,7 +52,7 @@ public abstract class AbstractApplicationMappingH2PersistenceDAO extends Abstrac source.put(ApplicationMappingTable.COLUMN_METRIC_ID, streamData.getMetricId()); source.put(ApplicationMappingTable.COLUMN_APPLICATION_ID, streamData.getApplicationId()); - source.put(ApplicationMappingTable.COLUMN_ADDRESS_ID, streamData.getAddressId()); + source.put(ApplicationMappingTable.COLUMN_MAPPING_APPLICATION_ID, streamData.getMappingApplicationId()); source.put(ApplicationMappingTable.COLUMN_TIME_BUCKET, streamData.getTimeBucket()); return source; diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/cache/ApplicationH2CacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/cache/ApplicationH2CacheDAO.java index 051eb91ff..6d4f612b7 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/cache/ApplicationH2CacheDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/cache/ApplicationH2CacheDAO.java @@ -22,10 +22,10 @@ import java.sql.ResultSet; import java.sql.SQLException; 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.Const; import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; import org.apache.skywalking.apm.collector.storage.dao.cache.IApplicationCacheDAO; import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.table.register.Application; import org.apache.skywalking.apm.collector.storage.table.register.ApplicationTable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,7 +38,7 @@ public class ApplicationH2CacheDAO extends H2DAO implements IApplicationCacheDAO private final Logger logger = LoggerFactory.getLogger(ApplicationH2CacheDAO.class); private static final String GET_APPLICATION_ID_SQL = "select {0} from {1} where {2} = ? and {3} = ?"; - private static final String GET_APPLICATION_CODE_SQL = "select {0} from {1} where {2} = ?"; + private static final String GET_APPLICATION_SQL = "select {0},{1} from {2} where {3} = ?"; public ApplicationH2CacheDAO(H2Client client) { super(client); @@ -61,19 +61,23 @@ public class ApplicationH2CacheDAO extends H2DAO implements IApplicationCacheDAO return 0; } - @Override public String getApplicationCode(int applicationId) { + @Override public Application getApplication(int applicationId) { logger.debug("get application code, applicationId: {}", applicationId); H2Client client = getClient(); - String sql = SqlBuilder.buildSql(GET_APPLICATION_CODE_SQL, ApplicationTable.COLUMN_APPLICATION_CODE, ApplicationTable.TABLE, ApplicationTable.COLUMN_APPLICATION_ID); + String sql = SqlBuilder.buildSql(GET_APPLICATION_SQL, ApplicationTable.COLUMN_APPLICATION_CODE, ApplicationTable.COLUMN_IS_ADDRESS, ApplicationTable.TABLE, ApplicationTable.COLUMN_APPLICATION_ID); Object[] params = new Object[] {applicationId}; try (ResultSet rs = client.executeQuery(sql, params)) { if (rs.next()) { - return rs.getString(1); + Application application = new Application(); + application.setApplicationId(applicationId); + application.setApplicationCode(rs.getString(1)); + application.setIsAddress(rs.getInt(2)); + return application; } } catch (SQLException | H2ClientException e) { logger.error(e.getMessage(), e); } - return Const.EMPTY_STRING; + return null; } @Override public int getApplicationIdByAddressId(int addressId) { diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/cache/ServiceNameH2CacheDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/cache/ServiceNameH2CacheDAO.java index dd5de4ab7..88c085382 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/cache/ServiceNameH2CacheDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/cache/ServiceNameH2CacheDAO.java @@ -16,17 +16,16 @@ * */ - package org.apache.skywalking.apm.collector.storage.h2.dao.cache; import java.sql.ResultSet; import java.sql.SQLException; -import org.apache.skywalking.apm.collector.core.util.Const; -import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; import org.apache.skywalking.apm.collector.client.h2.H2Client; import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; import org.apache.skywalking.apm.collector.storage.dao.cache.IServiceNameCacheDAO; import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.table.register.ServiceName; import org.apache.skywalking.apm.collector.storage.table.register.ServiceNameTable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,21 +44,23 @@ public class ServiceNameH2CacheDAO extends H2DAO implements IServiceNameCacheDAO super(client); } - @Override public String getServiceName(int serviceId) { + @Override public ServiceName get(int serviceId) { H2Client client = getClient(); String sql = SqlBuilder.buildSql(GET_SERVICE_NAME_SQL, ServiceNameTable.COLUMN_APPLICATION_ID, ServiceNameTable.COLUMN_SERVICE_NAME, ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SERVICE_ID); Object[] params = new Object[] {serviceId}; try (ResultSet rs = client.executeQuery(sql, params)) { if (rs.next()) { - String serviceName = rs.getString(ServiceNameTable.COLUMN_SERVICE_NAME); - int applicationId = rs.getInt(ServiceNameTable.COLUMN_APPLICATION_ID); - return applicationId + Const.ID_SPLIT + serviceName; + ServiceName serviceName = new ServiceName(); + serviceName.setServiceId(serviceId); + serviceName.setApplicationId(rs.getInt(ServiceNameTable.COLUMN_APPLICATION_ID)); + serviceName.setServiceName(rs.getString(ServiceNameTable.COLUMN_SERVICE_NAME)); + return serviceName; } } catch (SQLException | H2ClientException e) { logger.error(e.getMessage(), e); } - return Const.EMPTY_STRING; + return null; } @Override public int getServiceId(int applicationId, String serviceName) { diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/register/InstanceRegisterH2DAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/register/InstanceRegisterH2DAO.java index 45edf55a0..e1042f5dc 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/register/InstanceRegisterH2DAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/register/InstanceRegisterH2DAO.java @@ -22,6 +22,7 @@ import java.util.HashMap; import java.util.Map; 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.TimeBucketUtils; import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; import org.apache.skywalking.apm.collector.storage.dao.register.IInstanceRegisterDAO; import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; @@ -58,8 +59,8 @@ public class InstanceRegisterH2DAO extends H2DAO implements IInstanceRegisterDAO source.put(InstanceTable.COLUMN_INSTANCE_ID, instance.getInstanceId()); source.put(InstanceTable.COLUMN_APPLICATION_ID, instance.getApplicationId()); source.put(InstanceTable.COLUMN_AGENT_UUID, instance.getAgentUUID()); - source.put(InstanceTable.COLUMN_REGISTER_TIME, instance.getRegisterTime()); - source.put(InstanceTable.COLUMN_HEARTBEAT_TIME, instance.getHeartBeatTime()); + source.put(InstanceTable.COLUMN_REGISTER_TIME, TimeBucketUtils.INSTANCE.getSecondTimeBucket(instance.getRegisterTime())); + source.put(InstanceTable.COLUMN_HEARTBEAT_TIME, TimeBucketUtils.INSTANCE.getSecondTimeBucket(instance.getHeartBeatTime())); source.put(InstanceTable.COLUMN_OS_INFO, instance.getOsInfo()); source.put(InstanceTable.COLUMN_ADDRESS_ID, instance.getAddressId()); source.put(InstanceTable.COLUMN_IS_ADDRESS, instance.getIsAddress()); @@ -77,7 +78,7 @@ public class InstanceRegisterH2DAO extends H2DAO implements IInstanceRegisterDAO H2Client client = getClient(); String sql = SqlBuilder.buildSql(UPDATE_HEARTBEAT_TIME_SQL, InstanceTable.TABLE, InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.COLUMN_ID); - Object[] params = new Object[] {heartbeatTime, instanceId}; + Object[] params = new Object[] {TimeBucketUtils.INSTANCE.getSecondTimeBucket(heartbeatTime), instanceId}; try { client.execute(sql, params); } catch (H2ClientException e) { diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/register/NetworkAddressRegisterH2DAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/register/NetworkAddressRegisterH2DAO.java index 9ff6d0c8a..b0b632fac 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/register/NetworkAddressRegisterH2DAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/register/NetworkAddressRegisterH2DAO.java @@ -59,6 +59,7 @@ public class NetworkAddressRegisterH2DAO extends H2DAO implements INetworkAddres source.put(NetworkAddressTable.COLUMN_ID, networkAddress.getId()); source.put(NetworkAddressTable.COLUMN_NETWORK_ADDRESS, networkAddress.getNetworkAddress()); source.put(NetworkAddressTable.COLUMN_ADDRESS_ID, networkAddress.getAddressId()); + source.put(NetworkAddressTable.COLUMN_SPAN_LAYER, networkAddress.getSpanLayer()); String sql = SqlBuilder.buildBatchInsertSql(NetworkAddressTable.TABLE, source.keySet()); Object[] params = source.values().toArray(new Object[0]); diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationComponentH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/ApplicationComponentH2UIDAO.java similarity index 65% rename from apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationComponentH2UIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/ApplicationComponentH2UIDAO.java index cb165ee0f..d9cf10aef 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationComponentH2UIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/ApplicationComponentH2UIDAO.java @@ -16,19 +16,20 @@ * */ +package org.apache.skywalking.apm.collector.storage.h2.dao.ui; -package org.apache.skywalking.apm.collector.storage.h2.dao; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.LinkedList; +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.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationComponentUIDAO; import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; import org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponentTable; -import org.apache.skywalking.apm.collector.client.h2.H2ClientException; -import org.apache.skywalking.apm.collector.storage.dao.IApplicationComponentUIDAO; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,31 +45,29 @@ public class ApplicationComponentH2UIDAO extends H2DAO implements IApplicationCo super(client); } - @Override public JsonArray load(long startTime, long endTime) { - JsonArray applicationComponentArray = new JsonArray(); - applicationComponentArray.addAll(aggregationComponent(startTime, endTime)); - return applicationComponentArray; - } - - private JsonArray aggregationComponent(long startTime, long endTime) { + @Override public List load(Step step, long startTime, long endTime) { H2Client client = getClient(); - JsonArray applicationComponentArray = new JsonArray(); - String sql = SqlBuilder.buildSql(AGGREGATE_COMPONENT_SQL, ApplicationComponentTable.COLUMN_COMPONENT_ID, ApplicationComponentTable.COLUMN_PEER_ID, - ApplicationComponentTable.TABLE, ApplicationComponentTable.COLUMN_TIME_BUCKET); + String tableName = TimePyramidTableNameBuilder.build(step, ApplicationComponentTable.TABLE); + + List applicationComponents = new LinkedList<>(); + String sql = SqlBuilder.buildSql(AGGREGATE_COMPONENT_SQL, ApplicationComponentTable.COLUMN_COMPONENT_ID, ApplicationComponentTable.COLUMN_APPLICATION_ID, + tableName, ApplicationComponentTable.COLUMN_TIME_BUCKET); + Object[] params = new Object[] {startTime, endTime}; try (ResultSet rs = client.executeQuery(sql, params)) { while (rs.next()) { - int peerId = rs.getInt(ApplicationComponentTable.COLUMN_PEER_ID); + int applicationId = rs.getInt(ApplicationComponentTable.COLUMN_APPLICATION_ID); int componentId = rs.getInt(ApplicationComponentTable.COLUMN_COMPONENT_ID); - JsonObject applicationComponentObj = new JsonObject(); - applicationComponentObj.addProperty(ApplicationComponentTable.COLUMN_COMPONENT_ID, componentId); - applicationComponentObj.addProperty(ApplicationComponentTable.COLUMN_PEER_ID, peerId); - applicationComponentArray.add(applicationComponentObj); + + ApplicationComponent applicationComponent = new ApplicationComponent(); + applicationComponent.setComponentId(componentId); + applicationComponent.setApplicationId(applicationId); + applicationComponents.add(applicationComponent); } } catch (SQLException | H2ClientException e) { logger.error(e.getMessage(), e); } - return applicationComponentArray; + return applicationComponents; } } diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationMappingH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/ApplicationMappingH2UIDAO.java similarity index 68% rename from apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationMappingH2UIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/ApplicationMappingH2UIDAO.java index d1dd55677..9669f5891 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationMappingH2UIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/ApplicationMappingH2UIDAO.java @@ -16,19 +16,20 @@ * */ +package org.apache.skywalking.apm.collector.storage.h2.dao.ui; -package org.apache.skywalking.apm.collector.storage.h2.dao; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.LinkedList; +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.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMappingUIDAO; import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMappingTable; -import org.apache.skywalking.apm.collector.client.h2.H2ClientException; -import org.apache.skywalking.apm.collector.storage.dao.IApplicationMappingUIDAO; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,26 +45,29 @@ public class ApplicationMappingH2UIDAO extends H2DAO implements IApplicationMapp super(client); } - @Override public JsonArray load(long startTime, long endTime) { - H2Client client = getClient(); - JsonArray applicationMappingArray = new JsonArray(); - String sql = SqlBuilder.buildSql(APPLICATION_MAPPING_SQL, ApplicationMappingTable.COLUMN_APPLICATION_ID, - ApplicationMappingTable.COLUMN_ADDRESS_ID, ApplicationMappingTable.TABLE, ApplicationMappingTable.COLUMN_TIME_BUCKET); + @Override public List load(Step step, long startTime, long endTime) { + String tableName = TimePyramidTableNameBuilder.build(step, ApplicationMappingTable.TABLE); + H2Client client = getClient(); + String sql = SqlBuilder.buildSql(APPLICATION_MAPPING_SQL, ApplicationMappingTable.COLUMN_APPLICATION_ID, + ApplicationMappingTable.COLUMN_MAPPING_APPLICATION_ID, tableName, ApplicationMappingTable.COLUMN_TIME_BUCKET); + + List applicationMappings = new LinkedList<>(); Object[] params = new Object[] {startTime, endTime}; try (ResultSet rs = client.executeQuery(sql, params)) { while (rs.next()) { int applicationId = rs.getInt(ApplicationMappingTable.COLUMN_APPLICATION_ID); - int addressId = rs.getInt(ApplicationMappingTable.COLUMN_ADDRESS_ID); - JsonObject applicationMappingObj = new JsonObject(); - applicationMappingObj.addProperty(ApplicationMappingTable.COLUMN_APPLICATION_ID, applicationId); - applicationMappingObj.addProperty(ApplicationMappingTable.COLUMN_ADDRESS_ID, addressId); - applicationMappingArray.add(applicationMappingObj); + int addressId = rs.getInt(ApplicationMappingTable.COLUMN_MAPPING_APPLICATION_ID); + + ApplicationMapping applicationMapping = new ApplicationMapping(); + applicationMapping.setApplicationId(applicationId); + applicationMapping.setMappingApplicationId(addressId); + applicationMappings.add(applicationMapping); } } catch (SQLException | H2ClientException e) { logger.error(e.getMessage(), e); } - logger.debug("node mapping data: {}", applicationMappingArray.toString()); - return applicationMappingArray; + logger.debug("node mapping data: {}", applicationMappings.toString()); + return applicationMappings; } } diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationReferenceMetricH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/ApplicationReferenceMetricH2UIDAO.java similarity index 83% rename from apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationReferenceMetricH2UIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/ApplicationReferenceMetricH2UIDAO.java index 216485de9..e9c8a707f 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ApplicationReferenceMetricH2UIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/ApplicationReferenceMetricH2UIDAO.java @@ -16,13 +16,16 @@ * */ - -package org.apache.skywalking.apm.collector.storage.h2.dao; +package org.apache.skywalking.apm.collector.storage.h2.dao.ui; import com.google.gson.JsonArray; +import java.util.List; import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationReferenceMetricUIDAO; import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; -import org.apache.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.table.MetricSource; +import org.apache.skywalking.apm.collector.storage.ui.common.Call; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,7 +42,8 @@ public class ApplicationReferenceMetricH2UIDAO extends H2DAO implements IApplica super(client); } - @Override public JsonArray load(long startTime, long endTime) { + @Override public List getFrontApplications(Step step, int applicationId, long startTime, long endTime, + MetricSource metricSource) { H2Client client = getClient(); JsonArray applicationReferenceMetricArray = new JsonArray(); // String sql = SqlBuilder.buildSql(APPLICATION_REFERENCE_SQL, ApplicationReferenceMetricTable.COLUMN_S1_LTE, @@ -67,6 +71,15 @@ public class ApplicationReferenceMetricH2UIDAO extends H2DAO implements IApplica // } catch (SQLException | H2ClientException e) { // logger.error(e.getMessage(), e); // } - return applicationReferenceMetricArray; + return null; + } + + @Override public List getBehindApplications(Step step, int applicationId, long startTime, long endTime, + MetricSource metricSource) { + return null; + } + + @Override public List getApplications(Step step, long startTime, long endTime, MetricSource metricSource) { + 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/CpuMetricH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/CpuMetricH2UIDAO.java similarity index 55% rename from apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/CpuMetricH2UIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/CpuMetricH2UIDAO.java index 5f840cb6d..a044f4a0d 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/CpuMetricH2UIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/CpuMetricH2UIDAO.java @@ -16,22 +16,22 @@ * */ +package org.apache.skywalking.apm.collector.storage.h2.dao.ui; -package org.apache.skywalking.apm.collector.storage.h2.dao; - -import com.google.gson.JsonArray; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; -import org.apache.skywalking.apm.collector.core.util.Const; -import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.apache.skywalking.apm.collector.storage.table.jvm.CpuMetricTable; 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.TimeBucketUtils; -import org.apache.skywalking.apm.collector.storage.dao.ICpuMetricUIDAO; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.ui.ICpuMetricUIDAO; import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.table.jvm.CpuMetricTable; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.storage.utils.DurationPoint; +import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,48 +46,28 @@ public class CpuMetricH2UIDAO extends H2DAO implements ICpuMetricUIDAO { super(client); } - @Override public int getMetric(int instanceId, long timeBucket) { - String id = timeBucket + Const.ID_SPLIT + instanceId; + @Override public List getCPUTrend(int instanceId, Step step, List durationPoints) { H2Client client = getClient(); - String sql = SqlBuilder.buildSql(GET_CPU_METRIC_SQL, CpuMetricTable.TABLE, CpuMetricTable.COLUMN_ID); - Object[] params = new Object[] {id}; - try (ResultSet rs = client.executeQuery(sql, params)) { - if (rs.next()) { - return rs.getInt(CpuMetricTable.COLUMN_USAGE_PERCENT); - } - } catch (SQLException | H2ClientException e) { - logger.error(e.getMessage(), e); - } - return 0; - } + String tableName = TimePyramidTableNameBuilder.build(step, CpuMetricTable.TABLE); + String sql = SqlBuilder.buildSql(GET_CPU_METRIC_SQL, tableName, CpuMetricTable.COLUMN_ID); - @Override public JsonArray getMetric(int instanceId, long startTimeBucket, long endTimeBucket) { - H2Client client = getClient(); - String sql = SqlBuilder.buildSql(GET_CPU_METRIC_SQL, CpuMetricTable.TABLE, CpuMetricTable.COLUMN_ID); + List cpuTrends = new LinkedList<>(); + durationPoints.forEach(durationPoint -> { + String id = durationPoint.getPoint() + Const.ID_SPLIT + instanceId; - long timeBucket = startTimeBucket; - List idList = new ArrayList<>(); - do { - timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1); - String id = timeBucket + Const.ID_SPLIT + instanceId; - idList.add(id); - } - while (timeBucket <= endTimeBucket); - - JsonArray metrics = new JsonArray(); - idList.forEach(id -> { try (ResultSet rs = client.executeQuery(sql, new String[] {id})) { if (rs.next()) { double cpuUsed = rs.getDouble(CpuMetricTable.COLUMN_USAGE_PERCENT); - metrics.add((int)(cpuUsed * 100)); + long times = rs.getLong(CpuMetricTable.COLUMN_TIMES); + cpuTrends.add((int)((cpuUsed / times) * 100)); } else { - metrics.add(0); + cpuTrends.add(0); } } catch (SQLException | H2ClientException e) { logger.error(e.getMessage(), e); } }); - return metrics; + return cpuTrends; } } diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/GCMetricH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/GCMetricH2UIDAO.java new file mode 100644 index 000000000..e15363a88 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/GCMetricH2UIDAO.java @@ -0,0 +1,83 @@ +/* + * 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.LinkedList; +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.Const; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.ui.IGCMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.table.jvm.GCMetricTable; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.storage.utils.DurationPoint; +import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder; +import org.apache.skywalking.apm.network.proto.GCPhrase; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng, clevertension + */ +public class GCMetricH2UIDAO extends H2DAO implements IGCMetricUIDAO { + + private final Logger logger = LoggerFactory.getLogger(GCMetricH2UIDAO.class); + private static final String GET_GC_METRIC_SQL = "select * from {0} where {1} = ?"; + + public GCMetricH2UIDAO(H2Client client) { + super(client); + } + + @Override public List getYoungGCTrend(int instanceId, Step step, List durationPoints) { + return getGCTrend(instanceId, step, durationPoints, GCPhrase.NEW_VALUE); + } + + @Override public List getOldGCTrend(int instanceId, Step step, List durationPoints) { + return getGCTrend(instanceId, step, durationPoints, GCPhrase.OLD_VALUE); + } + + private List getGCTrend(int instanceId, Step step, List durationPoints, int gcPhrase) { + String tableName = TimePyramidTableNameBuilder.build(step, GCMetricTable.TABLE); + + H2Client client = getClient(); + String sql = SqlBuilder.buildSql(GET_GC_METRIC_SQL, tableName, GCMetricTable.COLUMN_ID); + + List gcTrends = new LinkedList<>(); + durationPoints.forEach(durationPoint -> { + String id = durationPoint.getPoint() + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + gcPhrase; + try (ResultSet rs = client.executeQuery(sql, new String[] {id})) { + if (rs.next()) { + long count = rs.getLong(GCMetricTable.COLUMN_COUNT); + long times = rs.getLong(GCMetricTable.COLUMN_TIMES); + gcTrends.add((int)(count / times)); + } else { + gcTrends.add(0); + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + }); + + return gcTrends; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/GlobalTraceH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/GlobalTraceH2UIDAO.java similarity index 96% rename from apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/GlobalTraceH2UIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/GlobalTraceH2UIDAO.java index 9a2eeee62..c1cb1e56c 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/GlobalTraceH2UIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/GlobalTraceH2UIDAO.java @@ -17,7 +17,7 @@ */ -package org.apache.skywalking.apm.collector.storage.h2.dao; +package org.apache.skywalking.apm.collector.storage.h2.dao.ui; import java.sql.ResultSet; import java.sql.SQLException; @@ -25,7 +25,7 @@ import java.util.ArrayList; import java.util.List; 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.IGlobalTraceUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IGlobalTraceUIDAO; import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; import org.apache.skywalking.apm.collector.client.h2.H2ClientException; import org.apache.skywalking.apm.collector.storage.table.global.GlobalTraceTable; diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/InstanceH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/InstanceH2UIDAO.java similarity index 71% rename from apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/InstanceH2UIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/InstanceH2UIDAO.java index 674cbee05..f80e8605d 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/InstanceH2UIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/InstanceH2UIDAO.java @@ -16,22 +16,23 @@ * */ -package org.apache.skywalking.apm.collector.storage.h2.dao; +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.LinkedList; 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.TimeBucketUtils; import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; -import org.apache.skywalking.apm.collector.storage.dao.IInstanceUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceUIDAO; import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; import org.apache.skywalking.apm.collector.storage.table.register.Instance; import org.apache.skywalking.apm.collector.storage.table.register.InstanceTable; +import org.apache.skywalking.apm.collector.storage.ui.application.Application; +import org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,7 +50,6 @@ public class InstanceH2UIDAO extends H2DAO implements IInstanceUIDAO { private static final String GET_LAST_HEARTBEAT_TIME_SQL = "select {0} from {1} where {2} > ? limit 1"; private static final String GET_INST_LAST_HEARTBEAT_TIME_SQL = "select {0} from {1} where {2} > ? and {3} = ? limit 1"; private static final String GET_INSTANCE_SQL = "select * from {0} where {1} = ?"; - private static final String GET_INSTANCES_SQL = "select * from {0} where {1} = ? and {2} >= ?"; private static final String GET_APPLICATIONS_SQL = "select {3}, count({0}) as cnt from {1} where {2} >= ? group by {3} limit 100"; @Override @@ -88,9 +88,9 @@ public class InstanceH2UIDAO extends H2DAO implements IInstanceUIDAO { } @Override - public JsonArray getApplications(long startTime, long endTime) { + public List getApplications(long startTime, long endTime, int... applicationIds) { H2Client client = getClient(); - JsonArray applications = new JsonArray(); + List applications = new LinkedList<>(); String sql = SqlBuilder.buildSql(GET_APPLICATIONS_SQL, InstanceTable.COLUMN_INSTANCE_ID, InstanceTable.TABLE, InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.COLUMN_APPLICATION_ID); Object[] params = new Object[] {startTime}; @@ -98,9 +98,9 @@ public class InstanceH2UIDAO extends H2DAO implements IInstanceUIDAO { while (rs.next()) { Integer applicationId = rs.getInt(InstanceTable.COLUMN_APPLICATION_ID); logger.debug("applicationId: {}", applicationId); - JsonObject application = new JsonObject(); - application.addProperty("applicationId", applicationId); - application.addProperty("instanceCount", rs.getInt("cnt")); + Application application = new Application(); + application.setId(applicationId); + application.setNumOfServer(rs.getInt("cnt")); applications.add(application); } } catch (SQLException | H2ClientException e) { @@ -131,25 +131,36 @@ public class InstanceH2UIDAO extends H2DAO implements IInstanceUIDAO { return null; } - @Override - public List getInstances(int applicationId, long timeBucket) { - logger.debug("get instances info, application id: {}, timeBucket: {}", applicationId, timeBucket); - List instanceList = new LinkedList<>(); + @Override public List searchServer(String keyword, long start, long end) { + logger.debug("get instances info, keyword: {}, start: {}, end: {}", keyword, start, end); + String dynamicSql = "select * from {0} where {1} like ? and {2} >= ? and {2} <= ? and {3} = ?"; + String sql = SqlBuilder.buildSql(dynamicSql, InstanceTable.TABLE, InstanceTable.COLUMN_OS_INFO, InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.COLUMN_IS_ADDRESS); + Object[] params = new Object[] {keyword, start, end, BooleanUtils.FALSE}; + return buildAppServerInfo(sql, params); + } + + @Override public List getAllServer(int applicationId, long start, long end) { + logger.debug("get instances info, applicationId: {}, start: {}, end: {}", applicationId, start, end); + String dynamicSql = "select * from {0} where {1} = ? and {2} >= ? and {2} <= ? and {3} = ?"; + String sql = SqlBuilder.buildSql(dynamicSql, InstanceTable.TABLE, InstanceTable.COLUMN_APPLICATION_ID, InstanceTable.COLUMN_HEARTBEAT_TIME, InstanceTable.COLUMN_IS_ADDRESS); + Object[] params = new Object[] {applicationId, start, end, BooleanUtils.FALSE}; + return buildAppServerInfo(sql, params); + } + + private List buildAppServerInfo(String sql, Object[] params) { H2Client client = getClient(); - String sql = SqlBuilder.buildSql(GET_INSTANCES_SQL, InstanceTable.TABLE, InstanceTable.COLUMN_APPLICATION_ID, InstanceTable.COLUMN_HEARTBEAT_TIME); - Object[] params = new Object[] {applicationId, timeBucket}; + + List appServerInfos = new LinkedList<>(); try (ResultSet rs = client.executeQuery(sql, params)) { while (rs.next()) { - Instance instance = new Instance(); - instance.setId(rs.getString(InstanceTable.COLUMN_ID)); - instance.setApplicationId(rs.getInt(InstanceTable.COLUMN_APPLICATION_ID)); - instance.setHeartBeatTime(rs.getLong(InstanceTable.COLUMN_HEARTBEAT_TIME)); - instance.setInstanceId(rs.getInt(InstanceTable.COLUMN_INSTANCE_ID)); - instanceList.add(instance); + AppServerInfo appServerInfo = new AppServerInfo(); + appServerInfo.setId(rs.getInt(InstanceTable.COLUMN_INSTANCE_ID)); + appServerInfo.setOsInfo(rs.getString(InstanceTable.COLUMN_OS_INFO)); + appServerInfos.add(appServerInfo); } } catch (SQLException | H2ClientException e) { logger.error(e.getMessage(), e); } - return instanceList; + return appServerInfos; } } diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/InstanceMetricH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/InstanceMetricH2UIDAO.java new file mode 100644 index 000000000..fdc746e82 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/InstanceMetricH2UIDAO.java @@ -0,0 +1,106 @@ +/* + * 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.LinkedList; +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.Const; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.table.MetricSource; +import org.apache.skywalking.apm.collector.storage.table.instance.InstanceMetricTable; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo; +import org.apache.skywalking.apm.collector.storage.utils.DurationPoint; +import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng, clevertension + */ +public class InstanceMetricH2UIDAO extends H2DAO implements IInstanceMetricUIDAO { + + private final Logger logger = LoggerFactory.getLogger(InstanceMetricH2UIDAO.class); + private static final String GET_TPS_METRIC_SQL = "select * from {0} where {1} = ?"; + + public InstanceMetricH2UIDAO(H2Client client) { + super(client); + } + + @Override public List getTopNServerThroughput(int applicationId, Step step, long start, long end, + long secondBetween, int topN, MetricSource metricSource) { + return null; + } + + @Override public List getServerTPSTrend(int instanceId, Step step, List durationPoints) { + H2Client client = getClient(); + String tableName = TimePyramidTableNameBuilder.build(step, InstanceMetricTable.TABLE); + + String sql = SqlBuilder.buildSql(GET_TPS_METRIC_SQL, tableName, InstanceMetricTable.COLUMN_ID); + + List throughputTrend = new LinkedList<>(); + durationPoints.forEach(durationPoint -> { + String id = durationPoint.getPoint() + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + MetricSource.Callee.getValue(); + try (ResultSet rs = client.executeQuery(sql, new Object[] {id})) { + if (rs.next()) { + long callTimes = rs.getLong(InstanceMetricTable.COLUMN_TRANSACTION_CALLS); + throughputTrend.add((int)(callTimes / durationPoint.getSecondsBetween())); + } else { + throughputTrend.add(0); + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + }); + + return throughputTrend; + } + + @Override public List getResponseTimeTrend(int instanceId, Step step, List durationPoints) { + H2Client client = getClient(); + + String tableName = TimePyramidTableNameBuilder.build(step, InstanceMetricTable.TABLE); + String sql = SqlBuilder.buildSql(GET_TPS_METRIC_SQL, tableName, InstanceMetricTable.COLUMN_ID); + + List responseTimeTrends = new LinkedList<>(); + durationPoints.forEach(durationPoint -> { + String id = durationPoint.getPoint() + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + MetricSource.Callee.getValue(); + try (ResultSet rs = client.executeQuery(sql, new Object[] {id})) { + if (rs.next()) { + long callTimes = rs.getLong(InstanceMetricTable.COLUMN_TRANSACTION_CALLS); + long errorCallTimes = rs.getLong(InstanceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS); + long durationSum = rs.getLong(InstanceMetricTable.COLUMN_TRANSACTION_DURATION_SUM); + long errorDurationSum = rs.getLong(InstanceMetricTable.COLUMN_BUSINESS_TRANSACTION_ERROR_DURATION_SUM); + responseTimeTrends.add((int)((durationSum - errorDurationSum) / (callTimes - errorCallTimes))); + } else { + responseTimeTrends.add(0); + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + }); + return responseTimeTrends; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/MemoryMetricH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/MemoryMetricH2UIDAO.java new file mode 100644 index 000000000..bc84318cf --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/MemoryMetricH2UIDAO.java @@ -0,0 +1,86 @@ +/* + * 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.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.Const; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.ui.IMemoryMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.table.jvm.MemoryMetricTable; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.storage.utils.DurationPoint; +import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author clevertension + */ +public class MemoryMetricH2UIDAO extends H2DAO implements IMemoryMetricUIDAO { + + private final Logger logger = LoggerFactory.getLogger(MemoryMetricH2UIDAO.class); + private static final String GET_MEMORY_METRIC_SQL = "select * from {0} where {1} =?"; + + public MemoryMetricH2UIDAO(H2Client client) { + super(client); + } + + @Override public Trend getHeapMemoryTrend(int instanceId, Step step, List durationPoints) { + return getMemoryTrend(instanceId, step, durationPoints, true); + } + + @Override public Trend getNoHeapMemoryTrend(int instanceId, Step step, List durationPoints) { + return getMemoryTrend(instanceId, step, durationPoints, false); + } + + private Trend getMemoryTrend(int instanceId, Step step, List durationPoints, + boolean isHeap) { + String tableName = TimePyramidTableNameBuilder.build(step, MemoryMetricTable.TABLE); + + H2Client client = getClient(); + String sql = SqlBuilder.buildSql(GET_MEMORY_METRIC_SQL, tableName, MemoryMetricTable.COLUMN_ID); + + Trend trend = new Trend(); + durationPoints.forEach(durationPoint -> { + String id = durationPoint.getPoint() + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + BooleanUtils.booleanToValue(isHeap); + try (ResultSet rs = client.executeQuery(sql, new String[] {id})) { + if (rs.next()) { + long max = rs.getLong(MemoryMetricTable.COLUMN_MAX); + long used = rs.getLong(MemoryMetricTable.COLUMN_USED); + long times = rs.getLong(MemoryMetricTable.COLUMN_TIMES); + trend.getMetrics().add((int)(used / times)); + trend.getMaxMetrics().add((int)(max / times)); + } else { + trend.getMetrics().add(0); + trend.getMaxMetrics().add(0); + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + }); + + return trend; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/MemoryPoolMetricH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/MemoryPoolMetricH2UIDAO.java similarity index 92% rename from apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/MemoryPoolMetricH2UIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/MemoryPoolMetricH2UIDAO.java index d4a5b11ae..b60d49276 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/MemoryPoolMetricH2UIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/MemoryPoolMetricH2UIDAO.java @@ -16,8 +16,7 @@ * */ - -package org.apache.skywalking.apm.collector.storage.h2.dao; +package org.apache.skywalking.apm.collector.storage.h2.dao.ui; import com.google.gson.JsonArray; import com.google.gson.JsonObject; @@ -25,12 +24,11 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -import org.apache.skywalking.apm.collector.core.util.Const; -import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; 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.TimeBucketUtils; -import org.apache.skywalking.apm.collector.storage.dao.IMemoryPoolMetricUIDAO; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.ui.IMemoryPoolMetricUIDAO; import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; import org.apache.skywalking.apm.collector.storage.table.jvm.MemoryPoolMetricTable; import org.slf4j.Logger; @@ -76,7 +74,7 @@ public class MemoryPoolMetricH2UIDAO extends H2DAO implements IMemoryPoolMetricU List idList = new ArrayList<>(); long timeBucket = startTimeBucket; do { - timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, 1); +// timeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND, timeBucket, 1); String id = timeBucket + Const.ID_SPLIT + instanceId + Const.ID_SPLIT + poolType; idList.add(id); } diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/NetworkAddressH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/NetworkAddressH2UIDAO.java new file mode 100644 index 000000000..54383f0fd --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/NetworkAddressH2UIDAO.java @@ -0,0 +1,57 @@ +/* + * 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 org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.client.h2.H2ClientException; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.ui.INetworkAddressUIDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.table.register.NetworkAddressTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class NetworkAddressH2UIDAO extends H2DAO implements INetworkAddressUIDAO { + + private final Logger logger = LoggerFactory.getLogger(NetworkAddressH2UIDAO.class); + + public NetworkAddressH2UIDAO(H2Client client) { + super(client); + } + + @Override public int getNumOfSpanLayer(int spanLayer) { + String dynamicSql = "select count({0}) as cnt from {1} where {2} = ?"; + String sql = SqlBuilder.buildSql(dynamicSql, NetworkAddressTable.COLUMN_NETWORK_ADDRESS, NetworkAddressTable.TABLE, NetworkAddressTable.COLUMN_SPAN_LAYER); + Object[] params = new Object[] {spanLayer}; + + try (ResultSet rs = getClient().executeQuery(sql, params)) { + if (rs.next()) { + return rs.getInt("cnt"); + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + return 0; + } +} 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/dao/SegmentH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/SegmentH2UIDAO.java similarity index 95% rename from apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/SegmentH2UIDAO.java rename to apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/SegmentH2UIDAO.java index 7d5019bc0..be52519bb 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/SegmentH2UIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/SegmentH2UIDAO.java @@ -17,14 +17,14 @@ */ -package org.apache.skywalking.apm.collector.storage.h2.dao; +package org.apache.skywalking.apm.collector.storage.h2.dao.ui; import com.google.protobuf.InvalidProtocolBufferException; import java.sql.ResultSet; import java.sql.SQLException; 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.ISegmentUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.ISegmentUIDAO; import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; import org.apache.skywalking.apm.collector.storage.table.segment.SegmentTable; import org.apache.skywalking.apm.collector.client.h2.H2ClientException; diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/ServiceMetricH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/ServiceMetricH2UIDAO.java new file mode 100644 index 000000000..0bab7e5b8 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/ServiceMetricH2UIDAO.java @@ -0,0 +1,119 @@ +/* + * 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.Collection; +import java.util.LinkedList; +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.Const; +import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.table.MetricSource; +import org.apache.skywalking.apm.collector.storage.table.service.ServiceMetricTable; +import org.apache.skywalking.apm.collector.storage.ui.common.Node; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric; +import org.apache.skywalking.apm.collector.storage.utils.DurationPoint; +import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ServiceMetricH2UIDAO extends H2DAO implements IServiceMetricUIDAO { + + private final Logger logger = LoggerFactory.getLogger(ServiceMetricH2UIDAO.class); + + public ServiceMetricH2UIDAO(H2Client client) { + super(client); + } + + @Override + public List getServiceResponseTimeTrend(int serviceId, Step step, List durationPoints) { + String tableName = TimePyramidTableNameBuilder.build(step, ServiceMetricTable.TABLE); + + H2Client client = getClient(); + String dynamicSql = "select * from {0} where {1} = ?"; + String sql = SqlBuilder.buildSql(dynamicSql, tableName, ServiceMetricTable.COLUMN_ID); + + List trends = new LinkedList<>(); + durationPoints.forEach(durationPoint -> { + String id = durationPoint.getPoint() + Const.ID_SPLIT + serviceId + Const.ID_SPLIT + MetricSource.Callee.getValue(); + + try (ResultSet rs = client.executeQuery(sql, new String[] {id})) { + if (rs.next()) { + long calls = rs.getLong(ServiceMetricTable.COLUMN_TRANSACTION_CALLS); + long errorCalls = rs.getLong(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS); + long durationSum = rs.getLong(ServiceMetricTable.COLUMN_TRANSACTION_DURATION_SUM); + long errorDurationSum = rs.getLong(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM); + trends.add((int)((durationSum - errorDurationSum) / (calls - errorCalls))); + } else { + trends.add(0); + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + }); + + return trends; + } + + @Override public List getServiceSLATrend(int serviceId, Step step, List durationPoints) { + String tableName = TimePyramidTableNameBuilder.build(step, ServiceMetricTable.TABLE); + + H2Client client = getClient(); + String dynamicSql = "select * from {0} where {1} = ?"; + String sql = SqlBuilder.buildSql(dynamicSql, tableName, ServiceMetricTable.COLUMN_ID); + + List trends = new LinkedList<>(); + durationPoints.forEach(durationPoint -> { + String id = durationPoint.getPoint() + Const.ID_SPLIT + serviceId + Const.ID_SPLIT + MetricSource.Callee.getValue(); + + try (ResultSet rs = client.executeQuery(sql, new String[] {id})) { + if (rs.next()) { + long calls = rs.getLong(ServiceMetricTable.COLUMN_TRANSACTION_CALLS); + long errorCalls = rs.getLong(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS); + trends.add((int)(((calls - errorCalls) / calls)) * 10000); + } else { + trends.add(10000); + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + }); + + return trends; + } + + @Override public List getServicesMetric(Step step, long startTime, long endTime, MetricSource metricSource, + Collection serviceIds) { + return null; + } + + @Override public List getSlowService(int applicationId, Step step, long start, long end, Integer top, + MetricSource metricSource) { + 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/ServiceNameServiceH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/ServiceNameServiceH2UIDAO.java new file mode 100644 index 000000000..29470eefb --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/ServiceNameServiceH2UIDAO.java @@ -0,0 +1,79 @@ +/* + * 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.LinkedList; +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.storage.base.sql.SqlBuilder; +import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceNameServiceUIDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.table.register.ServiceNameTable; +import org.apache.skywalking.apm.collector.storage.ui.service.ServiceInfo; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ServiceNameServiceH2UIDAO extends H2DAO implements IServiceNameServiceUIDAO { + + private final Logger logger = LoggerFactory.getLogger(ServiceNameServiceH2UIDAO.class); + + public ServiceNameServiceH2UIDAO(H2Client client) { + super(client); + } + + @Override public int getCount() { + String dynamicSql = "select count({0}) as cnt from {1}"; + String sql = SqlBuilder.buildSql(dynamicSql, ServiceNameTable.COLUMN_SERVICE_ID, ServiceNameTable.TABLE); + Object[] params = new Object[] {}; + + try (ResultSet rs = getClient().executeQuery(sql, params)) { + if (rs.next()) { + return rs.getInt("cnt"); + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + return 0; + } + + @Override public List searchService(String keyword, int topN) { + String dynamicSql = "select {0},{1} from {2} where {3} like ? limit ?"; + String sql = SqlBuilder.buildSql(dynamicSql, ServiceNameTable.COLUMN_SERVICE_ID, ServiceNameTable.COLUMN_SERVICE_NAME, ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SERVICE_NAME); + Object[] params = new Object[] {keyword, topN}; + + List serviceInfos = new LinkedList<>(); + try (ResultSet rs = getClient().executeQuery(sql, params)) { + while (rs.next()) { + ServiceInfo serviceInfo = new ServiceInfo(); + serviceInfo.setId(rs.getInt(ServiceNameTable.COLUMN_SERVICE_ID)); + serviceInfo.setName(rs.getString(ServiceNameTable.COLUMN_SERVICE_NAME)); + serviceInfos.add(serviceInfo); + } + } catch (SQLException | H2ClientException e) { + logger.error(e.getMessage(), e); + } + return serviceInfos; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/ServiceReferenceH2MetricUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/ServiceReferenceH2MetricUIDAO.java new file mode 100644 index 000000000..c5f27f97f --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/ServiceReferenceH2MetricUIDAO.java @@ -0,0 +1,57 @@ +/* + * 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.util.List; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceReferenceMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.table.MetricSource; +import org.apache.skywalking.apm.collector.storage.ui.common.Call; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; + +/** + * @author peng-yongsheng + */ +public class ServiceReferenceH2MetricUIDAO extends H2DAO implements IServiceReferenceMetricUIDAO { + + public ServiceReferenceH2MetricUIDAO(H2Client client) { + super(client); + } + + @Override public List getFrontServices(Step step, long startTime, long endTime, MetricSource metricSource, + int behindServiceId) { + return null; + } + + @Override public List getBehindServices(Step step, long startTime, long endTime, MetricSource metricSource, + int frontServiceId) { + return null; + } + + @Override public List getFrontServices(Step step, long startTime, long endTime, MetricSource metricSource, + List behindServiceIds) { + return null; + } + + @Override public List getBehindServices(Step step, long startTime, long endTime, MetricSource metricSource, + List frontServiceIds) { + return null; + } +} 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/java/org/apache/skywalking/apm/collector/storage/h2/define/appcomp/AbstractApplicationComponentH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/appcomp/AbstractApplicationComponentH2TableDefine.java index 570dcc7f7..2f0102c6b 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/appcomp/AbstractApplicationComponentH2TableDefine.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/appcomp/AbstractApplicationComponentH2TableDefine.java @@ -35,7 +35,7 @@ public abstract class AbstractApplicationComponentH2TableDefine extends H2TableD addColumn(new H2ColumnDefine(ApplicationComponentTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); addColumn(new H2ColumnDefine(ApplicationComponentTable.COLUMN_METRIC_ID, H2ColumnDefine.Type.Varchar.name())); addColumn(new H2ColumnDefine(ApplicationComponentTable.COLUMN_COMPONENT_ID, H2ColumnDefine.Type.Int.name())); - addColumn(new H2ColumnDefine(ApplicationComponentTable.COLUMN_PEER_ID, H2ColumnDefine.Type.Int.name())); + addColumn(new H2ColumnDefine(ApplicationComponentTable.COLUMN_APPLICATION_ID, H2ColumnDefine.Type.Int.name())); addColumn(new H2ColumnDefine(ApplicationComponentTable.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/appmapping/AbstractApplicationMappingH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/appmapping/AbstractApplicationMappingH2TableDefine.java index ee5239fb7..41ba8b8d5 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/appmapping/AbstractApplicationMappingH2TableDefine.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/appmapping/AbstractApplicationMappingH2TableDefine.java @@ -35,7 +35,7 @@ public abstract class AbstractApplicationMappingH2TableDefine extends H2TableDef addColumn(new H2ColumnDefine(ApplicationMappingTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); addColumn(new H2ColumnDefine(ApplicationMappingTable.COLUMN_METRIC_ID, H2ColumnDefine.Type.Varchar.name())); addColumn(new H2ColumnDefine(ApplicationMappingTable.COLUMN_APPLICATION_ID, H2ColumnDefine.Type.Int.name())); - addColumn(new H2ColumnDefine(ApplicationMappingTable.COLUMN_ADDRESS_ID, H2ColumnDefine.Type.Int.name())); + addColumn(new H2ColumnDefine(ApplicationMappingTable.COLUMN_MAPPING_APPLICATION_ID, H2ColumnDefine.Type.Int.name())); addColumn(new H2ColumnDefine(ApplicationMappingTable.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/register/ApplicationH2TableDefine.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/register/ApplicationH2TableDefine.java index 62ef7fd27..c4bd87319 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/register/ApplicationH2TableDefine.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/define/register/ApplicationH2TableDefine.java @@ -35,6 +35,7 @@ public class ApplicationH2TableDefine extends H2TableDefine { addColumn(new H2ColumnDefine(ApplicationTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name())); addColumn(new H2ColumnDefine(ApplicationTable.COLUMN_APPLICATION_CODE, H2ColumnDefine.Type.Varchar.name())); addColumn(new H2ColumnDefine(ApplicationTable.COLUMN_APPLICATION_ID, H2ColumnDefine.Type.Int.name())); + addColumn(new H2ColumnDefine(ApplicationTable.COLUMN_LAYER, H2ColumnDefine.Type.Int.name())); addColumn(new H2ColumnDefine(ApplicationTable.COLUMN_ADDRESS_ID, H2ColumnDefine.Type.Int.name())); addColumn(new H2ColumnDefine(ApplicationTable.COLUMN_IS_ADDRESS, H2ColumnDefine.Type.Int.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..fdb2fd844 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 @@ -80,10 +80,12 @@ org.apache.skywalking.apm.collector.storage.h2.define.alarm.ApplicationAlarmH2Ta org.apache.skywalking.apm.collector.storage.h2.define.alarm.ApplicationAlarmListH2TableDefine org.apache.skywalking.apm.collector.storage.h2.define.alarm.ApplicationReferenceAlarmH2TableDefine org.apache.skywalking.apm.collector.storage.h2.define.alarm.ApplicationReferenceAlarmListH2TableDefine + org.apache.skywalking.apm.collector.storage.h2.define.alarm.InstanceAlarmH2TableDefine org.apache.skywalking.apm.collector.storage.h2.define.alarm.InstanceAlarmListH2TableDefine org.apache.skywalking.apm.collector.storage.h2.define.alarm.InstanceReferenceAlarmH2TableDefine org.apache.skywalking.apm.collector.storage.h2.define.alarm.InstanceReferenceAlarmListH2TableDefine + org.apache.skywalking.apm.collector.storage.h2.define.alarm.ServiceAlarmH2TableDefine org.apache.skywalking.apm.collector.storage.h2.define.alarm.ServiceAlarmListH2TableDefine org.apache.skywalking.apm.collector.storage.h2.define.alarm.ServiceReferenceAlarmH2TableDefine diff --git a/apm-collector/apm-collector-ui/collector-ui-graphql/pom.xml b/apm-collector/apm-collector-ui/collector-ui-graphql/pom.xml new file mode 100644 index 000000000..7e82b5ad6 --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-graphql/pom.xml @@ -0,0 +1,45 @@ + + + + + + apm-collector-ui + org.apache.skywalking + 5.0.0-alpha + + 4.0.0 + + collector-ui-graphql + jar + + + + com.graphql-java + graphql-java-tools + 4.3.0 + + + org.apache.skywalking + apm-ui-protocol + ${project.version} + + + diff --git a/apm-collector/apm-collector-ui/collector-ui-graphql/src/main/java/org/apache/skywalking/apm/collector/ui/graphql/Mutation.java b/apm-collector/apm-collector-ui/collector-ui-graphql/src/main/java/org/apache/skywalking/apm/collector/ui/graphql/Mutation.java new file mode 100644 index 000000000..6967911aa --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-graphql/src/main/java/org/apache/skywalking/apm/collector/ui/graphql/Mutation.java @@ -0,0 +1,27 @@ +/* + * 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.graphql; + +import com.coxautodev.graphql.tools.GraphQLMutationResolver; + +/** + * @author peng-yongsheng + */ +public interface Mutation extends GraphQLMutationResolver { +} diff --git a/apm-collector/apm-collector-ui/collector-ui-graphql/src/main/java/org/apache/skywalking/apm/collector/ui/graphql/Query.java b/apm-collector/apm-collector-ui/collector-ui-graphql/src/main/java/org/apache/skywalking/apm/collector/ui/graphql/Query.java new file mode 100644 index 000000000..735089000 --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-graphql/src/main/java/org/apache/skywalking/apm/collector/ui/graphql/Query.java @@ -0,0 +1,27 @@ +/* + * 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.graphql; + +import com.coxautodev.graphql.tools.GraphQLQueryResolver; + +/** + * @author peng-yongsheng + */ +public interface Query extends GraphQLQueryResolver { +} diff --git a/apm-collector/apm-collector-ui/collector-ui-graphql/src/main/java/org/apache/skywalking/apm/collector/ui/graphql/VersionMutation.java b/apm-collector/apm-collector-ui/collector-ui-graphql/src/main/java/org/apache/skywalking/apm/collector/ui/graphql/VersionMutation.java new file mode 100644 index 000000000..3b4295c18 --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-graphql/src/main/java/org/apache/skywalking/apm/collector/ui/graphql/VersionMutation.java @@ -0,0 +1,26 @@ +/* + * 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.graphql; + +/** + * @author peng-yongsheng + */ +public class VersionMutation implements Mutation { + private String version; +} diff --git a/apm-collector/apm-collector-ui/collector-ui-graphql/src/main/java/org/apache/skywalking/apm/collector/ui/graphql/VersionQuery.java b/apm-collector/apm-collector-ui/collector-ui-graphql/src/main/java/org/apache/skywalking/apm/collector/ui/graphql/VersionQuery.java new file mode 100644 index 000000000..bba61bc8f --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-graphql/src/main/java/org/apache/skywalking/apm/collector/ui/graphql/VersionQuery.java @@ -0,0 +1,26 @@ +/* + * 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.graphql; + +/** + * @author peng-yongsheng + */ +public class VersionQuery implements Query { + private String version; +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/pom.xml b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/pom.xml index 83086aaa8..94469c388 100644 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/pom.xml +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/pom.xml @@ -36,6 +36,11 @@ collector-ui-define ${project.version} + + org.apache.skywalking + collector-ui-graphql + ${project.version} + org.apache.skywalking collector-cluster-define diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/UIModuleJettyProvider.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/UIModuleJettyProvider.java index 90bc5af2b..d01cda2b1 100644 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/UIModuleJettyProvider.java +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/UIModuleJettyProvider.java @@ -33,20 +33,9 @@ import org.apache.skywalking.apm.collector.naming.service.NamingHandlerRegisterS import org.apache.skywalking.apm.collector.server.Server; import org.apache.skywalking.apm.collector.storage.StorageModule; import org.apache.skywalking.apm.collector.ui.UIModule; -import org.apache.skywalking.apm.collector.ui.jetty.handler.SegmentTopGetHandler; -import org.apache.skywalking.apm.collector.ui.jetty.handler.SpanGetHandler; -import org.apache.skywalking.apm.collector.ui.jetty.handler.TraceDagGetHandler; -import org.apache.skywalking.apm.collector.ui.jetty.handler.TraceStackGetHandler; -import org.apache.skywalking.apm.collector.ui.jetty.handler.application.ApplicationsGetHandler; -import org.apache.skywalking.apm.collector.ui.jetty.handler.instancehealth.InstanceHealthGetHandler; -import org.apache.skywalking.apm.collector.ui.jetty.handler.instancemetric.InstanceMetricGetOneTimeBucketHandler; -import org.apache.skywalking.apm.collector.ui.jetty.handler.instancemetric.InstanceMetricGetRangeTimeBucketHandler; -import org.apache.skywalking.apm.collector.ui.jetty.handler.instancemetric.InstanceOsInfoGetHandler; +import org.apache.skywalking.apm.collector.ui.jetty.handler.GraphQLHandler; import org.apache.skywalking.apm.collector.ui.jetty.handler.naming.UIJettyNamingHandler; import org.apache.skywalking.apm.collector.ui.jetty.handler.naming.UIJettyNamingListener; -import org.apache.skywalking.apm.collector.ui.jetty.handler.servicetree.ServiceTreeGetByIdHandler; -import org.apache.skywalking.apm.collector.ui.jetty.handler.time.AllInstanceLastTimeGetHandler; -import org.apache.skywalking.apm.collector.ui.jetty.handler.time.OneInstanceLastTimeGetHandler; /** * @author peng-yongsheng @@ -98,17 +87,6 @@ public class UIModuleJettyProvider extends ModuleProvider { } private void addHandlers(Server jettyServer) { - jettyServer.addHandler(new ApplicationsGetHandler(getManager())); - jettyServer.addHandler(new InstanceHealthGetHandler(getManager())); - jettyServer.addHandler(new InstanceMetricGetOneTimeBucketHandler(getManager())); - jettyServer.addHandler(new InstanceMetricGetRangeTimeBucketHandler(getManager())); - jettyServer.addHandler(new InstanceOsInfoGetHandler(getManager())); - jettyServer.addHandler(new ServiceTreeGetByIdHandler(getManager())); - jettyServer.addHandler(new AllInstanceLastTimeGetHandler(getManager())); - jettyServer.addHandler(new OneInstanceLastTimeGetHandler(getManager())); - jettyServer.addHandler(new SegmentTopGetHandler(getManager())); - jettyServer.addHandler(new SpanGetHandler(getManager())); - jettyServer.addHandler(new TraceDagGetHandler(getManager())); - jettyServer.addHandler(new TraceStackGetHandler(getManager())); + jettyServer.addHandler(new GraphQLHandler(getManager())); } } diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/GraphQLHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/GraphQLHandler.java new file mode 100644 index 000000000..c845edd65 --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/GraphQLHandler.java @@ -0,0 +1,156 @@ +/* + * 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.jetty.handler; + +import com.coxautodev.graphql.tools.SchemaParser; +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.reflect.TypeToken; +import graphql.ExecutionInput; +import graphql.ExecutionResult; +import graphql.GraphQL; +import graphql.GraphQLError; +import graphql.schema.GraphQLSchema; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.lang.reflect.Type; +import java.util.List; +import java.util.Map; +import javax.servlet.http.HttpServletRequest; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.core.util.CollectionUtils; +import org.apache.skywalking.apm.collector.server.jetty.ArgumentsParseException; +import org.apache.skywalking.apm.collector.server.jetty.JettyHandler; +import org.apache.skywalking.apm.collector.storage.ui.application.ApplicationNode; +import org.apache.skywalking.apm.collector.storage.ui.application.ConjecturalNode; +import org.apache.skywalking.apm.collector.storage.ui.common.VisualUserNode; +import org.apache.skywalking.apm.collector.storage.ui.service.ServiceNode; +import org.apache.skywalking.apm.collector.ui.graphql.VersionMutation; +import org.apache.skywalking.apm.collector.ui.graphql.VersionQuery; +import org.apache.skywalking.apm.collector.ui.mutation.ConfigMutation; +import org.apache.skywalking.apm.collector.ui.query.AlarmQuery; +import org.apache.skywalking.apm.collector.ui.query.ApplicationQuery; +import org.apache.skywalking.apm.collector.ui.query.ConfigQuery; +import org.apache.skywalking.apm.collector.ui.query.OverViewLayerQuery; +import org.apache.skywalking.apm.collector.ui.query.ServerQuery; +import org.apache.skywalking.apm.collector.ui.query.ServiceQuery; +import org.apache.skywalking.apm.collector.ui.query.TraceQuery; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class GraphQLHandler extends JettyHandler { + + private final Logger logger = LoggerFactory.getLogger(GraphQLHandler.class); + + private final Gson gson = new Gson(); + private final GraphQL graphQL; + private static final String QUERY = "query"; + private static final String VARIABLES = "variables"; + private static final String DATA = "data"; + private static final String ERRORS = "errors"; + private static final String MESSAGE = "message"; + + public GraphQLHandler(ModuleManager moduleManager) { + GraphQLSchema schema = SchemaParser.newParser() + .file("ui-graphql/alarm.graphqls") + .file("ui-graphql/application-layer.graphqls") + .file("ui-graphql/common.graphqls") + .file("ui-graphql/config.graphqls") + .file("ui-graphql/overview-layer.graphqls") + .file("ui-graphql/server-layer.graphqls") + .file("ui-graphql/service-layer.graphqls") + .file("ui-graphql/trace.graphqls") + .resolvers(new VersionQuery(), new VersionMutation(), new AlarmQuery(), new ApplicationQuery(moduleManager)) + .resolvers(new OverViewLayerQuery(moduleManager), new ServerQuery(moduleManager), new ServiceQuery(moduleManager), new TraceQuery(moduleManager)) + .resolvers(new ConfigQuery(), new ConfigMutation()) + .dictionary(ConjecturalNode.class, VisualUserNode.class, ApplicationNode.class, ServiceNode.class) + .build() + .makeExecutableSchema(); + + this.graphQL = GraphQL.newGraphQL(schema).build(); + } + + @Override public String pathSpec() { + return "/graphql"; + } + + @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { + return execute(req.getParameter(QUERY), null); + } + + @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException, IOException { + BufferedReader reader = new BufferedReader(new InputStreamReader(req.getInputStream())); + String line; + String request = ""; + while ((line = reader.readLine()) != null) { + request += line; + } + + JsonObject requestJson = gson.fromJson(request, JsonObject.class); + + Type mapType = new TypeToken>() { }.getType(); + + return execute(requestJson.get(QUERY).getAsString(), gson.fromJson(requestJson.get(VARIABLES), mapType)); + } + + private JsonObject execute(String request, Map variables) { + try { + ExecutionInput executionInput = ExecutionInput.newExecutionInput().query(request).variables(variables).build(); + ExecutionResult executionResult = graphQL.execute(executionInput); + logger.info("Execution result is {}", executionResult); + Object data = executionResult.getData(); + List errors = executionResult.getErrors(); + + JsonObject jsonObject = new JsonObject(); + if (data != null) { + jsonObject.add(DATA, gson.fromJson(gson.toJson(data), JsonObject.class)); + } + + if (CollectionUtils.isNotEmpty(errors)) { + JsonArray errorArray = new JsonArray(); + errors.forEach(error -> { + JsonObject errorJson = new JsonObject(); + errorJson.addProperty(MESSAGE, error.getMessage()); + errorArray.add(errorJson); + }); + + jsonObject.add(ERRORS, errorArray); + } + + return jsonObject; + } catch (Throwable e) { + logger.error(e.getMessage(), e); + JsonObject jsonObject = new JsonObject(); + + JsonArray errorArray = new JsonArray(); + JsonObject errorJson = new JsonObject(); + errorJson.addProperty(MESSAGE, e.getMessage()); + errorArray.add(errorJson); + + jsonObject.add(ERRORS, errorArray); + return jsonObject; + } + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/SegmentTopGetHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/SegmentTopGetHandler.java deleted file mode 100644 index 4cdeaf384..000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/SegmentTopGetHandler.java +++ /dev/null @@ -1,141 +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.ui.jetty.handler; - -import com.google.gson.JsonElement; -import javax.servlet.http.HttpServletRequest; -import org.apache.skywalking.apm.collector.storage.dao.ISegmentCostUIDAO; -import org.apache.skywalking.apm.collector.core.module.ModuleManager; -import org.apache.skywalking.apm.collector.core.util.StringUtils; -import org.apache.skywalking.apm.collector.server.jetty.ArgumentsParseException; -import org.apache.skywalking.apm.collector.server.jetty.JettyHandler; -import org.apache.skywalking.apm.collector.ui.service.SegmentTopService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class SegmentTopGetHandler extends JettyHandler { - - private final Logger logger = LoggerFactory.getLogger(SegmentTopGetHandler.class); - - @Override public String pathSpec() { - return "/segment/top"; - } - - private final SegmentTopService service; - - public SegmentTopGetHandler(ModuleManager moduleManager) { - this.service = new SegmentTopService(moduleManager); - } - - @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { - if (!req.getParameterMap().containsKey("startTime") || !req.getParameterMap().containsKey("endTime") || !req.getParameterMap().containsKey("from") || !req.getParameterMap().containsKey("limit")) { - throw new ArgumentsParseException("the request parameter must contains startTime, endTime, from, limit"); - } - - if (logger.isDebugEnabled()) { - logger.debug("startTime: {}, endTime: {}, from: {}", req.getParameter("startTime"), req.getParameter("endTime"), req.getParameter("from")); - } - - long startTime; - try { - startTime = Long.valueOf(req.getParameter("startTime")); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("the request parameter startTime must be a long"); - } - - long endTime; - try { - endTime = Long.valueOf(req.getParameter("endTime")); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("the request parameter endTime must be a long"); - } - - int from; - try { - from = Integer.valueOf(req.getParameter("from")); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("the request parameter from must be an integer"); - } - - int limit; - try { - limit = Integer.valueOf(req.getParameter("limit")); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("the request parameter from must be an integer"); - } - - int minCost = -1; - if (req.getParameterMap().containsKey("minCost")) { - minCost = Integer.valueOf(req.getParameter("minCost")); - } - int maxCost = -1; - if (req.getParameterMap().containsKey("maxCost")) { - maxCost = Integer.valueOf(req.getParameter("maxCost")); - } - - String globalTraceId = null; - if (req.getParameterMap().containsKey("globalTraceId")) { - globalTraceId = req.getParameter("globalTraceId"); - } - - String operationName = null; - if (req.getParameterMap().containsKey("operationName")) { - operationName = req.getParameter("operationName"); - } - - int applicationId; - try { - applicationId = Integer.valueOf(req.getParameter("applicationId")); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("the request parameter applicationId must be a int"); - } - - ISegmentCostUIDAO.Error error; - String errorStr = req.getParameter("error"); - if (StringUtils.isNotEmpty(errorStr)) { - if ("true".equals(errorStr)) { - error = ISegmentCostUIDAO.Error.True; - } else if ("false".equals(errorStr)) { - error = ISegmentCostUIDAO.Error.False; - } else { - error = ISegmentCostUIDAO.Error.All; - } - } else { - error = ISegmentCostUIDAO.Error.All; - } - - ISegmentCostUIDAO.Sort sort = ISegmentCostUIDAO.Sort.Cost; - if (req.getParameterMap().containsKey("sort")) { - String sortStr = req.getParameter("sort"); - if (sortStr.toLowerCase().equals(ISegmentCostUIDAO.Sort.Time.name().toLowerCase())) { - sort = ISegmentCostUIDAO.Sort.Time; - } - } - - return service.loadTop(startTime, endTime, minCost, maxCost, operationName, globalTraceId, error, applicationId, limit, from, sort); - } - - @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { - throw new UnsupportedOperationException(); - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/SpanGetHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/SpanGetHandler.java deleted file mode 100644 index bb14254b5..000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/SpanGetHandler.java +++ /dev/null @@ -1,66 +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.ui.jetty.handler; - -import com.google.gson.JsonElement; -import javax.servlet.http.HttpServletRequest; -import org.apache.skywalking.apm.collector.core.module.ModuleManager; -import org.apache.skywalking.apm.collector.server.jetty.ArgumentsParseException; -import org.apache.skywalking.apm.collector.server.jetty.JettyHandler; -import org.apache.skywalking.apm.collector.ui.service.SpanService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class SpanGetHandler extends JettyHandler { - - private final Logger logger = LoggerFactory.getLogger(SpanGetHandler.class); - - @Override public String pathSpec() { - return "/span/spanId"; - } - - private final SpanService service; - - public SpanGetHandler(ModuleManager moduleManager) { - this.service = new SpanService(moduleManager); - } - - @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { - String segmentId = req.getParameter("segmentId"); - String spanIdStr = req.getParameter("spanId"); - logger.debug("segmentSpanId: {}, spanIdStr: {}", segmentId, spanIdStr); - - int spanId; - try { - spanId = Integer.parseInt(spanIdStr); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("span id must be integer"); - } - - return service.load(segmentId, spanId); - } - - @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { - throw new UnsupportedOperationException(); - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/TraceDagGetHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/TraceDagGetHandler.java deleted file mode 100644 index 34143ce3b..000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/TraceDagGetHandler.java +++ /dev/null @@ -1,77 +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.ui.jetty.handler; - -import com.google.gson.JsonElement; -import javax.servlet.http.HttpServletRequest; -import org.apache.skywalking.apm.collector.core.module.ModuleManager; -import org.apache.skywalking.apm.collector.server.jetty.ArgumentsParseException; -import org.apache.skywalking.apm.collector.server.jetty.JettyHandler; -import org.apache.skywalking.apm.collector.ui.service.TraceDagService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class TraceDagGetHandler extends JettyHandler { - - private final Logger logger = LoggerFactory.getLogger(TraceDagGetHandler.class); - - @Override public String pathSpec() { - return "/traceDag"; - } - - private final TraceDagService service; - - public TraceDagGetHandler(ModuleManager moduleManager) { - this.service = new TraceDagService(moduleManager); - } - - @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { - if (!req.getParameterMap().containsKey("startTime") || !req.getParameterMap().containsKey("endTime")) { - throw new ArgumentsParseException("the request parameter must contains startTime, endTime"); - } - - String startTimeStr = req.getParameter("startTime"); - String endTimeStr = req.getParameter("endTime"); - logger.debug("startTime: {}, endTimeStr: {}", startTimeStr, endTimeStr); - - long startTime; - try { - startTime = Long.valueOf(req.getParameter("startTime")); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("the request parameter startTime must be a long"); - } - - long endTime; - try { - endTime = Long.valueOf(req.getParameter("endTime")); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("the request parameter endTime must be a long"); - } - - return service.load(startTime, endTime); - } - - @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { - throw new UnsupportedOperationException(); - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/TraceStackGetHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/TraceStackGetHandler.java deleted file mode 100644 index 368348abd..000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/TraceStackGetHandler.java +++ /dev/null @@ -1,58 +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.ui.jetty.handler; - -import com.google.gson.JsonElement; -import javax.servlet.http.HttpServletRequest; -import org.apache.skywalking.apm.collector.core.module.ModuleManager; -import org.apache.skywalking.apm.collector.server.jetty.ArgumentsParseException; -import org.apache.skywalking.apm.collector.server.jetty.JettyHandler; -import org.apache.skywalking.apm.collector.ui.service.TraceStackService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class TraceStackGetHandler extends JettyHandler { - - private final Logger logger = LoggerFactory.getLogger(TraceStackGetHandler.class); - - @Override public String pathSpec() { - return "/traceStack/globalTraceId"; - } - - private final TraceStackService service; - - public TraceStackGetHandler(ModuleManager moduleManager) { - this.service = new TraceStackService(moduleManager); - } - - @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { - String globalTraceId = req.getParameter("globalTraceId"); - logger.debug("globalTraceId: {}", globalTraceId); - - return service.load(globalTraceId); - } - - @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { - throw new UnsupportedOperationException(); - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/application/ApplicationsGetHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/application/ApplicationsGetHandler.java deleted file mode 100644 index 51ddcc6ce..000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/application/ApplicationsGetHandler.java +++ /dev/null @@ -1,77 +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.ui.jetty.handler.application; - -import com.google.gson.JsonElement; -import javax.servlet.http.HttpServletRequest; -import org.apache.skywalking.apm.collector.ui.service.ApplicationService; -import org.apache.skywalking.apm.collector.core.module.ModuleManager; -import org.apache.skywalking.apm.collector.server.jetty.ArgumentsParseException; -import org.apache.skywalking.apm.collector.server.jetty.JettyHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class ApplicationsGetHandler extends JettyHandler { - - private final Logger logger = LoggerFactory.getLogger(ApplicationsGetHandler.class); - - @Override public String pathSpec() { - return "/applications"; - } - - private final ApplicationService applicationService; - - public ApplicationsGetHandler(ModuleManager moduleManager) { - this.applicationService = new ApplicationService(moduleManager); - } - - @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { - if (!req.getParameterMap().containsKey("startTime") || !req.getParameterMap().containsKey("endTime")) { - throw new ArgumentsParseException("must contains startTime. endTime parameter"); - } - - String startTimeStr = req.getParameter("startTime"); - String endTimeStr = req.getParameter("endTime"); - logger.debug("applications getApplicationIdByCode start time: {}, end time: {}", startTimeStr, endTimeStr); - - long startTime; - try { - startTime = Long.parseLong(startTimeStr); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("start time must be long"); - } - - long endTime; - try { - endTime = Long.parseLong(endTimeStr); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("end time must be long"); - } - - return applicationService.getApplications(startTime, endTime); - } - - @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { - throw new UnsupportedOperationException(); - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/instancehealth/InstanceHealthGetHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/instancehealth/InstanceHealthGetHandler.java deleted file mode 100644 index 008f4e143..000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/instancehealth/InstanceHealthGetHandler.java +++ /dev/null @@ -1,85 +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.ui.jetty.handler.instancehealth; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import javax.servlet.http.HttpServletRequest; -import org.apache.skywalking.apm.collector.core.module.ModuleManager; -import org.apache.skywalking.apm.collector.server.jetty.ArgumentsParseException; -import org.apache.skywalking.apm.collector.server.jetty.JettyHandler; -import org.apache.skywalking.apm.collector.ui.service.InstanceHealthService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class InstanceHealthGetHandler extends JettyHandler { - - private final Logger logger = LoggerFactory.getLogger(InstanceHealthGetHandler.class); - - @Override public String pathSpec() { - return "/instance/health/applicationId"; - } - - private final InstanceHealthService service; - - public InstanceHealthGetHandler(ModuleManager moduleManager) { - this.service = new InstanceHealthService(moduleManager); - } - - @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { - String timeBucketStr = req.getParameter("timeBucket"); - String[] applicationIdsStr = req.getParameterValues("applicationIds"); - logger.debug("instance health getApplicationIdByCode timeBucket: {}, applicationIdsStr: {}", timeBucketStr, applicationIdsStr); - - long timeBucket; - try { - timeBucket = Long.parseLong(timeBucketStr); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("timestamp must be long"); - } - - int[] applicationIds = new int[applicationIdsStr.length]; - for (int i = 0; i < applicationIdsStr.length; i++) { - try { - applicationIds[i] = Integer.parseInt(applicationIdsStr[i]); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("application id must be integer"); - } - } - - JsonObject response = new JsonObject(); - response.addProperty("timeBucket", timeBucket); - JsonArray appInstances = new JsonArray(); - response.add("appInstances", appInstances); - - for (int applicationId : applicationIds) { - appInstances.add(service.getInstances(timeBucket, applicationId)); - } - return response; - } - - @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { - throw new UnsupportedOperationException(); - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/instancemetric/InstanceMetricGetOneTimeBucketHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/instancemetric/InstanceMetricGetOneTimeBucketHandler.java deleted file mode 100644 index 15e73ce93..000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/instancemetric/InstanceMetricGetOneTimeBucketHandler.java +++ /dev/null @@ -1,86 +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.ui.jetty.handler.instancemetric; - -import com.google.gson.JsonElement; -import java.util.LinkedHashSet; -import java.util.Set; -import javax.servlet.http.HttpServletRequest; -import org.apache.skywalking.apm.collector.core.module.ModuleManager; -import org.apache.skywalking.apm.collector.server.jetty.ArgumentsParseException; -import org.apache.skywalking.apm.collector.server.jetty.JettyHandler; -import org.apache.skywalking.apm.collector.ui.service.InstanceJVMService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class InstanceMetricGetOneTimeBucketHandler extends JettyHandler { - - private final Logger logger = LoggerFactory.getLogger(InstanceMetricGetOneTimeBucketHandler.class); - - @Override public String pathSpec() { - return "/instance/jvm/instanceId/oneBucket"; - } - - private final InstanceJVMService service; - - public InstanceMetricGetOneTimeBucketHandler(ModuleManager moduleManager) { - this.service = new InstanceJVMService(moduleManager); - } - - @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { - String timeBucketStr = req.getParameter("timeBucket"); - String instanceIdStr = req.getParameter("instanceId"); - String[] metricTypes = req.getParameterValues("metricTypes"); - - logger.debug("instance jvm metric getApplicationIdByCode timeBucket: {}, instance id: {}, metric types: {}", timeBucketStr, instanceIdStr, metricTypes); - - long timeBucket; - try { - timeBucket = Long.parseLong(timeBucketStr); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("timeBucket must be long"); - } - - int instanceId; - try { - instanceId = Integer.parseInt(instanceIdStr); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("instance id must be integer"); - } - - if (metricTypes.length == 0) { - throw new ArgumentsParseException("at least one metric type"); - } - - Set metricTypeSet = new LinkedHashSet<>(); - for (String metricType : metricTypes) { - metricTypeSet.add(metricType); - } - - return service.getInstanceJvmMetric(instanceId, metricTypeSet, timeBucket); - } - - @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { - throw new UnsupportedOperationException(); - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/instancemetric/InstanceMetricGetRangeTimeBucketHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/instancemetric/InstanceMetricGetRangeTimeBucketHandler.java deleted file mode 100644 index a78c63dca..000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/instancemetric/InstanceMetricGetRangeTimeBucketHandler.java +++ /dev/null @@ -1,94 +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.ui.jetty.handler.instancemetric; - -import com.google.gson.JsonElement; -import java.util.LinkedHashSet; -import java.util.Set; -import javax.servlet.http.HttpServletRequest; -import org.apache.skywalking.apm.collector.core.module.ModuleManager; -import org.apache.skywalking.apm.collector.server.jetty.ArgumentsParseException; -import org.apache.skywalking.apm.collector.server.jetty.JettyHandler; -import org.apache.skywalking.apm.collector.ui.service.InstanceJVMService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class InstanceMetricGetRangeTimeBucketHandler extends JettyHandler { - - private final Logger logger = LoggerFactory.getLogger(InstanceMetricGetRangeTimeBucketHandler.class); - - @Override public String pathSpec() { - return "/instance/jvm/instanceId/rangeBucket"; - } - - private final InstanceJVMService service; - - public InstanceMetricGetRangeTimeBucketHandler(ModuleManager moduleManager) { - this.service = new InstanceJVMService(moduleManager); - } - - @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { - String startTimeBucketStr = req.getParameter("startTimeBucket"); - String endTimeBucketStr = req.getParameter("endTimeBucket"); - String instanceIdStr = req.getParameter("instanceId"); - String[] metricTypes = req.getParameterValues("metricTypes"); - - logger.debug("instance jvm metric getApplicationIdByCode start timeBucket: {}, end timeBucket:{} , instance id: {}, metric types: {}", startTimeBucketStr, endTimeBucketStr, instanceIdStr, metricTypes); - - long startTimeBucket; - try { - startTimeBucket = Long.parseLong(startTimeBucketStr); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("start timeBucket must be long"); - } - - long endTimeBucket; - try { - endTimeBucket = Long.parseLong(endTimeBucketStr); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("end timeBucket must be long"); - } - - int instanceId; - try { - instanceId = Integer.parseInt(instanceIdStr); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("instance id must be integer"); - } - - if (metricTypes.length == 0) { - throw new ArgumentsParseException("at least one metric type"); - } - - Set metricTypeSet = new LinkedHashSet<>(); - for (String metricType : metricTypes) { - metricTypeSet.add(metricType); - } - - return service.getInstanceJvmMetrics(instanceId, metricTypeSet, startTimeBucket, endTimeBucket); - } - - @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { - throw new UnsupportedOperationException(); - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/instancemetric/InstanceOsInfoGetHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/instancemetric/InstanceOsInfoGetHandler.java deleted file mode 100644 index 3b035f8eb..000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/instancemetric/InstanceOsInfoGetHandler.java +++ /dev/null @@ -1,65 +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.ui.jetty.handler.instancemetric; - -import com.google.gson.JsonElement; -import javax.servlet.http.HttpServletRequest; -import org.apache.skywalking.apm.collector.core.module.ModuleManager; -import org.apache.skywalking.apm.collector.server.jetty.ArgumentsParseException; -import org.apache.skywalking.apm.collector.server.jetty.JettyHandler; -import org.apache.skywalking.apm.collector.ui.service.InstanceJVMService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class InstanceOsInfoGetHandler extends JettyHandler { - - private final Logger logger = LoggerFactory.getLogger(InstanceOsInfoGetHandler.class); - - @Override public String pathSpec() { - return "/instance/os/instanceId"; - } - - private final InstanceJVMService service; - - public InstanceOsInfoGetHandler(ModuleManager moduleManager) { - this.service = new InstanceJVMService(moduleManager); - } - - @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { - String instanceIdStr = req.getParameter("instanceId"); - logger.debug("instance os info getApplicationIdByCode, instance id: {}", instanceIdStr); - - int instanceId; - try { - instanceId = Integer.parseInt(instanceIdStr); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("instance id must be integer"); - } - - return service.getInstanceOsInfo(instanceId); - } - - @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { - throw new UnsupportedOperationException(); - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/servicetree/ServiceTreeGetByIdHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/servicetree/ServiceTreeGetByIdHandler.java deleted file mode 100644 index 27ea8149f..000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/servicetree/ServiceTreeGetByIdHandler.java +++ /dev/null @@ -1,85 +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.ui.jetty.handler.servicetree; - -import com.google.gson.JsonElement; -import javax.servlet.http.HttpServletRequest; -import org.apache.skywalking.apm.collector.ui.service.ServiceTreeService; -import org.apache.skywalking.apm.collector.core.module.ModuleManager; -import org.apache.skywalking.apm.collector.server.jetty.ArgumentsParseException; -import org.apache.skywalking.apm.collector.server.jetty.JettyHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class ServiceTreeGetByIdHandler extends JettyHandler { - - private final Logger logger = LoggerFactory.getLogger(ServiceTreeGetByIdHandler.class); - - @Override public String pathSpec() { - return "/service/tree/entryServiceId"; - } - - private final ServiceTreeService service; - - public ServiceTreeGetByIdHandler(ModuleManager moduleManager) { - this.service = new ServiceTreeService(moduleManager); - } - - @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { - if (!req.getParameterMap().containsKey("entryServiceId") || !req.getParameterMap().containsKey("startTime") || !req.getParameterMap().containsKey("endTime")) { - throw new ArgumentsParseException("must contains parameters: entryServiceId, startTime, endTime"); - } - - String entryServiceIdStr = req.getParameter("entryServiceId"); - String startTimeStr = req.getParameter("startTime"); - String endTimeStr = req.getParameter("endTime"); - logger.debug("service entry getApplicationIdByCode entryServiceId: {}, startTime: {}, endTime: {}", entryServiceIdStr, startTimeStr, endTimeStr); - - int entryServiceId; - try { - entryServiceId = Integer.parseInt(entryServiceIdStr); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("entry service id must be integer"); - } - - long startTime; - try { - startTime = Long.parseLong(startTimeStr); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("start time must be long"); - } - - long endTime; - try { - endTime = Long.parseLong(endTimeStr); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("end time must be long"); - } - - return service.loadServiceTree(entryServiceId, startTime, endTime); - } - - @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { - throw new UnsupportedOperationException(); - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/time/AllInstanceLastTimeGetHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/time/AllInstanceLastTimeGetHandler.java deleted file mode 100644 index f0ea90d7a..000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/time/AllInstanceLastTimeGetHandler.java +++ /dev/null @@ -1,71 +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.ui.jetty.handler.time; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import java.util.Calendar; -import javax.servlet.http.HttpServletRequest; -import org.apache.skywalking.apm.collector.core.module.ModuleManager; -import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; -import org.apache.skywalking.apm.collector.server.jetty.ArgumentsParseException; -import org.apache.skywalking.apm.collector.server.jetty.JettyHandler; -import org.apache.skywalking.apm.collector.ui.service.TimeSynchronousService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class AllInstanceLastTimeGetHandler extends JettyHandler { - - private final Logger logger = LoggerFactory.getLogger(AllInstanceLastTimeGetHandler.class); - - @Override public String pathSpec() { - return "/time/allInstance"; - } - - private final TimeSynchronousService service; - - public AllInstanceLastTimeGetHandler(ModuleManager moduleManager) { - this.service = new TimeSynchronousService(moduleManager); - } - - @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { - Long timeBucket = service.allInstanceLastTime(); - logger.debug("all instance last time: {}", timeBucket); - - if (timeBucket == 0) { - timeBucket = TimeBucketUtils.INSTANCE.getSecondTimeBucket(System.currentTimeMillis()); - } - Calendar calendar = Calendar.getInstance(); - calendar.setTimeInMillis(TimeBucketUtils.INSTANCE.changeTimeBucket2TimeStamp(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket)); - calendar.add(Calendar.SECOND, -5); - timeBucket = calendar.getTimeInMillis(); - - JsonObject timeJson = new JsonObject(); - timeJson.addProperty("timeBucket", TimeBucketUtils.INSTANCE.getSecondTimeBucket(timeBucket)); - return timeJson; - } - - @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { - throw new UnsupportedOperationException(); - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/time/OneInstanceLastTimeGetHandler.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/time/OneInstanceLastTimeGetHandler.java deleted file mode 100644 index 89aaa7093..000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/jetty/handler/time/OneInstanceLastTimeGetHandler.java +++ /dev/null @@ -1,70 +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.ui.jetty.handler.time; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import javax.servlet.http.HttpServletRequest; -import org.apache.skywalking.apm.collector.core.module.ModuleManager; -import org.apache.skywalking.apm.collector.server.jetty.ArgumentsParseException; -import org.apache.skywalking.apm.collector.server.jetty.JettyHandler; -import org.apache.skywalking.apm.collector.ui.service.TimeSynchronousService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class OneInstanceLastTimeGetHandler extends JettyHandler { - - private final Logger logger = LoggerFactory.getLogger(OneInstanceLastTimeGetHandler.class); - - @Override public String pathSpec() { - return "/time/oneInstance"; - } - - private final TimeSynchronousService service; - - public OneInstanceLastTimeGetHandler(ModuleManager moduleManager) { - this.service = new TimeSynchronousService(moduleManager); - } - - @Override protected JsonElement doGet(HttpServletRequest req) throws ArgumentsParseException { - String instanceIdStr = req.getParameter("instanceId"); - logger.debug("instanceId: {}", instanceIdStr); - - int instanceId; - try { - instanceId = Integer.parseInt(instanceIdStr); - } catch (NumberFormatException e) { - throw new ArgumentsParseException("application instance id must be integer"); - } - - Long time = service.instanceLastTime(instanceId); - logger.debug("application instance id: {}, instance last time: {}", instanceId, time); - JsonObject timeJson = new JsonObject(); - timeJson.addProperty("timeBucket", time); - return timeJson; - } - - @Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException { - throw new UnsupportedOperationException(); - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/mutation/ConfigMutation.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/mutation/ConfigMutation.java new file mode 100644 index 000000000..ab2d80a09 --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/mutation/ConfigMutation.java @@ -0,0 +1,38 @@ +/* + * 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.mutation; + +import java.util.List; +import org.apache.skywalking.apm.collector.storage.ui.config.AlarmThreshold; +import org.apache.skywalking.apm.collector.storage.ui.config.TTLConfigItem; +import org.apache.skywalking.apm.collector.ui.graphql.Mutation; + +/** + * @author peng-yongsheng + */ +public class ConfigMutation implements Mutation { + + public Boolean setDataTTLConfigs(List ttl) { + return null; + } + + public Boolean setAlarmThreshold(List thresholds) { + return null; + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/AlarmQuery.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/AlarmQuery.java new file mode 100644 index 000000000..3b377d213 --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/AlarmQuery.java @@ -0,0 +1,40 @@ +/* + * 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.query; + +import org.apache.skywalking.apm.collector.ui.graphql.Query; +import org.apache.skywalking.apm.collector.storage.ui.alarm.Alarm; +import org.apache.skywalking.apm.collector.storage.ui.alarm.AlarmType; +import org.apache.skywalking.apm.collector.storage.ui.common.Duration; +import org.apache.skywalking.apm.collector.storage.ui.common.Pagination; + +import java.util.Collections; + +/** + * @author peng-yongsheng + */ +public class AlarmQuery implements Query { + + public Alarm loadAlarmList(String keyword, AlarmType alarmType, Duration duration, Pagination paging) { + Alarm alarm = new Alarm(); + alarm.setTotal(0); + alarm.setItems(Collections.emptyList()); + return alarm; + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/ApplicationQuery.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/ApplicationQuery.java new file mode 100644 index 000000000..121cdce78 --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/ApplicationQuery.java @@ -0,0 +1,86 @@ +/* + * 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.query; + +import java.text.ParseException; +import java.util.List; +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.application.Application; +import org.apache.skywalking.apm.collector.storage.ui.common.Duration; +import org.apache.skywalking.apm.collector.storage.ui.common.Topology; +import org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo; +import org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric; +import org.apache.skywalking.apm.collector.ui.graphql.Query; +import org.apache.skywalking.apm.collector.ui.service.ApplicationService; +import org.apache.skywalking.apm.collector.ui.service.ApplicationTopologyService; +import org.apache.skywalking.apm.collector.ui.utils.DurationUtils; + +/** + * @author peng-yongsheng + */ +public class ApplicationQuery implements Query { + + private final ModuleManager moduleManager; + private ApplicationService applicationService; + private ApplicationTopologyService applicationTopologyService; + + public ApplicationQuery(ModuleManager moduleManager) { + this.moduleManager = moduleManager; + } + + private ApplicationService getApplicationService() { + if (ObjectUtils.isEmpty(applicationService)) { + this.applicationService = new ApplicationService(moduleManager); + } + return applicationService; + } + + private ApplicationTopologyService getApplicationTopologyService() { + if (ObjectUtils.isEmpty(applicationTopologyService)) { + this.applicationTopologyService = new ApplicationTopologyService(moduleManager); + } + return applicationTopologyService; + } + + public List getAllApplication(Duration duration) throws ParseException { + long start = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getStart()); + long end = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getEnd()); + + return getApplicationService().getApplications(start, end); + } + + public Topology getApplicationTopology(int applicationId, Duration duration) throws ParseException { + long start = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart()); + long end = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd()); + + return getApplicationTopologyService().getApplicationTopology(duration.getStep(), applicationId, start, end); + } + + public List getSlowService(int applicationId, Duration duration, Integer top) throws ParseException { + long start = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart()); + long end = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd()); + + return getApplicationService().getSlowService(applicationId, duration.getStep(), start, end, top); + } + + public List getServerThroughput(int applicationId, Duration duration, Integer top) { + return null; + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/ConfigQuery.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/ConfigQuery.java new file mode 100644 index 000000000..ce1d8d31f --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/ConfigQuery.java @@ -0,0 +1,38 @@ +/* + * 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.query; + +import org.apache.skywalking.apm.collector.ui.graphql.Query; +import org.apache.skywalking.apm.collector.storage.ui.alarm.AlarmType; +import org.apache.skywalking.apm.collector.storage.ui.config.ExistedAlarmThresholds; +import org.apache.skywalking.apm.collector.storage.ui.config.ExistedTTLConfigs; + +/** + * @author peng-yongsheng + */ +public class ConfigQuery implements Query { + + public ExistedTTLConfigs queryAllDataTTLConfigs() { + return null; + } + + public ExistedAlarmThresholds queryAlarmThresholds(AlarmType alarmType) { + return null; + } +} 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 new file mode 100644 index 000000000..e424512dd --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/OverViewLayerQuery.java @@ -0,0 +1,145 @@ +/* + * 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.query; + +import java.text.ParseException; +import java.util.List; +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.common.Duration; +import org.apache.skywalking.apm.collector.storage.ui.common.Topology; +import org.apache.skywalking.apm.collector.storage.ui.overview.AlarmTrend; +import org.apache.skywalking.apm.collector.storage.ui.overview.ClusterBrief; +import org.apache.skywalking.apm.collector.storage.ui.overview.ConjecturalAppBrief; +import org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo; +import org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric; +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; +import org.apache.skywalking.apm.collector.ui.service.ServerService; +import org.apache.skywalking.apm.collector.ui.service.ServiceNameService; +import org.apache.skywalking.apm.collector.ui.utils.DurationUtils; + +/** + * @author peng-yongsheng + */ +public class OverViewLayerQuery implements Query { + + private final ModuleManager moduleManager; + private ClusterTopologyService clusterTopologyService; + private ApplicationService applicationService; + private NetworkAddressService networkAddressService; + private ServiceNameService serviceNameService; + private ServerService serverService; + private AlarmService alarmService; + + public OverViewLayerQuery(ModuleManager moduleManager) { + this.moduleManager = moduleManager; + } + + private ClusterTopologyService getClusterTopologyService() { + if (ObjectUtils.isEmpty(clusterTopologyService)) { + this.clusterTopologyService = new ClusterTopologyService(moduleManager); + } + return clusterTopologyService; + } + + private ApplicationService getApplicationService() { + if (ObjectUtils.isEmpty(applicationService)) { + this.applicationService = new ApplicationService(moduleManager); + } + return applicationService; + } + + private NetworkAddressService getNetworkAddressService() { + if (ObjectUtils.isEmpty(networkAddressService)) { + this.networkAddressService = new NetworkAddressService(moduleManager); + } + return networkAddressService; + } + + private ServiceNameService getServiceNameService() { + if (ObjectUtils.isEmpty(serviceNameService)) { + this.serviceNameService = new ServiceNameService(moduleManager); + } + return serviceNameService; + } + + private AlarmService getAlarmService() { + if (ObjectUtils.isEmpty(alarmService)) { + this.alarmService = new AlarmService(moduleManager); + } + return alarmService; + } + + private ServerService getServerService() { + if (ObjectUtils.isEmpty(serverService)) { + this.serverService = new ServerService(moduleManager); + } + return serverService; + } + + 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()); + + return getClusterTopologyService().getClusterTopology(duration.getStep(), start, end); + } + + public ClusterBrief getClusterBrief(Duration duration) throws ParseException { + long start = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getStart()); + long end = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getEnd()); + + ClusterBrief clusterBrief = new ClusterBrief(); + clusterBrief.setNumOfApplication(getApplicationService().getApplications(start, end).size()); + clusterBrief.setNumOfDatabase(getNetworkAddressService().getNumOfDatabase()); + clusterBrief.setNumOfCache(getNetworkAddressService().getNumOfCache()); + clusterBrief.setNumOfMQ(getNetworkAddressService().getNumOfMQ()); + clusterBrief.setNumOfService(getServiceNameService().getCount()); + return clusterBrief; + } + + 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) { + return null; + } + + public List getTopNSlowService(Duration duration, int topN) throws ParseException { + long start = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart()); + long end = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd()); + + return getServiceNameService().getSlowService(duration.getStep(), start, end, topN); + } + + public List getTopNServerThroughput(int applicationId, Duration duration, + int topN) throws ParseException { + long start = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart()); + long end = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd()); + + return getServerService().getTopNServerThroughput(applicationId, duration.getStep(), start, end, topN); + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/ServerQuery.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/ServerQuery.java new file mode 100644 index 000000000..23e9a60a7 --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/ServerQuery.java @@ -0,0 +1,96 @@ +/* + * 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.query; + +import java.text.ParseException; +import java.util.List; +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.common.Duration; +import org.apache.skywalking.apm.collector.storage.ui.common.ResponseTimeTrend; +import org.apache.skywalking.apm.collector.storage.ui.common.ThroughputTrend; +import org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo; +import org.apache.skywalking.apm.collector.storage.ui.server.CPUTrend; +import org.apache.skywalking.apm.collector.storage.ui.server.GCTrend; +import org.apache.skywalking.apm.collector.storage.ui.server.MemoryTrend; +import org.apache.skywalking.apm.collector.ui.graphql.Query; +import org.apache.skywalking.apm.collector.ui.service.ServerService; +import org.apache.skywalking.apm.collector.ui.utils.DurationUtils; + +/** + * @author peng-yongsheng + */ +public class ServerQuery implements Query { + + private final ModuleManager moduleManager; + private ServerService serverService; + + public ServerQuery(ModuleManager moduleManager) { + this.moduleManager = moduleManager; + } + + private ServerService getServerService() { + if (ObjectUtils.isEmpty(serverService)) { + this.serverService = new ServerService(moduleManager); + } + return serverService; + } + + public List searchServer(String keyword, Duration duration) throws ParseException { + long start = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getStart()); + long end = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getEnd()); + return getServerService().searchServer(keyword, start, end); + } + + public List getAllServer(int applicationId, Duration duration) throws ParseException { + long start = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getStart()); + long end = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getEnd()); + return getServerService().getAllServer(applicationId, start, end); + } + + public ResponseTimeTrend getServerResponseTimeTrend(int serverId, Duration duration) throws ParseException { + long start = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart()); + long end = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd()); + return getServerService().getServerResponseTimeTrend(serverId, duration.getStep(), start, end); + } + + public ThroughputTrend getServerTPSTrend(int serverId, Duration duration) throws ParseException { + long start = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart()); + long end = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd()); + return getServerService().getServerTPSTrend(serverId, duration.getStep(), start, end); + } + + public CPUTrend getCPUTrend(int serverId, Duration duration) throws ParseException { + long start = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart()); + long end = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd()); + return getServerService().getCPUTrend(serverId, duration.getStep(), start, end); + } + + public GCTrend getGCTrend(int serverId, Duration duration) throws ParseException { + long start = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart()); + long end = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd()); + return getServerService().getGCTrend(serverId, duration.getStep(), start, end); + } + + public MemoryTrend getMemoryTrend(int serverId, Duration duration) throws ParseException { + long start = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart()); + long end = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd()); + return getServerService().getMemoryTrend(serverId, duration.getStep(), start, end); + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/ServiceQuery.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/ServiceQuery.java new file mode 100644 index 000000000..d4051b035 --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/ServiceQuery.java @@ -0,0 +1,88 @@ +/* + * 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.query; + +import java.text.ParseException; +import java.util.List; +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.common.Duration; +import org.apache.skywalking.apm.collector.storage.ui.common.ResponseTimeTrend; +import org.apache.skywalking.apm.collector.storage.ui.common.SLATrend; +import org.apache.skywalking.apm.collector.storage.ui.common.ThroughputTrend; +import org.apache.skywalking.apm.collector.storage.ui.common.Topology; +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.ServiceNameService; +import org.apache.skywalking.apm.collector.ui.service.ServiceTopologyService; +import org.apache.skywalking.apm.collector.ui.utils.DurationUtils; + +/** + * @author peng-yongsheng + */ +public class ServiceQuery implements Query { + + private final ModuleManager moduleManager; + private ServiceNameService serviceNameService; + private ServiceTopologyService serviceTopologyService; + + public ServiceQuery(ModuleManager moduleManager) { + this.moduleManager = moduleManager; + } + + private ServiceNameService getServiceNameService() { + if (ObjectUtils.isEmpty(serviceNameService)) { + this.serviceNameService = new ServiceNameService(moduleManager); + } + return serviceNameService; + } + + private ServiceTopologyService getServiceTopologyService() { + if (ObjectUtils.isEmpty(serviceTopologyService)) { + this.serviceTopologyService = new ServiceTopologyService(moduleManager); + } + return serviceTopologyService; + } + + public List searchService(String keyword, int topN) throws ParseException { + return getServiceNameService().searchService(keyword, topN); + } + + public ResponseTimeTrend getServiceResponseTimeTrend(int serviceId, Duration duration) throws ParseException { + long start = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart()); + long end = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd()); + return getServiceNameService().getServiceResponseTimeTrend(serviceId, duration.getStep(), start, end); + } + + public ThroughputTrend getServiceTPSTrend(int serviceId, Duration duration) { + return null; + } + + public SLATrend getServiceSLATrend(int serviceId, Duration duration) throws ParseException { + long start = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart()); + long end = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd()); + return getServiceNameService().getServiceSLATrend(serviceId, duration.getStep(), start, end); + } + + public Topology getServiceTopology(int serviceId, Duration duration) throws ParseException { + long start = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart()); + long end = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd()); + return getServiceTopologyService().getServiceTopology(duration.getStep(), serviceId, start, end); + } +} 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 new file mode 100644 index 000000000..336824467 --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/TraceQuery.java @@ -0,0 +1,77 @@ +/* + * 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.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.service.TraceStackService; +import org.apache.skywalking.apm.collector.ui.utils.DurationUtils; + +/** + * @author peng-yongsheng + */ +public class TraceQuery implements Query { + + private final ModuleManager moduleManager; + private SegmentTopService segmentTopService; + private TraceStackService traceStackService; + + public TraceQuery(ModuleManager moduleManager) { + this.moduleManager = moduleManager; + } + + private SegmentTopService getSegmentTopService() { + if (ObjectUtils.isEmpty(segmentTopService)) { + this.segmentTopService = new SegmentTopService(moduleManager); + } + return segmentTopService; + } + + private TraceStackService getTraceStackService() { + if (ObjectUtils.isEmpty(traceStackService)) { + this.traceStackService = new TraceStackService(moduleManager); + } + return traceStackService; + } + + 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 getSegmentTopService().loadTop(start, end, minDuration, maxDuration, operationName, traceId, applicationId, limit, from); + } + + public Trace queryTrace(String traceId) { + return getTraceStackService().load(traceId); + } +} 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/ApplicationService.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ApplicationService.java index 1807fc321..42c094fe8 100644 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ApplicationService.java +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ApplicationService.java @@ -16,16 +16,21 @@ * */ - package org.apache.skywalking.apm.collector.ui.service; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; +import java.text.ParseException; +import java.util.List; import org.apache.skywalking.apm.collector.cache.CacheModule; import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService; +import org.apache.skywalking.apm.collector.cache.service.ServiceNameCacheService; 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.IInstanceUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.table.MetricSource; +import org.apache.skywalking.apm.collector.storage.ui.application.Application; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric; /** * @author peng-yongsheng @@ -33,22 +38,35 @@ import org.apache.skywalking.apm.collector.storage.dao.IInstanceUIDAO; public class ApplicationService { private final IInstanceUIDAO instanceDAO; + private final IServiceMetricUIDAO serviceMetricUIDAO; private final ApplicationCacheService applicationCacheService; + private final ServiceNameCacheService serviceNameCacheService; public ApplicationService(ModuleManager moduleManager) { this.instanceDAO = moduleManager.find(StorageModule.NAME).getService(IInstanceUIDAO.class); + this.serviceMetricUIDAO = moduleManager.find(StorageModule.NAME).getService(IServiceMetricUIDAO.class); this.applicationCacheService = moduleManager.find(CacheModule.NAME).getService(ApplicationCacheService.class); + this.serviceNameCacheService = moduleManager.find(CacheModule.NAME).getService(ServiceNameCacheService.class); } - public JsonArray getApplications(long startTime, long endTime) { - JsonArray applications = instanceDAO.getApplications(startTime, endTime); + public List getApplications(long startTime, long endTime, int... applicationIds) { + List applications = instanceDAO.getApplications(startTime, endTime, applicationIds); - applications.forEach(jsonElement -> { - JsonObject application = jsonElement.getAsJsonObject(); - int applicationId = application.get("applicationId").getAsInt(); - String applicationCode = applicationCacheService.getApplicationCodeById(applicationId); - application.addProperty("applicationCode", applicationCode); + applications.forEach(application -> { + String applicationCode = applicationCacheService.getApplicationById(application.getId()).getApplicationCode(); + application.setName(applicationCode); }); return applications; } + + public List getSlowService(int applicationId, Step step, long start, long end, + Integer top) throws ParseException { + List slowServices = serviceMetricUIDAO.getSlowService(applicationId, step, start, end, top, MetricSource.Callee); + slowServices.forEach(slowService -> { + slowService.setName(serviceNameCacheService.get(slowService.getId()).getServiceName()); + //TODO + slowService.setTps(1); + }); + return slowServices; + } } diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ApplicationTopologyService.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ApplicationTopologyService.java new file mode 100644 index 000000000..fea4e0bed --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ApplicationTopologyService.java @@ -0,0 +1,129 @@ +/* + * 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.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +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.ui.IApplicationComponentUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMappingUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationReferenceMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.table.MetricSource; +import org.apache.skywalking.apm.collector.storage.ui.common.Call; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.storage.ui.common.Topology; +import org.apache.skywalking.apm.collector.ui.utils.DurationUtils; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ApplicationTopologyService { + + private final Logger logger = LoggerFactory.getLogger(ApplicationTopologyService.class); + + private final IApplicationComponentUIDAO applicationComponentUIDAO; + private final IApplicationMappingUIDAO applicationMappingUIDAO; + private final IApplicationReferenceMetricUIDAO applicationReferenceMetricUIDAO; + private final ModuleManager moduleManager; + + public ApplicationTopologyService(ModuleManager moduleManager) { + this.moduleManager = moduleManager; + this.applicationComponentUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationComponentUIDAO.class); + this.applicationMappingUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationMappingUIDAO.class); + this.applicationReferenceMetricUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationReferenceMetricUIDAO.class); + } + + public Topology getApplicationTopology(Step step, int applicationId, long startTime, + long endTime) throws ParseException { + logger.debug("startTime: {}, endTime: {}", startTime, endTime); + List applicationComponents = applicationComponentUIDAO.load(step, startTime, endTime); + List applicationMappings = applicationMappingUIDAO.load(step, startTime, endTime); + + Map components = new HashMap<>(); + applicationComponents.forEach(component -> components.put(component.getApplicationId(), ComponentsDefine.getInstance().getComponentName(component.getComponentId()))); + + List callerCalls = applicationReferenceMetricUIDAO.getFrontApplications(step, applicationId, startTime, endTime, MetricSource.Caller); + callerCalls.addAll(applicationReferenceMetricUIDAO.getBehindApplications(step, applicationId, startTime, endTime, MetricSource.Caller)); + + callerCalls.forEach(callerCall -> callerCall.setCallType(components.get(callerCall.getTarget()))); + + List calleeCalls = applicationReferenceMetricUIDAO.getFrontApplications(step, applicationId, startTime, endTime, MetricSource.Callee); + calleeCalls.addAll(applicationReferenceMetricUIDAO.getBehindApplications(step, applicationId, startTime, endTime, MetricSource.Callee)); + + calleeCalls.forEach(calleeCall -> calleeCall.setCallType(components.get(calleeCall.getTarget()))); + + Set mappings = new HashSet<>(); + applicationMappings.forEach(mapping -> { + if (applicationId == mapping.getApplicationId()) { + mappings.add(mapping.getMappingApplicationId()); + } + }); + + mappings.forEach(mappingApplicationId -> { + List frontCallerApplications = applicationReferenceMetricUIDAO.getFrontApplications(step, mappingApplicationId, startTime, endTime, MetricSource.Caller); + frontCallerApplications.forEach(call -> { + call.setCallType(components.get(call.getTarget())); + call.setTarget(applicationId); + callerCalls.add(call); + }); + + List behindCallerApplications = applicationReferenceMetricUIDAO.getBehindApplications(step, mappingApplicationId, startTime, endTime, MetricSource.Caller); + behindCallerApplications.forEach(call -> { + call.setCallType(components.get(call.getTarget())); + call.setSource(applicationId); + callerCalls.add(call); + }); + + List frontCalleeApplications = applicationReferenceMetricUIDAO.getFrontApplications(step, mappingApplicationId, startTime, endTime, MetricSource.Callee); + frontCalleeApplications.forEach(call -> { + call.setCallType(components.get(call.getTarget())); + call.setTarget(applicationId); + calleeCalls.add(call); + }); + + List behindCalleeApplications = applicationReferenceMetricUIDAO.getBehindApplications(step, mappingApplicationId, startTime, endTime, MetricSource.Callee); + behindCalleeApplications.forEach(call -> { + call.setCallType(components.get(call.getTarget())); + call.setSource(applicationId); + calleeCalls.add(call); + }); + }); + + TopologyBuilder builder = new TopologyBuilder(moduleManager); + + long secondsBetween = DurationUtils.INSTANCE.secondsBetween(step, startTime, endTime); + Topology topology = builder.build(applicationComponents, applicationMappings, callerCalls, calleeCalls, secondsBetween); + + topology.getCalls().forEach(call -> { + long calls = call.getCalls(); + long responseTimes = call.getResponseTimes(); + call.setCallsPerSec(calls / secondsBetween); + call.setResponseTimePerSec(responseTimes / secondsBetween); + }); + return topology; + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ClusterTopologyService.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ClusterTopologyService.java new file mode 100644 index 000000000..da98adbfe --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ClusterTopologyService.java @@ -0,0 +1,86 @@ +/* + * 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.HashMap; +import java.util.List; +import java.util.Map; +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.ui.IApplicationComponentUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMappingUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationReferenceMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.table.MetricSource; +import org.apache.skywalking.apm.collector.storage.ui.common.Call; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.storage.ui.common.Topology; +import org.apache.skywalking.apm.collector.ui.utils.DurationUtils; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ClusterTopologyService { + + private final Logger logger = LoggerFactory.getLogger(ClusterTopologyService.class); + + private final IApplicationComponentUIDAO applicationComponentUIDAO; + private final IApplicationMappingUIDAO applicationMappingUIDAO; + private final IApplicationReferenceMetricUIDAO applicationReferenceMetricUIDAO; + private final ModuleManager moduleManager; + + public ClusterTopologyService(ModuleManager moduleManager) { + this.moduleManager = moduleManager; + this.applicationComponentUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationComponentUIDAO.class); + this.applicationMappingUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationMappingUIDAO.class); + this.applicationReferenceMetricUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationReferenceMetricUIDAO.class); + } + + public Topology getClusterTopology(Step step, long startTime, long endTime) throws ParseException { + logger.debug("startTime: {}, endTime: {}", startTime, endTime); + List applicationComponents = applicationComponentUIDAO.load(step, startTime, endTime); + List applicationMappings = applicationMappingUIDAO.load(step, startTime, endTime); + + Map components = new HashMap<>(); + applicationComponents.forEach(component -> components.put(component.getApplicationId(), ComponentsDefine.getInstance().getComponentName(component.getComponentId()))); + + List callerCalls = applicationReferenceMetricUIDAO.getApplications(step, startTime, endTime, MetricSource.Caller); + callerCalls.forEach(callerCall -> callerCall.setCallType(components.get(callerCall.getTarget()))); + + List calleeCalls = applicationReferenceMetricUIDAO.getApplications(step, startTime, endTime, MetricSource.Callee); + + calleeCalls.forEach(calleeCall -> calleeCall.setCallType(components.get(calleeCall.getTarget()))); + + TopologyBuilder builder = new TopologyBuilder(moduleManager); + + long secondsBetween = DurationUtils.INSTANCE.secondsBetween(step, startTime, endTime); + Topology topology = builder.build(applicationComponents, applicationMappings, callerCalls, calleeCalls, secondsBetween); + + topology.getCalls().forEach(call -> { + long calls = call.getCalls(); + long responseTimes = call.getResponseTimes(); + call.setCallsPerSec(calls / secondsBetween); + call.setResponseTimePerSec(responseTimes / secondsBetween); + }); + return topology; + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/InstanceHealthService.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/InstanceHealthService.java index 65492c8b1..5b1048b4c 100644 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/InstanceHealthService.java +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/InstanceHealthService.java @@ -16,21 +16,17 @@ * */ - package org.apache.skywalking.apm.collector.ui.service; import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import java.util.List; import org.apache.skywalking.apm.collector.cache.CacheModule; -import org.apache.skywalking.apm.collector.core.module.ModuleManager; -import org.apache.skywalking.apm.collector.storage.dao.IGCMetricUIDAO; -import org.apache.skywalking.apm.collector.storage.table.register.Instance; import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService; -import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +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.IInstanceMetricUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.IInstanceUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IGCMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceUIDAO; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,58 +52,58 @@ public class InstanceHealthService { public JsonObject getInstances(long timeBucket, int applicationId) { JsonObject response = new JsonObject(); - long[] timeBuckets = TimeBucketUtils.INSTANCE.getFiveSecondTimeBuckets(timeBucket); - long halfHourBeforeTimeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket, -60 * 30); - List instanceList = instanceDAO.getInstances(applicationId, halfHourBeforeTimeBucket); +// long[] timeBuckets = TimeBucketUtils.INSTANCE.getFiveSecondTimeBuckets(timeBucket); +// long halfHourBeforeTimeBucket = TimeBucketUtils.INSTANCE.addSecondForSecondTimeBucket(TimeBucketUtils.TimeBucketType.SECOND, timeBucket, -60 * 30); +// List instanceList = instanceDAO.getInstances(applicationId, halfHourBeforeTimeBucket); JsonArray instances = new JsonArray(); response.add("instances", instances); - instanceList.forEach(instance -> { - response.addProperty("applicationCode", applicationCacheService.getApplicationCodeById(applicationId)); - response.addProperty("applicationId", applicationId); +// instanceList.forEach(instance -> { +// response.addProperty("applicationCode", applicationCacheService.getApplicationById(applicationId)); +// response.addProperty("applicationId", applicationId); +// +// IInstanceMetricUIDAO.InstanceMetric performance = instanceMetricUIDAO.get(timeBuckets, instance.getInstanceId()); +// +// JsonObject instanceJson = new JsonObject(); +// instanceJson.addProperty("id", instance.getInstanceId()); +// if (performance != null) { +// instanceJson.addProperty("tps", performance.getCalls()); +// } else { +// instanceJson.addProperty("tps", 0); +// } +// +// int avg = 0; +// if (performance != null && performance.getCalls() != 0) { +// avg = (int)(performance.getDurationSum() / performance.getCalls()); +// } +// instanceJson.addProperty("avg", avg); +// +// if (avg > 5000) { +// instanceJson.addProperty("healthLevel", 0); +// } else if (avg > 3000 && avg <= 5000) { +// instanceJson.addProperty("healthLevel", 1); +// } else if (avg > 1000 && avg <= 3000) { +// instanceJson.addProperty("healthLevel", 2); +// } else { +// instanceJson.addProperty("healthLevel", 3); +// } - IInstanceMetricUIDAO.InstanceMetric performance = instanceMetricUIDAO.get(timeBuckets, instance.getInstanceId()); - - JsonObject instanceJson = new JsonObject(); - instanceJson.addProperty("id", instance.getInstanceId()); - if (performance != null) { - instanceJson.addProperty("tps", performance.getCalls()); - } else { - instanceJson.addProperty("tps", 0); - } - - int avg = 0; - if (performance != null && performance.getCalls() != 0) { - avg = (int)(performance.getDurationSum() / performance.getCalls()); - } - instanceJson.addProperty("avg", avg); - - if (avg > 5000) { - instanceJson.addProperty("healthLevel", 0); - } else if (avg > 3000 && avg <= 5000) { - instanceJson.addProperty("healthLevel", 1); - } else if (avg > 1000 && avg <= 3000) { - instanceJson.addProperty("healthLevel", 2); - } else { - instanceJson.addProperty("healthLevel", 3); - } - - long heartBeatTime = TimeBucketUtils.INSTANCE.changeTimeBucket2TimeStamp(TimeBucketUtils.TimeBucketType.SECOND.name(), instance.getHeartBeatTime()); - long currentTime = TimeBucketUtils.INSTANCE.changeTimeBucket2TimeStamp(TimeBucketUtils.TimeBucketType.SECOND.name(), timeBucket); - - if (currentTime - heartBeatTime < 1000 * 60 * 2) { - instanceJson.addProperty("status", 0); - } else { - instanceJson.addProperty("status", 1); - } - - IGCMetricUIDAO.GCCount gcCount = gcMetricDAO.getGCCount(timeBuckets, instance.getInstanceId()); - instanceJson.addProperty("ygc", gcCount.getYoung()); - instanceJson.addProperty("ogc", gcCount.getOld()); - - instances.add(instanceJson); - }); +// long heartBeatTime = TimeBucketUtils.INSTANCE.changeTimeBucket2TimeStamp(TimeBucketUtils.TimeBucketType.SECOND, instance.getHeartBeatTime()); +// long currentTime = TimeBucketUtils.INSTANCE.changeTimeBucket2TimeStamp(TimeBucketUtils.TimeBucketType.SECOND, timeBucket); +// +// if (currentTime - heartBeatTime < 1000 * 60 * 2) { +// instanceJson.addProperty("status", 0); +// } else { +// instanceJson.addProperty("status", 1); +// } +// +// IGCMetricUIDAO.GCCount gcCount = gcMetricDAO.getGCCount(timeBuckets, instance.getInstanceId()); +// instanceJson.addProperty("ygc", gcCount.getYoung()); +// instanceJson.addProperty("ogc", gcCount.getOld()); +// +// instances.add(instanceJson); +// }); return response; } diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/InstanceJVMService.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/InstanceJVMService.java index bf14afd97..61af75d2e 100644 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/InstanceJVMService.java +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/InstanceJVMService.java @@ -16,7 +16,6 @@ * */ - package org.apache.skywalking.apm.collector.ui.service; import com.google.gson.Gson; @@ -25,14 +24,14 @@ import java.util.Set; import org.apache.skywalking.apm.collector.core.UnexpectedException; 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.dao.ICpuMetricUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.IGCMetricUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.IMemoryMetricUIDAO; -import org.apache.skywalking.apm.collector.storage.table.register.Instance; import org.apache.skywalking.apm.collector.storage.StorageModule; -import org.apache.skywalking.apm.collector.storage.dao.IInstanceMetricUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.IInstanceUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.IMemoryPoolMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.ICpuMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IGCMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceMetricUIDAO; +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.table.register.Instance; import org.apache.skywalking.apm.network.proto.PoolType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -75,17 +74,11 @@ public class InstanceJVMService { JsonObject metrics = new JsonObject(); for (String metricType : metricTypes) { if (metricType.toLowerCase().equals(MetricType.cpu.name())) { - metrics.addProperty(MetricType.cpu.name(), cpuMetricDAO.getMetric(instanceId, timeBucket)); } else if (metricType.toLowerCase().equals(MetricType.gc.name())) { - metrics.add(MetricType.gc.name(), gcMetricDAO.getMetric(instanceId, timeBucket)); } else if (metricType.toLowerCase().equals(MetricType.tps.name())) { - metrics.addProperty(MetricType.tps.name(), instanceMetricUIDAO.getTpsMetric(instanceId, timeBucket)); } else if (metricType.toLowerCase().equals(MetricType.resptime.name())) { - metrics.addProperty(MetricType.resptime.name(), instanceMetricUIDAO.getRespTimeMetric(instanceId, timeBucket)); } else if (metricType.toLowerCase().equals(MetricType.heapmemory.name())) { - metrics.add(MetricType.heapmemory.name(), memoryMetricDAO.getMetric(instanceId, timeBucket, true)); } else if (metricType.toLowerCase().equals(MetricType.nonheapmemory.name())) { - metrics.add(MetricType.nonheapmemory.name(), memoryMetricDAO.getMetric(instanceId, timeBucket, false)); } else if (metricType.toLowerCase().equals(MetricType.permgen.name())) { metrics.add(MetricType.permgen.name(), memoryPoolMetricDAO.getMetric(instanceId, timeBucket, PoolType.PERMGEN_USAGE_VALUE)); } else if (metricType.toLowerCase().equals(MetricType.metaspace.name())) { @@ -108,17 +101,11 @@ public class InstanceJVMService { JsonObject metrics = new JsonObject(); for (String metricType : metricTypes) { if (metricType.toLowerCase().equals(MetricType.cpu.name())) { - metrics.add(MetricType.cpu.name(), cpuMetricDAO.getMetric(instanceId, startTimeBucket, endTimeBucket)); } else if (metricType.toLowerCase().equals(MetricType.gc.name())) { - metrics.add(MetricType.gc.name(), gcMetricDAO.getMetric(instanceId, startTimeBucket, endTimeBucket)); } else if (metricType.toLowerCase().equals(MetricType.tps.name())) { - metrics.add(MetricType.tps.name(), instanceMetricUIDAO.getTpsMetric(instanceId, startTimeBucket, endTimeBucket)); } else if (metricType.toLowerCase().equals(MetricType.resptime.name())) { - metrics.add(MetricType.resptime.name(), instanceMetricUIDAO.getRespTimeMetric(instanceId, startTimeBucket, endTimeBucket)); } else if (metricType.toLowerCase().equals(MetricType.heapmemory.name())) { - metrics.add(MetricType.heapmemory.name(), memoryMetricDAO.getMetric(instanceId, startTimeBucket, endTimeBucket, true)); } else if (metricType.toLowerCase().equals(MetricType.nonheapmemory.name())) { - metrics.add(MetricType.nonheapmemory.name(), memoryMetricDAO.getMetric(instanceId, startTimeBucket, endTimeBucket, false)); } else if (metricType.toLowerCase().equals(MetricType.permgen.name())) { metrics.add(MetricType.permgen.name(), memoryPoolMetricDAO.getMetric(instanceId, startTimeBucket, endTimeBucket, PoolType.PERMGEN_USAGE_VALUE)); } else if (metricType.toLowerCase().equals(MetricType.metaspace.name())) { diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/NetworkAddressService.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/NetworkAddressService.java new file mode 100644 index 000000000..ed7045365 --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/NetworkAddressService.java @@ -0,0 +1,48 @@ +/* + * 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 org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.storage.dao.ui.INetworkAddressUIDAO; +import org.apache.skywalking.apm.network.proto.SpanLayer; + +/** + * @author peng-yongsheng + */ +public class NetworkAddressService { + + private final INetworkAddressUIDAO networkAddressUIDAO; + + public NetworkAddressService(ModuleManager moduleManager) { + this.networkAddressUIDAO = moduleManager.find(StorageModule.NAME).getService(INetworkAddressUIDAO.class); + } + + public int getNumOfDatabase() { + return networkAddressUIDAO.getNumOfSpanLayer(SpanLayer.Database_VALUE); + } + + public int getNumOfCache() { + return networkAddressUIDAO.getNumOfSpanLayer(SpanLayer.Cache_VALUE); + } + + public int getNumOfMQ() { + return networkAddressUIDAO.getNumOfSpanLayer(SpanLayer.MQ_VALUE); + } +} 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 7497b3de9..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.IGlobalTraceUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.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-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ServerService.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ServerService.java new file mode 100644 index 000000000..12a27420d --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ServerService.java @@ -0,0 +1,181 @@ +/* + * 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 com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import java.text.ParseException; +import java.util.LinkedList; +import java.util.List; +import org.apache.skywalking.apm.collector.cache.CacheModule; +import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService; +import org.apache.skywalking.apm.collector.cache.service.InstanceCacheService; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.core.util.StringUtils; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.storage.dao.ui.ICpuMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IGCMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceMetricUIDAO; +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.table.MetricSource; +import org.apache.skywalking.apm.collector.storage.table.register.Instance; +import org.apache.skywalking.apm.collector.storage.ui.common.ResponseTimeTrend; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.storage.ui.common.ThroughputTrend; +import org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo; +import org.apache.skywalking.apm.collector.storage.ui.server.CPUTrend; +import org.apache.skywalking.apm.collector.storage.ui.server.GCTrend; +import org.apache.skywalking.apm.collector.storage.ui.server.MemoryTrend; +import org.apache.skywalking.apm.collector.storage.utils.DurationPoint; +import org.apache.skywalking.apm.collector.ui.utils.DurationUtils; + +/** + * @author peng-yongsheng + */ +public class ServerService { + + private final Gson gson = new Gson(); + private final IInstanceUIDAO instanceUIDAO; + private final IInstanceMetricUIDAO instanceMetricUIDAO; + private final ICpuMetricUIDAO cpuMetricUIDAO; + private final IGCMetricUIDAO gcMetricUIDAO; + private final IMemoryMetricUIDAO memoryMetricUIDAO; + private final InstanceCacheService instanceCacheService; + private final ApplicationCacheService applicationCacheService; + + public ServerService(ModuleManager moduleManager) { + this.instanceUIDAO = moduleManager.find(StorageModule.NAME).getService(IInstanceUIDAO.class); + this.instanceMetricUIDAO = moduleManager.find(StorageModule.NAME).getService(IInstanceMetricUIDAO.class); + this.cpuMetricUIDAO = moduleManager.find(StorageModule.NAME).getService(ICpuMetricUIDAO.class); + this.gcMetricUIDAO = moduleManager.find(StorageModule.NAME).getService(IGCMetricUIDAO.class); + this.memoryMetricUIDAO = moduleManager.find(StorageModule.NAME).getService(IMemoryMetricUIDAO.class); + this.instanceCacheService = moduleManager.find(CacheModule.NAME).getService(InstanceCacheService.class); + this.applicationCacheService = moduleManager.find(CacheModule.NAME).getService(ApplicationCacheService.class); + } + + public List getTopNServerThroughput(int applicationId, Step step, long start, long end, int topN) { + //TODO + List appServerInfos = instanceMetricUIDAO.getTopNServerThroughput(applicationId, step, start, end, 1000, topN, MetricSource.Callee); + appServerInfos.forEach(appServerInfo -> { + Instance instance = instanceUIDAO.getInstance(appServerInfo.getId()); + appServerInfo.setOsInfo(instance.getOsInfo()); + }); + buildAppServerInfo(appServerInfos); + + return appServerInfos; + } + + public List searchServer(String keyword, long start, long end) { + List serverInfos = instanceUIDAO.searchServer(keyword, start, end); + serverInfos.forEach(serverInfo -> { + if (serverInfo.getId() == Const.NONE_INSTANCE_ID) { + serverInfos.remove(serverInfo); + } + }); + + buildAppServerInfo(serverInfos); + return serverInfos; + } + + public List getAllServer(int applicationId, long start, long end) { + List serverInfos = instanceUIDAO.getAllServer(applicationId, start, end); + buildAppServerInfo(serverInfos); + return serverInfos; + } + + public ResponseTimeTrend getServerResponseTimeTrend(int instanceId, Step step, long start, + long end) throws ParseException { + ResponseTimeTrend responseTimeTrend = new ResponseTimeTrend(); + List durationPoints = DurationUtils.INSTANCE.getDurationPoints(step, start, end); + List trends = instanceMetricUIDAO.getResponseTimeTrend(instanceId, step, durationPoints); + responseTimeTrend.setTrendList(trends); + return responseTimeTrend; + } + + public ThroughputTrend getServerTPSTrend(int instanceId, Step step, long start, long end) throws ParseException { + ThroughputTrend throughputTrend = new ThroughputTrend(); + List durationPoints = DurationUtils.INSTANCE.getDurationPoints(step, start, end); + List trends = instanceMetricUIDAO.getServerTPSTrend(instanceId, step, durationPoints); + throughputTrend.setTrendList(trends); + return throughputTrend; + } + + public CPUTrend getCPUTrend(int instanceId, Step step, long start, long end) throws ParseException { + CPUTrend cpuTrend = new CPUTrend(); + List durationPoints = DurationUtils.INSTANCE.getDurationPoints(step, start, end); + List trends = cpuMetricUIDAO.getCPUTrend(instanceId, step, durationPoints); + cpuTrend.setCost(trends); + return cpuTrend; + } + + public GCTrend getGCTrend(int instanceId, Step step, long start, long end) throws ParseException { + GCTrend gcTrend = new GCTrend(); + List durationPoints = DurationUtils.INSTANCE.getDurationPoints(step, start, end); + List youngGCTrend = gcMetricUIDAO.getYoungGCTrend(instanceId, step, durationPoints); + gcTrend.setYoungGC(youngGCTrend); + List oldGCTrend = gcMetricUIDAO.getOldGCTrend(instanceId, step, durationPoints); + gcTrend.setOldGC(oldGCTrend); + return gcTrend; + } + + public MemoryTrend getMemoryTrend(int instanceId, Step step, long start, long end) throws ParseException { + MemoryTrend memoryTrend = new MemoryTrend(); + List durationPoints = DurationUtils.INSTANCE.getDurationPoints(step, start, end); + IMemoryMetricUIDAO.Trend heapMemoryTrend = memoryMetricUIDAO.getHeapMemoryTrend(instanceId, step, durationPoints); + memoryTrend.setHeap(heapMemoryTrend.getMetrics()); + memoryTrend.setMaxHeap(heapMemoryTrend.getMaxMetrics()); + + IMemoryMetricUIDAO.Trend noHeapMemoryTrend = memoryMetricUIDAO.getNoHeapMemoryTrend(instanceId, step, durationPoints); + memoryTrend.setNoheap(noHeapMemoryTrend.getMetrics()); + memoryTrend.setMaxNoheap(noHeapMemoryTrend.getMaxMetrics()); + + return memoryTrend; + } + + private void buildAppServerInfo(List serverInfos) { + serverInfos.forEach(serverInfo -> { + int applicationId = instanceCacheService.getApplicationId(serverInfo.getId()); + serverInfo.setApplicationId(applicationId); + serverInfo.setApplicationCode(applicationCacheService.getApplicationById(applicationId).getApplicationCode()); + if (StringUtils.isNotEmpty(serverInfo.getOsInfo())) { + JsonObject osInfoJson = gson.fromJson(serverInfo.getOsInfo(), JsonObject.class); + if (osInfoJson.has("osName")) { + serverInfo.setName(osInfoJson.get("osName").getAsString()); + } + if (osInfoJson.has("hostName")) { + serverInfo.setHost(osInfoJson.get("hostName").getAsString()); + } + if (osInfoJson.has("processId")) { + serverInfo.setPid(osInfoJson.get("processId").getAsInt()); + } + + if (osInfoJson.has("ipv4s")) { + JsonArray ipv4Array = osInfoJson.get("ipv4s").getAsJsonArray(); + + List ipv4s = new LinkedList<>(); + ipv4Array.forEach(ipv4 -> ipv4s.add(ipv4.getAsString())); + serverInfo.setIpv4(ipv4s); + } + } + }); + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ServiceNameService.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ServiceNameService.java new file mode 100644 index 000000000..2342deb3b --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ServiceNameService.java @@ -0,0 +1,86 @@ +/* + * 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.cache.CacheModule; +import org.apache.skywalking.apm.collector.cache.service.ServiceNameCacheService; +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.ui.IServiceMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceNameServiceUIDAO; +import org.apache.skywalking.apm.collector.storage.table.MetricSource; +import org.apache.skywalking.apm.collector.storage.ui.common.ResponseTimeTrend; +import org.apache.skywalking.apm.collector.storage.ui.common.SLATrend; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.storage.ui.service.ServiceInfo; +import org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric; +import org.apache.skywalking.apm.collector.storage.utils.DurationPoint; +import org.apache.skywalking.apm.collector.ui.utils.DurationUtils; + +/** + * @author peng-yongsheng + */ +public class ServiceNameService { + + private final IServiceNameServiceUIDAO serviceNameServiceUIDAO; + private final IServiceMetricUIDAO serviceMetricUIDAO; + private final ServiceNameCacheService serviceNameCacheService; + + public ServiceNameService(ModuleManager moduleManager) { + this.serviceNameServiceUIDAO = moduleManager.find(StorageModule.NAME).getService(IServiceNameServiceUIDAO.class); + this.serviceMetricUIDAO = moduleManager.find(StorageModule.NAME).getService(IServiceMetricUIDAO.class); + this.serviceNameCacheService = moduleManager.find(CacheModule.NAME).getService(ServiceNameCacheService.class); + } + + public int getCount() { + return serviceNameServiceUIDAO.getCount(); + } + + public List searchService(String keyword, int topN) { + return serviceNameServiceUIDAO.searchService(keyword, topN); + } + + public ResponseTimeTrend getServiceResponseTimeTrend(int serviceId, Step step, long start, + long end) throws ParseException { + ResponseTimeTrend responseTimeTrend = new ResponseTimeTrend(); + List durationPoints = DurationUtils.INSTANCE.getDurationPoints(step, start, end); + responseTimeTrend.setTrendList(serviceMetricUIDAO.getServiceResponseTimeTrend(serviceId, step, durationPoints)); + return responseTimeTrend; + } + + public SLATrend getServiceSLATrend(int serviceId, Step step, long start, long end) throws ParseException { + SLATrend slaTrend = new SLATrend(); + List durationPoints = DurationUtils.INSTANCE.getDurationPoints(step, start, end); + slaTrend.setTrendList(serviceMetricUIDAO.getServiceSLATrend(serviceId, step, durationPoints)); + return slaTrend; + } + + public List getSlowService(Step step, long start, long end, + Integer top) throws ParseException { + List slowServices = serviceMetricUIDAO.getSlowService(0, step, start, end, top, MetricSource.Callee); + slowServices.forEach(slowService -> { + slowService.setName(serviceNameCacheService.get(slowService.getId()).getServiceName()); + //TODO + slowService.setTps(1); + }); + return slowServices; + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ServiceTopologyService.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ServiceTopologyService.java new file mode 100644 index 000000000..5ce4340be --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ServiceTopologyService.java @@ -0,0 +1,93 @@ +/* + * 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.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.apache.skywalking.apm.collector.cache.CacheModule; +import org.apache.skywalking.apm.collector.cache.service.ServiceNameCacheService; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationComponentUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceReferenceMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.table.MetricSource; +import org.apache.skywalking.apm.collector.storage.table.register.ServiceName; +import org.apache.skywalking.apm.collector.storage.ui.common.Call; +import org.apache.skywalking.apm.collector.storage.ui.common.Node; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.storage.ui.common.Topology; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ServiceTopologyService { + + private final Logger logger = LoggerFactory.getLogger(ServiceTopologyService.class); + + private final IApplicationComponentUIDAO applicationComponentUIDAO; + private final IServiceMetricUIDAO serviceMetricUIDAO; + private final IServiceReferenceMetricUIDAO serviceReferenceMetricUIDAO; + private final ServiceNameCacheService serviceNameCacheService; + + public ServiceTopologyService(ModuleManager moduleManager) { + this.serviceMetricUIDAO = moduleManager.find(StorageModule.NAME).getService(IServiceMetricUIDAO.class); + this.serviceReferenceMetricUIDAO = moduleManager.find(StorageModule.NAME).getService(IServiceReferenceMetricUIDAO.class); + this.applicationComponentUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationComponentUIDAO.class); + this.serviceNameCacheService = moduleManager.find(CacheModule.NAME).getService(ServiceNameCacheService.class); + } + + public Topology getServiceTopology(Step step, int serviceId, long start, long end) throws ParseException { + logger.debug("start: {}, end: {}", start, end); + List applicationComponents = applicationComponentUIDAO.load(step, start, end); + + Map components = new HashMap<>(); + applicationComponents.forEach(component -> components.put(component.getApplicationId(), ComponentsDefine.getInstance().getComponentName(component.getComponentId()))); + + List calleeCalls = serviceReferenceMetricUIDAO.getFrontServices(step, start, end, MetricSource.Callee, serviceId); + calleeCalls.addAll(serviceReferenceMetricUIDAO.getBehindServices(step, start, end, MetricSource.Caller, serviceId)); + + Set nodeIds = new HashSet<>(); + calleeCalls.forEach(call -> { + call.setCallType(Const.EMPTY_STRING); + nodeIds.add(call.getSource()); + nodeIds.add(call.getTarget()); + }); + + List serviceNodes = serviceMetricUIDAO.getServicesMetric(step, start, end, MetricSource.Callee, nodeIds); + + serviceNodes.forEach(serviceNode -> { + ServiceName serviceName = serviceNameCacheService.get(serviceNode.getId()); + serviceNode.setName(serviceName.getServiceName()); + }); + + Topology topology = new Topology(); + topology.setCalls(calleeCalls); + topology.setNodes(serviceNodes); + return topology; + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ServiceTreeService.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ServiceTreeService.java deleted file mode 100644 index 085120e61..000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ServiceTreeService.java +++ /dev/null @@ -1,123 +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.ui.service; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import java.util.Iterator; -import java.util.Map; -import org.apache.skywalking.apm.collector.cache.CacheModule; -import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService; -import org.apache.skywalking.apm.collector.cache.service.ServiceNameCacheService; -import org.apache.skywalking.apm.collector.core.module.ModuleManager; -import org.apache.skywalking.apm.collector.core.util.ColumnNameUtils; -import org.apache.skywalking.apm.collector.core.util.Const; -import org.apache.skywalking.apm.collector.core.util.ObjectUtils; -import org.apache.skywalking.apm.collector.storage.StorageModule; -import org.apache.skywalking.apm.collector.storage.dao.IServiceReferenceUIDAO; -import org.apache.skywalking.apm.collector.storage.table.service.ServiceReferenceMetricTable; - -/** - * @author peng-yongsheng - */ -public class ServiceTreeService { - - private final IServiceReferenceUIDAO serviceReferenceDAO; - private final ApplicationCacheService applicationCacheService; - private final ServiceNameCacheService serviceNameCacheService; - - public ServiceTreeService(ModuleManager moduleManager) { - this.serviceReferenceDAO = moduleManager.find(StorageModule.NAME).getService(IServiceReferenceUIDAO.class); - this.applicationCacheService = moduleManager.find(CacheModule.NAME).getService(ApplicationCacheService.class); - this.serviceNameCacheService = moduleManager.find(CacheModule.NAME).getService(ServiceNameCacheService.class); - } - - public JsonArray loadServiceTree(int entryServiceId, long startTime, long endTime) { - Map serviceReferenceMap = serviceReferenceDAO.load(entryServiceId, startTime, endTime); - serviceReferenceMap.values().forEach(serviceReference -> { - int frontServiceId = serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID)).getAsInt(); - int behindServiceId = serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID)).getAsInt(); - String frontServiceName = serviceNameCacheService.getSplitServiceName(serviceNameCacheService.get(frontServiceId)); - String behindServiceName = serviceNameCacheService.getSplitServiceName(serviceNameCacheService.get(behindServiceId)); - serviceReference.addProperty("frontServiceName", frontServiceName); - serviceReference.addProperty("behindServiceName", behindServiceName); - }); - return buildTreeData(serviceReferenceMap); - } - - private JsonArray buildTreeData(Map serviceReferenceMap) { - JsonArray serviceReferenceArray = new JsonArray(); - JsonObject rootServiceReference = findRoot(serviceReferenceMap); - if (ObjectUtils.isNotEmpty(rootServiceReference)) { - serviceReferenceArray.add(rootServiceReference); - String id = rootServiceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID)) + Const.ID_SPLIT + rootServiceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID)); - serviceReferenceMap.remove(id); - - int rootServiceId = rootServiceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID)).getAsInt(); - sortAsTree(rootServiceId, serviceReferenceArray, serviceReferenceMap); - } - - return serviceReferenceArray; - } - - private JsonObject findRoot(Map serviceReferenceMap) { - for (JsonObject serviceReference : serviceReferenceMap.values()) { - int frontServiceId = serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID)).getAsInt(); - if (frontServiceId == 1) { - return serviceReference; - } - } - return null; - } - - private void sortAsTree(int serviceId, JsonArray serviceReferenceArray, - Map serviceReferenceMap) { - Iterator iterator = serviceReferenceMap.values().iterator(); - while (iterator.hasNext()) { - JsonObject serviceReference = iterator.next(); - int frontServiceId = serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID)).getAsInt(); - if (serviceId == frontServiceId) { - serviceReferenceArray.add(serviceReference); - - int behindServiceId = serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID)).getAsInt(); - sortAsTree(behindServiceId, serviceReferenceArray, serviceReferenceMap); - } - } - } - - private void merge(Map serviceReferenceMap, JsonObject serviceReference) { - String id = serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_FRONT_SERVICE_ID)) + Const.ID_SPLIT + serviceReference.get(ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_BEHIND_SERVICE_ID)); - - if (serviceReferenceMap.containsKey(id)) { - JsonObject reference = serviceReferenceMap.get(id); - add(reference, serviceReference, ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_TRANSACTION_CALLS)); - add(reference, serviceReference, ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS)); - add(reference, serviceReference, ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_TRANSACTION_DURATION_SUM)); - add(reference, serviceReference, ColumnNameUtils.INSTANCE.rename(ServiceReferenceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM)); - } else { - serviceReferenceMap.put(id, serviceReference); - } - } - - private void add(JsonObject oldReference, JsonObject newReference, String key) { - long oldValue = oldReference.get(key).getAsLong(); - long newValue = newReference.get(key).getAsLong(); - oldReference.addProperty(key, oldValue + newValue); - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/SpanService.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/SpanService.java index 0e902fe34..c149778fe 100644 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/SpanService.java +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/SpanService.java @@ -16,25 +16,24 @@ * */ - package org.apache.skywalking.apm.collector.ui.service; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import java.util.List; import org.apache.skywalking.apm.collector.cache.CacheModule; -import org.apache.skywalking.apm.collector.core.module.ModuleManager; -import org.apache.skywalking.apm.collector.core.util.Const; -import org.apache.skywalking.apm.collector.storage.dao.ISegmentUIDAO; -import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService; import org.apache.skywalking.apm.collector.cache.service.ServiceNameCacheService; +import org.apache.skywalking.apm.collector.core.module.ModuleManager; import org.apache.skywalking.apm.collector.core.util.StringUtils; import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.storage.dao.ui.ISegmentUIDAO; +import org.apache.skywalking.apm.collector.storage.table.register.ServiceName; import org.apache.skywalking.apm.network.proto.KeyWithStringValue; import org.apache.skywalking.apm.network.proto.LogMessage; import org.apache.skywalking.apm.network.proto.SpanObject; import org.apache.skywalking.apm.network.proto.TraceSegmentObject; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; /** * @author peng-yongsheng @@ -60,9 +59,9 @@ public class SpanService { if (spanId == spanObject.getSpanId()) { String operationName = spanObject.getOperationName(); if (spanObject.getOperationNameId() != 0) { - String serviceName = serviceNameCacheService.get(spanObject.getOperationNameId()); + ServiceName serviceName = serviceNameCacheService.get(spanObject.getOperationNameId()); if (StringUtils.isNotEmpty(serviceName)) { - operationName = serviceName.split(Const.ID_SPLIT)[1]; + operationName = serviceName.getServiceName(); } } spanJson.addProperty("operationName", operationName); @@ -108,7 +107,7 @@ public class SpanService { if (spanObject.getPeerId() == 0) { peerJson.addProperty("value", spanObject.getPeer()); } else { - peerJson.addProperty("value", applicationCacheService.getApplicationCodeById(spanObject.getPeerId())); + peerJson.addProperty("value", applicationCacheService.getApplicationById(spanObject.getPeerId()).getApplicationCode()); } tagsArray.add(peerJson); diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/TimeSynchronousService.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/TimeSynchronousService.java index 663ec3c75..d83abe06a 100644 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/TimeSynchronousService.java +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/TimeSynchronousService.java @@ -21,7 +21,7 @@ package org.apache.skywalking.apm.collector.ui.service; 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.IInstanceUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceUIDAO; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/TopologyBuilder.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/TopologyBuilder.java new file mode 100644 index 000000000..90bcd8344 --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/TopologyBuilder.java @@ -0,0 +1,155 @@ +/* + * 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.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.apache.skywalking.apm.collector.cache.CacheModule; +import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService; +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.Const; +import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationComponentUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMappingUIDAO; +import org.apache.skywalking.apm.collector.storage.table.register.Application; +import org.apache.skywalking.apm.collector.storage.ui.application.ApplicationNode; +import org.apache.skywalking.apm.collector.storage.ui.application.ConjecturalNode; +import org.apache.skywalking.apm.collector.storage.ui.common.Call; +import org.apache.skywalking.apm.collector.storage.ui.common.Node; +import org.apache.skywalking.apm.collector.storage.ui.common.Topology; +import org.apache.skywalking.apm.collector.storage.ui.common.VisualUserNode; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; + +/** + * @author peng-yongsheng + */ +class TopologyBuilder { + + private final ApplicationCacheService applicationCacheService; + + TopologyBuilder(ModuleManager moduleManager) { + this.applicationCacheService = moduleManager.find(CacheModule.NAME).getService(ApplicationCacheService.class); + } + + Topology build(List applicationComponents, + List applicationMappings, List callerCalls, + List calleeCalls, long secondsBetween) { + Map components = changeNodeComp2Map(applicationComponents); + Map mappings = changeMapping2Map(applicationMappings); + + List calls = buildCalls(callerCalls, calleeCalls); + + Set nodeIds = new HashSet<>(); + calls.forEach(call -> { + String sourceName = applicationCacheService.getApplicationById(call.getSource()).getApplicationCode(); + String targetName = applicationCacheService.getApplicationById(call.getTarget()).getApplicationCode(); + + call.setSourceName(sourceName); + call.setTargetName(targetName); + + nodeIds.add(call.getSource()); + nodeIds.add(call.getTarget()); + }); + + List nodes = new LinkedList<>(); + nodeIds.forEach(nodeId -> { + Application application = applicationCacheService.getApplicationById(nodeId); + if (BooleanUtils.valueToBoolean(application.getAddressId())) { + ConjecturalNode conjecturalNode = new ConjecturalNode(); + conjecturalNode.setId(nodeId); + conjecturalNode.setName(application.getApplicationCode()); + conjecturalNode.setType(components.getOrDefault(application.getApplicationId(), Const.UNKNOWN)); + nodes.add(conjecturalNode); + } else { + if (nodeId == Const.NONE_APPLICATION_ID) { + VisualUserNode node = new VisualUserNode(); + node.setId(nodeId); + node.setName(Const.USER_CODE); + node.setType(Const.USER_CODE.toUpperCase()); + nodes.add(node); + } else { + ApplicationNode applicationNode = new ApplicationNode(); + applicationNode.setId(nodeId); + applicationNode.setName(application.getApplicationCode()); + applicationNode.setType(components.getOrDefault(application.getApplicationId(), Const.UNKNOWN)); + + calleeCalls.forEach(call -> { + if (call.getTarget() == nodeId) { + call.setCallsPerSec(call.getCalls() / secondsBetween); + call.setResponseTimePerSec(call.getResponseTimes() / secondsBetween); + } + }); + applicationNode.setCallsPerSec(100L); + applicationNode.setResponseTimePerSec(100L); + nodes.add(applicationNode); + } + } + }); + + Topology topology = new Topology(); + topology.setCalls(calls); + topology.setNodes(nodes); + return topology; + } + + private Map changeMapping2Map( + List applicationMappings) { + Map mappings = new HashMap<>(); + applicationMappings.forEach(applicationMapping -> { + String applicationCode = applicationCacheService.getApplicationById(applicationMapping.getApplicationId()).getApplicationCode(); + String address = applicationCacheService.getApplicationById(applicationMapping.getMappingApplicationId()).getApplicationCode(); + mappings.put(address, applicationCode); + }); + return mappings; + } + + private Map changeNodeComp2Map( + List applicationComponents) { + Map components = new HashMap<>(); + applicationComponents.forEach(applicationComponent -> { + String componentName = ComponentsDefine.getInstance().getComponentName(applicationComponent.getComponentId()); + components.put(applicationComponent.getApplicationId(), componentName); + }); + return components; + } + + private List buildCalls(List callerCalls, List calleeCalls) { + List calls = new LinkedList<>(); + + Set distinctCalls = new HashSet<>(); + callerCalls.forEach(callerCall -> { + distinctCalls.add(callerCall.getSource() + Const.ID_SPLIT + callerCall.getTarget()); + calls.add(callerCall); + }); + + calleeCalls.forEach(calleeCall -> { + String call = calleeCall.getSource() + Const.ID_SPLIT + calleeCall.getTarget(); + if (!distinctCalls.contains(call)) { + distinctCalls.add(call); + calls.add(calleeCall); + } + }); + + return calls; + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/TraceDagDataBuilder.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/TraceDagDataBuilder.java deleted file mode 100644 index 297c43573..000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/TraceDagDataBuilder.java +++ /dev/null @@ -1,153 +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.ui.service; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; -import org.apache.skywalking.apm.collector.cache.CacheModule; -import org.apache.skywalking.apm.collector.core.util.Const; -import org.apache.skywalking.apm.collector.storage.table.application.ApplicationComponentTable; -import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMappingTable; -import org.apache.skywalking.apm.collector.storage.table.application.ApplicationReferenceMetricTable; -import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService; -import org.apache.skywalking.apm.collector.core.module.ModuleManager; -import org.apache.skywalking.apm.collector.core.util.ColumnNameUtils; -import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class TraceDagDataBuilder { - private final Logger logger = LoggerFactory.getLogger(TraceDagDataBuilder.class); - - private Integer nodeId = -1; - private Map mappingMap = new HashMap<>(); - private Map nodeCompMap = new HashMap<>(); - private Map nodeIdMap = new HashMap<>(); - private JsonArray pointArray = new JsonArray(); - private JsonArray lineArray = new JsonArray(); - private final ApplicationCacheService applicationCacheService; - - public TraceDagDataBuilder(ModuleManager moduleManager) { - this.applicationCacheService = moduleManager.find(CacheModule.NAME).getService(ApplicationCacheService.class); - } - - public JsonObject build(JsonArray nodeCompArray, JsonArray nodesMappingArray, JsonArray resSumArray) { - changeNodeComp2Map(nodeCompArray); - changeMapping2Map(nodesMappingArray); - - Map mergedResSumMap = getApplicationCode(resSumArray); - - mergedResSumMap.values().forEach(nodeRefJsonObj -> { - String front = nodeRefJsonObj.get("front").getAsString(); - String behind = nodeRefJsonObj.get("behind").getAsString(); - - if (hasMapping(behind)) { - return; - } - - JsonObject lineJsonObj = new JsonObject(); - lineJsonObj.addProperty("from", findOrCreateNode(front)); - lineJsonObj.addProperty("to", findOrCreateNode(behind)); - lineJsonObj.addProperty("resSum", nodeRefJsonObj.get(ApplicationReferenceMetricTable.COLUMN_TRANSACTION_CALLS).getAsInt()); - - lineArray.add(lineJsonObj); - logger.debug("line: {}", lineJsonObj); - }); - - JsonObject dagJsonObj = new JsonObject(); - dagJsonObj.add("nodes", pointArray); - dagJsonObj.add("nodeRefs", lineArray); - return dagJsonObj; - } - - private Integer findOrCreateNode(String peers) { - if (nodeIdMap.containsKey(peers) && !peers.equals(Const.USER_CODE)) { - return nodeIdMap.get(peers); - } else { - nodeId++; - JsonObject nodeJsonObj = new JsonObject(); - nodeJsonObj.addProperty("id", nodeId); - nodeJsonObj.addProperty("peer", peers); - if (peers.equals(Const.USER_CODE)) { - nodeJsonObj.addProperty("component", Const.USER_CODE); - } else { - nodeJsonObj.addProperty("component", nodeCompMap.get(peers)); - } - pointArray.add(nodeJsonObj); - - nodeIdMap.put(peers, nodeId); - logger.debug("node: {}", nodeJsonObj); - } - return nodeId; - } - - private void changeMapping2Map(JsonArray nodesMappingArray) { - for (int i = 0; i < nodesMappingArray.size(); i++) { - JsonObject nodesMappingJsonObj = nodesMappingArray.get(i).getAsJsonObject(); - int applicationId = nodesMappingJsonObj.get(ApplicationMappingTable.COLUMN_APPLICATION_ID).getAsInt(); - String applicationCode = applicationCacheService.getApplicationCodeById(applicationId); - int addressId = nodesMappingJsonObj.get(ApplicationMappingTable.COLUMN_ADDRESS_ID).getAsInt(); - String address = applicationCacheService.getApplicationCodeById(addressId); - mappingMap.put(address, applicationCode); - } - } - - private void changeNodeComp2Map(JsonArray nodeCompArray) { - for (int i = 0; i < nodeCompArray.size(); i++) { - JsonObject nodesJsonObj = nodeCompArray.get(i).getAsJsonObject(); - logger.debug(nodesJsonObj.toString()); - int componentId = nodesJsonObj.get(ApplicationComponentTable.COLUMN_COMPONENT_ID).getAsInt(); - String componentName = ComponentsDefine.getInstance().getComponentName(componentId); - int peerId = nodesJsonObj.get(ApplicationComponentTable.COLUMN_PEER_ID).getAsInt(); - String peer = applicationCacheService.getApplicationCodeById(peerId); - nodeCompMap.put(peer, componentName); - } - } - - private boolean hasMapping(String peers) { - return mappingMap.containsKey(peers); - } - - private Map getApplicationCode(JsonArray nodeReference) { - Map mergedRef = new LinkedHashMap<>(); - for (int i = 0; i < nodeReference.size(); i++) { - JsonObject nodeRefJsonObj = nodeReference.get(i).getAsJsonObject(); - - int frontApplicationId = nodeRefJsonObj.get(ColumnNameUtils.INSTANCE.rename(ApplicationReferenceMetricTable.COLUMN_FRONT_APPLICATION_ID)).getAsInt(); - int behindApplicationId = nodeRefJsonObj.get(ColumnNameUtils.INSTANCE.rename(ApplicationReferenceMetricTable.COLUMN_BEHIND_APPLICATION_ID)).getAsInt(); - - String front = applicationCacheService.getApplicationCodeById(frontApplicationId); - String behind = applicationCacheService.getApplicationCodeById(behindApplicationId); - - String id = front + Const.ID_SPLIT + behind; - nodeRefJsonObj.addProperty("front", front); - nodeRefJsonObj.addProperty("behind", behind); - mergedRef.put(id, nodeRefJsonObj); - } - - return mergedRef; - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/TraceDagService.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/TraceDagService.java deleted file mode 100644 index 501ca0e4e..000000000 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/TraceDagService.java +++ /dev/null @@ -1,64 +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.ui.service; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -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.IApplicationComponentUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.IApplicationMappingUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.IApplicationReferenceMetricUIDAO; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author peng-yongsheng - */ -public class TraceDagService { - - private final Logger logger = LoggerFactory.getLogger(TraceDagService.class); - - private final IApplicationComponentUIDAO applicationComponentUIDAO; - private final IApplicationMappingUIDAO applicationMappingUIDAO; - private final IApplicationReferenceMetricUIDAO applicationReferenceMetricUIDAO; - private final ModuleManager moduleManager; - - public TraceDagService(ModuleManager moduleManager) { - this.moduleManager = moduleManager; - this.applicationComponentUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationComponentUIDAO.class); - this.applicationMappingUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationMappingUIDAO.class); - this.applicationReferenceMetricUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationReferenceMetricUIDAO.class); - } - - public JsonObject load(long startTime, long endTime) { - logger.debug("startTime: {}, endTime: {}", startTime, endTime); - JsonArray applicationComponentArray = applicationComponentUIDAO.load(startTime, endTime); - - JsonArray applicationMappingArray = applicationMappingUIDAO.load(startTime, endTime); - - JsonArray applicationReferenceMetricArray = applicationReferenceMetricUIDAO.load(startTime, endTime); - - TraceDagDataBuilder builder = new TraceDagDataBuilder(moduleManager); - JsonObject traceDag = builder.build(applicationComponentArray, applicationMappingArray, applicationReferenceMetricArray); - - return traceDag; - } -} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/TraceStackService.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/TraceStackService.java index 16da98b37..9d65686f2 100644 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/TraceStackService.java +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/TraceStackService.java @@ -16,26 +16,33 @@ * */ - package org.apache.skywalking.apm.collector.ui.service; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; import org.apache.skywalking.apm.collector.cache.CacheModule; +import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService; +import org.apache.skywalking.apm.collector.cache.service.NetworkAddressCacheService; +import org.apache.skywalking.apm.collector.cache.service.ServiceNameCacheService; import org.apache.skywalking.apm.collector.core.module.ModuleManager; import org.apache.skywalking.apm.collector.core.util.CollectionUtils; import org.apache.skywalking.apm.collector.core.util.Const; import org.apache.skywalking.apm.collector.core.util.ObjectUtils; -import org.apache.skywalking.apm.collector.storage.dao.IGlobalTraceUIDAO; -import org.apache.skywalking.apm.collector.storage.dao.ISegmentUIDAO; -import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService; -import org.apache.skywalking.apm.collector.cache.service.ServiceNameCacheService; -import org.apache.skywalking.apm.collector.core.util.StringUtils; import org.apache.skywalking.apm.collector.storage.StorageModule; +import org.apache.skywalking.apm.collector.storage.dao.ui.IGlobalTraceUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.ISegmentUIDAO; +import org.apache.skywalking.apm.collector.storage.table.register.ServiceName; +import org.apache.skywalking.apm.collector.storage.ui.trace.KeyValue; +import org.apache.skywalking.apm.collector.storage.ui.trace.LogEntity; +import org.apache.skywalking.apm.collector.storage.ui.trace.Ref; +import org.apache.skywalking.apm.collector.storage.ui.trace.RefType; +import org.apache.skywalking.apm.collector.storage.ui.trace.Span; +import org.apache.skywalking.apm.collector.storage.ui.trace.Trace; import org.apache.skywalking.apm.network.proto.SpanObject; import org.apache.skywalking.apm.network.proto.TraceSegmentObject; +import org.apache.skywalking.apm.network.proto.UniqueId; +import org.apache.skywalking.apm.network.trace.component.ComponentsDefine; /** * @author peng-yongsheng @@ -46,60 +53,45 @@ public class TraceStackService { private final ISegmentUIDAO segmentDAO; private final ApplicationCacheService applicationCacheService; private final ServiceNameCacheService serviceNameCacheService; + private final NetworkAddressCacheService networkAddressCacheService; public TraceStackService(ModuleManager moduleManager) { this.globalTraceDAO = moduleManager.find(StorageModule.NAME).getService(IGlobalTraceUIDAO.class); this.segmentDAO = moduleManager.find(StorageModule.NAME).getService(ISegmentUIDAO.class); this.applicationCacheService = moduleManager.find(CacheModule.NAME).getService(ApplicationCacheService.class); this.serviceNameCacheService = moduleManager.find(CacheModule.NAME).getService(ServiceNameCacheService.class); + this.networkAddressCacheService = moduleManager.find(CacheModule.NAME).getService(NetworkAddressCacheService.class); } - public JsonArray load(String globalTraceId) { - List spans = new ArrayList<>(); - List segmentIds = globalTraceDAO.getSegmentIds(globalTraceId); + public Trace load(String traceId) { + Trace trace = new Trace(); + List segmentIds = globalTraceDAO.getSegmentIds(traceId); if (CollectionUtils.isNotEmpty(segmentIds)) { for (String segmentId : segmentIds) { TraceSegmentObject segment = segmentDAO.load(segmentId); if (ObjectUtils.isNotEmpty(segment)) { - spans.addAll(buildSpanList(segmentId, segment)); + trace.getSpans().addAll(buildSpanList(traceId, segmentId, segment.getApplicationId(), segment.getSpansList())); } } } - List sortedSpans = new ArrayList<>(); - if (CollectionUtils.isNotEmpty(spans)) { - List rootSpans = findRoot(spans); + List sortedSpans = new LinkedList<>(); + if (CollectionUtils.isNotEmpty(trace.getSpans())) { + List rootSpans = findRoot(trace.getSpans()); if (CollectionUtils.isNotEmpty(rootSpans)) { rootSpans.forEach(span -> { List childrenSpan = new ArrayList<>(); childrenSpan.add(span); - findChildren(spans, span, childrenSpan); + findChildren(trace.getSpans(), span, childrenSpan); sortedSpans.addAll(childrenSpan); }); } } - minStartTime(sortedSpans); +// minStartTime(sortedSpans); - return toJsonArray(sortedSpans); - } - - private JsonArray toJsonArray(List sortedSpans) { - JsonArray traceStackArray = new JsonArray(); - sortedSpans.forEach(span -> { - JsonObject spanJson = new JsonObject(); - spanJson.addProperty("spanId", span.getSpanId()); - spanJson.addProperty("parentSpanId", span.getParentSpanId()); - spanJson.addProperty("segmentSpanId", span.getSegmentSpanId()); - spanJson.addProperty("segmentParentSpanId", span.getSegmentParentSpanId()); - spanJson.addProperty("startTime", span.getStartTime()); - spanJson.addProperty("operationName", span.getOperationName()); - spanJson.addProperty("applicationCode", span.getApplicationCode()); - spanJson.addProperty("cost", span.getCost()); - spanJson.addProperty("isRoot", span.isRoot()); - traceStackArray.add(spanJson); - }); - return traceStackArray; + trace.setSpans(sortedSpans); + return trace; } private void minStartTime(List spans) { @@ -115,56 +107,108 @@ public class TraceStackService { } } - private List buildSpanList(String segmentId, TraceSegmentObject segment) { + private List buildSpanList(String traceId, String segmentId, int applicationId, + List spanObjects) { List spans = new ArrayList<>(); - if (segment.getSpansCount() > 0) { - for (SpanObject spanObject : segment.getSpansList()) { - int spanId = spanObject.getSpanId(); - int parentSpanId = spanObject.getParentSpanId(); - String segmentSpanId = segmentId + Const.SEGMENT_SPAN_SPLIT + String.valueOf(spanId); - String segmentParentSpanId = segmentId + Const.SEGMENT_SPAN_SPLIT + String.valueOf(parentSpanId); - long startTime = spanObject.getStartTime(); - String operationName = spanObject.getOperationName(); - if (spanObject.getOperationNameId() != 0) { - String serviceName = serviceNameCacheService.get(spanObject.getOperationNameId()); - if (StringUtils.isNotEmpty(serviceName)) { - operationName = serviceName.split(Const.ID_SPLIT)[1]; + spanObjects.forEach(spanObject -> { + Span span = new Span(); + span.setTraceId(traceId); + span.setSegmentId(segmentId); + span.setSpanId(spanObject.getSpanId()); + span.setParentSpanId(spanObject.getParentSpanId()); + span.setStartTime(spanObject.getStartTime()); + span.setEndTime(spanObject.getEndTime()); + span.setError(spanObject.getIsError()); + span.setLayer(spanObject.getSpanLayer().name()); + span.setType(spanObject.getSpanType().name()); + + String segmentSpanId = segmentId + Const.SEGMENT_SPAN_SPLIT + String.valueOf(spanObject.getSpanId()); + span.setSegmentSpanId(segmentSpanId); + + String segmentParentSpanId = segmentId + Const.SEGMENT_SPAN_SPLIT + String.valueOf(spanObject.getParentSpanId()); + span.setSegmentParentSpanId(segmentParentSpanId); + + if (spanObject.getPeerId() == 0) { + span.setPeer(spanObject.getPeer()); + } else { + span.setPeer(networkAddressCacheService.getAddress(spanObject.getPeerId())); + } + + String operationName = spanObject.getOperationName(); + if (spanObject.getOperationNameId() != 0) { + ServiceName serviceName = serviceNameCacheService.get(spanObject.getOperationNameId()); + if (ObjectUtils.isNotEmpty(serviceName)) { + operationName = serviceName.getServiceName(); + } else { + operationName = Const.EMPTY_STRING; + } + } + span.setOperationName(operationName); + + String applicationCode = applicationCacheService.getApplicationById(applicationId).getApplicationCode(); + span.setApplicationCode(applicationCode); + + if (spanObject.getComponentId() == 0) { + span.setComponent(spanObject.getComponent()); + } else { + span.setComponent(ComponentsDefine.getInstance().getComponentName(spanObject.getComponentId())); + } + + spanObject.getRefsList().forEach(reference -> { + Ref ref = new Ref(); + ref.setTraceId(traceId); + + switch (reference.getRefType()) { + case CrossThread: + ref.setType(RefType.CROSS_THREAD); + break; + case CrossProcess: + ref.setType(RefType.CROSS_PROCESS); + break; + } + ref.setParentSpanId(reference.getParentSpanId()); + + UniqueId uniqueId = reference.getParentTraceSegmentId(); + StringBuilder segmentIdBuilder = new StringBuilder(); + for (int i = 0; i < uniqueId.getIdPartsList().size(); i++) { + if (i == 0) { + segmentIdBuilder.append(String.valueOf(uniqueId.getIdPartsList().get(i))); } else { - operationName = Const.EMPTY_STRING; + segmentIdBuilder.append(".").append(String.valueOf(uniqueId.getIdPartsList().get(i))); } } - String applicationCode = applicationCacheService.getApplicationCodeById(segment.getApplicationId()); + ref.setParentSegmentId(segmentIdBuilder.toString()); - long cost = spanObject.getEndTime() - spanObject.getStartTime(); - if (cost == 0) { - cost = 1; - } + span.setSegmentParentSpanId(ref.getParentSegmentId() + Const.SEGMENT_SPAN_SPLIT + String.valueOf(ref.getParentSpanId())); + + span.getRefs().add(ref); + }); + + spanObject.getTagsList().forEach(tag -> { + KeyValue keyValue = new KeyValue(); + keyValue.setKey(tag.getKey()); + keyValue.setValue(tag.getValue()); + span.getTags().add(keyValue); + }); + + spanObject.getLogsList().forEach(log -> { + LogEntity logEntity = new LogEntity(); + logEntity.setTime(log.getTime()); + + log.getDataList().forEach(data -> { + KeyValue keyValue = new KeyValue(); + keyValue.setKey(data.getKey()); + keyValue.setValue(data.getValue()); + logEntity.getData().add(keyValue); + }); + + span.getLogs().add(logEntity); + }); + + spans.add(span); + }); -// if (parentSpanId == -1 && segment.getRefsCount() > 0) { -// for (TraceSegmentReference reference : segment.getRefsList()) { -// parentSpanId = reference.getParentSpanId(); -// UniqueId uniqueId = reference.getParentTraceSegmentId(); -// -// StringBuilder segmentIdBuilder = new StringBuilder(); -// for (int i = 0; i < uniqueId.getIdPartsList().size(); i++) { -// if (i == 0) { -// segmentIdBuilder.append(String.valueOf(uniqueId.getIdPartsList().getApplicationIdByCode(i))); -// } else { -// segmentIdBuilder.append(".").append(String.valueOf(uniqueId.getIdPartsList().getApplicationIdByCode(i))); -// } -// } -// -// String parentSegmentId = segmentIdBuilder.toString(); -// segmentParentSpanId = parentSegmentId + Const.SEGMENT_SPAN_SPLIT + String.valueOf(parentSpanId); -// -// spans.add(new Span(spanId, parentSpanId, segmentSpanId, segmentParentSpanId, startTime, operationName, applicationCode, cost)); -// } -// } else { -// spans.add(new Span(spanId, parentSpanId, segmentSpanId, segmentParentSpanId, startTime, operationName, applicationCode, cost)); -// } - } - } return spans; } @@ -174,8 +218,8 @@ public class TraceStackService { String segmentParentSpanId = span.getSegmentParentSpanId(); boolean hasParent = false; - for (Span span1 : spans) { - if (segmentParentSpanId.equals(span1.getSegmentSpanId())) { + for (Span subSpan : spans) { + if (segmentParentSpanId.equals(subSpan.getSegmentSpanId())) { hasParent = true; } } @@ -196,72 +240,4 @@ public class TraceStackService { } }); } - - class Span { - private int spanId; - private int parentSpanId; - private String segmentSpanId; - private String segmentParentSpanId; - private long startTime; - private String operationName; - private String applicationCode; - private long cost; - private boolean isRoot = false; - - Span(int spanId, int parentSpanId, String segmentSpanId, String segmentParentSpanId, long startTime, - String operationName, String applicationCode, long cost) { - this.spanId = spanId; - this.parentSpanId = parentSpanId; - this.segmentSpanId = segmentSpanId; - this.segmentParentSpanId = segmentParentSpanId; - this.startTime = startTime; - this.operationName = operationName; - this.applicationCode = applicationCode; - this.cost = cost; - } - - int getSpanId() { - return spanId; - } - - int getParentSpanId() { - return parentSpanId; - } - - String getSegmentSpanId() { - return segmentSpanId; - } - - String getSegmentParentSpanId() { - return segmentParentSpanId; - } - - long getStartTime() { - return startTime; - } - - String getOperationName() { - return operationName; - } - - String getApplicationCode() { - return applicationCode; - } - - long getCost() { - return cost; - } - - public boolean isRoot() { - return isRoot; - } - - public void setRoot(boolean root) { - isRoot = root; - } - - public void setStartTime(long startTime) { - this.startTime = startTime; - } - } } diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/utils/DurationUtils.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/utils/DurationUtils.java new file mode 100644 index 000000000..e7ac4c8cf --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/utils/DurationUtils.java @@ -0,0 +1,186 @@ +/* + * 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.utils; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.LinkedList; +import java.util.List; +import org.apache.skywalking.apm.collector.core.UnexpectedException; +import org.apache.skywalking.apm.collector.core.util.Const; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.storage.utils.DurationPoint; +import org.joda.time.DateTime; +import org.joda.time.Seconds; + +/** + * @author peng-yongsheng + */ +public enum DurationUtils { + INSTANCE; + + public long exchangeToTimeBucket(String dateStr) throws ParseException { + dateStr = dateStr.replaceAll("-", Const.EMPTY_STRING); + dateStr = dateStr.replaceAll(" ", Const.EMPTY_STRING); + return Long.valueOf(dateStr); + } + + public long durationToSecondTimeBucket(Step step, String dateStr) throws ParseException { + long secondTimeBucket = 0; + switch (step) { + case MONTH: + secondTimeBucket = exchangeToTimeBucket(dateStr) * 100 * 100 * 100 * 100; + break; + case DAY: + secondTimeBucket = exchangeToTimeBucket(dateStr) * 100 * 100 * 100; + break; + case HOUR: + secondTimeBucket = exchangeToTimeBucket(dateStr) * 100 * 100; + break; + case MINUTE: + secondTimeBucket = exchangeToTimeBucket(dateStr) * 100; + break; + case SECOND: + secondTimeBucket = exchangeToTimeBucket(dateStr); + break; + } + return secondTimeBucket; + } + + public long secondsBetween(Step step, long start, long end) throws ParseException { + Date startDate = null; + Date endDate = null; + switch (step) { + case MONTH: + startDate = new SimpleDateFormat("yyyyMM").parse(String.valueOf(start)); + endDate = new SimpleDateFormat("yyyyMM").parse(String.valueOf(end)); + break; + case DAY: + startDate = new SimpleDateFormat("yyyyMMdd").parse(String.valueOf(start)); + endDate = new SimpleDateFormat("yyyyMMdd").parse(String.valueOf(end)); + break; + case HOUR: + startDate = new SimpleDateFormat("yyyyMMddHH").parse(String.valueOf(start)); + endDate = new SimpleDateFormat("yyyyMMddHH").parse(String.valueOf(end)); + break; + case MINUTE: + startDate = new SimpleDateFormat("yyyyMMddHHmm").parse(String.valueOf(start)); + endDate = new SimpleDateFormat("yyyyMMddHHmm").parse(String.valueOf(end)); + break; + case SECOND: + startDate = new SimpleDateFormat("yyyyMMddHHmmss").parse(String.valueOf(start)); + endDate = new SimpleDateFormat("yyyyMMddHHmmss").parse(String.valueOf(end)); + break; + } + + return Seconds.secondsBetween(new DateTime(startDate), new DateTime(endDate)).getSeconds(); + } + + public long secondsBetween(Step step, DateTime dateTime) throws ParseException { + switch (step) { + case MONTH: + return dateTime.dayOfMonth().getMaximumValue() * 24 * 60 * 60; + case DAY: + return 24 * 60 * 60; + case HOUR: + return 60 * 60; + case MINUTE: + return 60; + case SECOND: + return 1; + default: + return 1; + } + } + + public DateTime parseToDateTime(Step step, long time) throws ParseException { + DateTime dateTime = null; + + switch (step) { + case MONTH: + Date date = new SimpleDateFormat("yyyyMM").parse(String.valueOf(time)); + dateTime = new DateTime(date); + break; + case DAY: + date = new SimpleDateFormat("yyyyMMdd").parse(String.valueOf(time)); + dateTime = new DateTime(date); + break; + case HOUR: + date = new SimpleDateFormat("yyyyMMddHH").parse(String.valueOf(time)); + dateTime = new DateTime(date); + break; + case MINUTE: + date = new SimpleDateFormat("yyyyMMddHHmm").parse(String.valueOf(time)); + dateTime = new DateTime(date); + break; + case SECOND: + date = new SimpleDateFormat("yyyyMMddHHmmss").parse(String.valueOf(time)); + dateTime = new DateTime(date); + break; + } + + return dateTime; + } + + public List getDurationPoints(Step step, long start, long end) throws ParseException { + DateTime dateTime = parseToDateTime(step, start); + + List durations = new LinkedList<>(); + durations.add(new DurationPoint(start, secondsBetween(step, dateTime))); + + int i = 0; + do { + switch (step) { + case MONTH: + dateTime = dateTime.plusMonths(1); + String timeBucket = new SimpleDateFormat("yyyyMM").format(dateTime.toDate()); + durations.add(new DurationPoint(Long.valueOf(timeBucket), secondsBetween(step, dateTime))); + break; + case DAY: + dateTime = dateTime.plusDays(1); + timeBucket = new SimpleDateFormat("yyyyMMdd").format(dateTime.toDate()); + durations.add(new DurationPoint(Long.valueOf(timeBucket), secondsBetween(step, dateTime))); + break; + case HOUR: + dateTime = dateTime.plusHours(1); + timeBucket = new SimpleDateFormat("yyyyMMddHH").format(dateTime.toDate()); + durations.add(new DurationPoint(Long.valueOf(timeBucket), secondsBetween(step, dateTime))); + break; + case MINUTE: + dateTime = dateTime.plusMinutes(1); + timeBucket = new SimpleDateFormat("yyyyMMddHHmm").format(dateTime.toDate()); + durations.add(new DurationPoint(Long.valueOf(timeBucket), secondsBetween(step, dateTime))); + break; + case SECOND: + dateTime = dateTime.plusSeconds(1); + timeBucket = new SimpleDateFormat("yyyyMMddHHmmss").format(dateTime.toDate()); + durations.add(new DurationPoint(Long.valueOf(timeBucket), secondsBetween(step, dateTime))); + break; + } + i++; + if (i > 500) { + throw new UnexpectedException("Duration data error, step: " + step.name() + ", start: " + start + ", end: " + end); + } + } + while (end != durations.get(durations.size() - 1).getPoint()); + + return durations; + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/ui/query/ApplicationQueryTestCase.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/ui/query/ApplicationQueryTestCase.java new file mode 100644 index 000000000..234a9c85d --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/ui/query/ApplicationQueryTestCase.java @@ -0,0 +1,139 @@ +/* + * 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.query; + +import java.text.ParseException; +import org.apache.skywalking.apm.collector.storage.ui.common.Duration; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.ui.service.ApplicationService; +import org.junit.Assert; +import org.junit.Test; +import org.mockito.Mockito; +import org.mockito.internal.util.reflection.Whitebox; + +/** + * @author peng-yongsheng + */ +public class ApplicationQueryTestCase { + + @Test + public void testGetAllApplicationByMonthDuration() throws ParseException { + ApplicationQuery query = new ApplicationQuery(null); + ApplicationService applicationService = Mockito.mock(ApplicationService.class); + Whitebox.setInternalState(query, "applicationService", applicationService); + + Mockito.when(applicationService.getApplications(Mockito.anyLong(), Mockito.anyLong())).then(invocation -> { + Object[] arguments = invocation.getArguments(); + Assert.assertEquals(20170100000000L, arguments[0]); + Assert.assertEquals(20170100000000L, arguments[1]); + return null; + }); + + Duration duration = new Duration(); + duration.setStart("2017-01"); + duration.setEnd("2017-01"); + duration.setStep(Step.MONTH); + + query.getAllApplication(duration); + } + + @Test + public void testGetAllApplicationByDayDuration() throws ParseException { + ApplicationQuery query = new ApplicationQuery(null); + ApplicationService applicationService = Mockito.mock(ApplicationService.class); + Whitebox.setInternalState(query, "applicationService", applicationService); + + Mockito.when(applicationService.getApplications(Mockito.anyLong(), Mockito.anyLong())).then(invocation -> { + Object[] arguments = invocation.getArguments(); + Assert.assertEquals(20170101000000L, arguments[0]); + Assert.assertEquals(20170101000000L, arguments[1]); + return null; + }); + + Duration duration = new Duration(); + duration.setStart("2017-01-01"); + duration.setEnd("2017-01-01"); + duration.setStep(Step.DAY); + + query.getAllApplication(duration); + } + + @Test + public void testGetAllApplicationByHourDuration() throws ParseException { + ApplicationQuery query = new ApplicationQuery(null); + ApplicationService applicationService = Mockito.mock(ApplicationService.class); + Whitebox.setInternalState(query, "applicationService", applicationService); + + Mockito.when(applicationService.getApplications(Mockito.anyLong(), Mockito.anyLong())).then(invocation -> { + Object[] arguments = invocation.getArguments(); + Assert.assertEquals(20170101010000L, arguments[0]); + Assert.assertEquals(20170101010000L, arguments[1]); + return null; + }); + + Duration duration = new Duration(); + duration.setStart("2017-01-01 01"); + duration.setEnd("2017-01-01 01"); + duration.setStep(Step.HOUR); + + query.getAllApplication(duration); + } + + @Test + public void testGetAllApplicationByMinuteDuration() throws ParseException { + ApplicationQuery query = new ApplicationQuery(null); + ApplicationService applicationService = Mockito.mock(ApplicationService.class); + Whitebox.setInternalState(query, "applicationService", applicationService); + + Mockito.when(applicationService.getApplications(Mockito.anyLong(), Mockito.anyLong())).then(invocation -> { + Object[] arguments = invocation.getArguments(); + Assert.assertEquals(20170101010100L, arguments[0]); + Assert.assertEquals(20170101010100L, arguments[1]); + return null; + }); + + Duration duration = new Duration(); + duration.setStart("2017-01-01 0101"); + duration.setEnd("2017-01-01 0101"); + duration.setStep(Step.MINUTE); + + query.getAllApplication(duration); + } + + @Test + public void testGetAllApplicationBySecondDuration() throws ParseException { + ApplicationQuery query = new ApplicationQuery(null); + ApplicationService applicationService = Mockito.mock(ApplicationService.class); + Whitebox.setInternalState(query, "applicationService", applicationService); + + Mockito.when(applicationService.getApplications(Mockito.anyLong(), Mockito.anyLong())).then(invocation -> { + Object[] arguments = invocation.getArguments(); + Assert.assertEquals(20170101010101L, arguments[0]); + Assert.assertEquals(20170101010101L, arguments[1]); + return null; + }); + + Duration duration = new Duration(); + duration.setStart("2017-01-01 010101"); + duration.setEnd("2017-01-01 010101"); + duration.setStep(Step.SECOND); + + query.getAllApplication(duration); + } +} diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/ui/utils/DurationUtilsTestCase.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/ui/utils/DurationUtilsTestCase.java new file mode 100644 index 000000000..1ab46eaab --- /dev/null +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/ui/utils/DurationUtilsTestCase.java @@ -0,0 +1,112 @@ +/* + * 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.utils; + +import java.text.ParseException; +import java.util.List; +import org.apache.skywalking.apm.collector.core.UnexpectedException; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.storage.utils.DurationPoint; +import org.junit.Assert; +import org.junit.Test; + +/** + * @author peng-yongsheng + */ +public class DurationUtilsTestCase { + + @Test + public void test() throws ParseException { + } + + @Test + public void testGetDurationPoints() throws ParseException { + List durationPoints = DurationUtils.INSTANCE.getDurationPoints(Step.MONTH, 201710, 201803); + Assert.assertEquals(6, durationPoints.size()); + Assert.assertEquals(201710L, durationPoints.get(0).getPoint()); + Assert.assertEquals(2678400, durationPoints.get(0).getSecondsBetween()); + Assert.assertEquals(201711L, durationPoints.get(1).getPoint()); + Assert.assertEquals(2592000, durationPoints.get(1).getSecondsBetween()); + Assert.assertEquals(201712L, durationPoints.get(2).getPoint()); + Assert.assertEquals(2678400, durationPoints.get(2).getSecondsBetween()); + Assert.assertEquals(201801L, durationPoints.get(3).getPoint()); + Assert.assertEquals(2678400, durationPoints.get(3).getSecondsBetween()); + Assert.assertEquals(201802L, durationPoints.get(4).getPoint()); + Assert.assertEquals(2419200, durationPoints.get(4).getSecondsBetween()); + Assert.assertEquals(201803L, durationPoints.get(5).getPoint()); + Assert.assertEquals(2678400, durationPoints.get(5).getSecondsBetween()); + + durationPoints = DurationUtils.INSTANCE.getDurationPoints(Step.DAY, 20180129, 20180202); + Assert.assertEquals(5, durationPoints.size()); + Assert.assertEquals(20180129L, durationPoints.get(0).getPoint()); + Assert.assertEquals(86400, durationPoints.get(0).getSecondsBetween()); + Assert.assertEquals(20180130L, durationPoints.get(1).getPoint()); + Assert.assertEquals(86400, durationPoints.get(1).getSecondsBetween()); + Assert.assertEquals(20180131L, durationPoints.get(2).getPoint()); + Assert.assertEquals(86400, durationPoints.get(2).getSecondsBetween()); + Assert.assertEquals(20180201L, durationPoints.get(3).getPoint()); + Assert.assertEquals(86400, durationPoints.get(3).getSecondsBetween()); + Assert.assertEquals(20180202L, durationPoints.get(4).getPoint()); + Assert.assertEquals(86400, durationPoints.get(4).getSecondsBetween()); + + durationPoints = DurationUtils.INSTANCE.getDurationPoints(Step.HOUR, 2018012922, 2018013002); + Assert.assertEquals(5, durationPoints.size()); + Assert.assertEquals(2018012922L, durationPoints.get(0).getPoint()); + Assert.assertEquals(3600, durationPoints.get(0).getSecondsBetween()); + Assert.assertEquals(2018012923L, durationPoints.get(1).getPoint()); + Assert.assertEquals(3600, durationPoints.get(1).getSecondsBetween()); + Assert.assertEquals(2018013000L, durationPoints.get(2).getPoint()); + Assert.assertEquals(3600, durationPoints.get(2).getSecondsBetween()); + Assert.assertEquals(2018013001L, durationPoints.get(3).getPoint()); + Assert.assertEquals(3600, durationPoints.get(3).getSecondsBetween()); + Assert.assertEquals(2018013002L, durationPoints.get(4).getPoint()); + Assert.assertEquals(3600, durationPoints.get(4).getSecondsBetween()); + + durationPoints = DurationUtils.INSTANCE.getDurationPoints(Step.MINUTE, 201801292258L, 201801292302L); + Assert.assertEquals(5, durationPoints.size()); + Assert.assertEquals(201801292258L, durationPoints.get(0).getPoint()); + Assert.assertEquals(60, durationPoints.get(0).getSecondsBetween()); + Assert.assertEquals(201801292259L, durationPoints.get(1).getPoint()); + Assert.assertEquals(60, durationPoints.get(1).getSecondsBetween()); + Assert.assertEquals(201801292300L, durationPoints.get(2).getPoint()); + Assert.assertEquals(60, durationPoints.get(2).getSecondsBetween()); + Assert.assertEquals(201801292301L, durationPoints.get(3).getPoint()); + Assert.assertEquals(60, durationPoints.get(3).getSecondsBetween()); + Assert.assertEquals(201801292302L, durationPoints.get(4).getPoint()); + Assert.assertEquals(60, durationPoints.get(4).getSecondsBetween()); + + durationPoints = DurationUtils.INSTANCE.getDurationPoints(Step.SECOND, 20180129225858L, 20180129225902L); + Assert.assertEquals(5, durationPoints.size()); + Assert.assertEquals(20180129225858L, durationPoints.get(0).getPoint()); + Assert.assertEquals(1, durationPoints.get(0).getSecondsBetween()); + Assert.assertEquals(20180129225859L, durationPoints.get(1).getPoint()); + Assert.assertEquals(1, durationPoints.get(1).getSecondsBetween()); + Assert.assertEquals(20180129225900L, durationPoints.get(2).getPoint()); + Assert.assertEquals(1, durationPoints.get(2).getSecondsBetween()); + Assert.assertEquals(20180129225901L, durationPoints.get(3).getPoint()); + Assert.assertEquals(1, durationPoints.get(3).getSecondsBetween()); + Assert.assertEquals(20180129225902L, durationPoints.get(4).getPoint()); + Assert.assertEquals(1, durationPoints.get(4).getSecondsBetween()); + } + + @Test(expected = UnexpectedException.class) + public void testGetDurationPointsErrorDuration() throws ParseException { + DurationUtils.INSTANCE.getDurationPoints(Step.MONTH, 20171001, 20180301); + } +} diff --git a/apm-collector/apm-collector-ui/pom.xml b/apm-collector/apm-collector-ui/pom.xml index e35d06d3b..a34095e71 100644 --- a/apm-collector/apm-collector-ui/pom.xml +++ b/apm-collector/apm-collector-ui/pom.xml @@ -31,6 +31,7 @@ pom collector-ui-define + collector-ui-graphql collector-ui-jetty-provider diff --git a/apm-protocol/apm-ui-protocol/pom.xml b/apm-protocol/apm-ui-protocol/pom.xml index 0e7e75784..ca05ad164 100644 --- a/apm-protocol/apm-ui-protocol/pom.xml +++ b/apm-protocol/apm-ui-protocol/pom.xml @@ -33,7 +33,7 @@ com.graphql-java graphql-java - 6.0 + 7.0 diff --git a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/alarm.graphqls b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/alarm.graphqls index ae1461b47..de8070040 100644 --- a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/alarm.graphqls +++ b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/alarm.graphqls @@ -4,6 +4,7 @@ type Alarm { } type AlarmItem { + id: ID! # Typical include: Application Code + cause type. This is a short description. title: String! # Include all related info to trigger this alarm. diff --git a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/application-layer.graphqls b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/application-layer.graphqls index 91d0b2d79..67f435073 100644 --- a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/application-layer.graphqls +++ b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/application-layer.graphqls @@ -10,7 +10,7 @@ type ApplicationNode implements Node { # The number of incoming calls callsPerSec: Long! # Unit: millisecond - responseTimePerSec: Int! + responseTimePerSec: Long! # ref: http://www.apdex.org/ # Max value is 1 # 2 Digits after floating point. @@ -33,10 +33,16 @@ type ConjecturalNode implements Node { type: String } +type Application { + id: ID! + name: String! + # The number of servers in the application code + numOfServer: Int! +} extend type Query { - getAllApplication(duration: Duration!): [ApplicationNode!]! + getAllApplication(duration: Duration!): [Application!]! getApplicationTopology(applicationId: ID!, duration: Duration!): Topology - getSlowService(applicationId: ID!, duration: Duration!, top: Int!): [ServiceInfo!]! + getSlowService(applicationId: ID!, duration: Duration!, top: Int!): [ServiceMetric!]! getServerThroughput(applicationId: ID!, duration: Duration!, top: Int!): [AppServerInfo!]! } diff --git a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/common.graphqls b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/common.graphqls index 04f21eeb3..21d9becd1 100644 --- a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/common.graphqls +++ b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/common.graphqls @@ -104,7 +104,7 @@ type Call { isAlert: Boolean # The protocol and tech stack used in this distributed call callType: String! - callsPerSec: Int! + callsPerSec: Long! # Unit: millisecond - responseTimePerSec: Int! + responseTimePerSec: Long! } diff --git a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/overview-layer.graphqls b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/overview-layer.graphqls index 04b1033a6..8aae1e2e4 100644 --- a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/overview-layer.graphqls +++ b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/overview-layer.graphqls @@ -32,6 +32,6 @@ extend type Query { getClusterBrief(duration: Duration!): ClusterBrief getAlarmTrend(duration: Duration!): AlarmTrend getConjecturalApps(duration: Duration!): ConjecturalAppBrief - getTopNSlowService(duration: Duration!, topN: Int!): [ServiceInfo!]! - getTopNServerThroughput(duration: Duration!, topN: Int!): [AppServerInfo!]! + getTopNSlowService(duration: Duration!, topN: Int!): [ServiceMetric!]! + getTopNServerThroughput(applicationId: Int, duration: Duration!, topN: Int!): [AppServerInfo!]! } diff --git a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/server-layer.graphqls b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/server-layer.graphqls index ddd41c680..b43e21225 100644 --- a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/server-layer.graphqls +++ b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/server-layer.graphqls @@ -6,12 +6,12 @@ type AppServerInfo { id: ID! name: String! + applicationId: Int! + applicationName: String tps: Int! - os: String host: String pid: Int - ipv4: String - ipv6: String + ipv4: [String!]! } type CPUTrend { diff --git a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/service-layer.graphqls b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/service-layer.graphqls index a5b44557a..cf4b73ee8 100644 --- a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/service-layer.graphqls +++ b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/service-layer.graphqls @@ -3,9 +3,8 @@ type ServiceNode implements Node { name: String! type: String # Success rate of all incoming requests. - # Max value is 100. - # 2 Digits after floating point. - sla: Float! + # Max value is 10000. + sla: Int! # The number of incoming calls calls: Long! # The number of services alerting @@ -15,6 +14,11 @@ type ServiceNode implements Node { type ServiceInfo { id: ID! name: String +} + +type ServiceMetric { + id: ID! + name: String # The unit is millisecond. avgResponseTime: Int! tps: Int! @@ -27,7 +31,7 @@ type TraceItem { } extend type Query { - searchService(keyword: String!, duration: Duration!, topN: Int!): [ServiceNode!]! + searchService(keyword: String!, topN: Int!): [ServiceInfo!]! getServiceResponseTimeTrend(serviceId: ID!, duration: Duration!): ResponseTimeTrend getServiceTPSTrend(serviceId: ID!, duration: Duration!): ThroughputTrend getServiceSLATrend(serviceId: ID!, duration: Duration!): SLATrend 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