You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2018/06/28 23:02:29 UTC

[GitHub] wu-sheng closed pull request #1406: [Collector] Add application id into service metric for UI

wu-sheng closed pull request #1406: [Collector] Add application id into service metric for UI
URL: https://github.com/apache/incubator-skywalking/pull/1406
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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
index bb420b966..caf75753d 100644
--- 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
@@ -22,26 +22,21 @@
  * @author peng-yongsheng
  */
 public class ServiceMetric {
-    private int id;
-    private String name;
+    private ServiceInfo service;
     private long calls;
     private int avgResponseTime;
     private int cpm;
 
-    public int getId() {
-        return id;
+    public ServiceMetric() {
+        this.service = new ServiceInfo();
     }
 
-    public void setId(int id) {
-        this.id = id;
+    public ServiceInfo getService() {
+        return service;
     }
 
-    public String getName() {
-        return name;
-    }
-
-    public void setName(String name) {
-        this.name = name;
+    public void setService(ServiceInfo service) {
+        this.service = service;
     }
 
     public int getAvgResponseTime() {
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
index 9f9c17be0..3ff859748 100644
--- 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
@@ -208,7 +208,8 @@ public void accept(DurationPoint durationPoint) {
             int serviceId = ((Number)searchHit.getSource().get(ServiceMetricTable.SERVICE_ID.getName())).intValue();
             if (!serviceIds.contains(serviceId)) {
                 ServiceMetric serviceMetric = new ServiceMetric();
-                serviceMetric.setId(serviceId);
+                serviceMetric.getService().setId(serviceId);
+                serviceMetric.getService().setApplicationId(serviceId);
                 serviceMetric.setCalls(((Number)searchHit.getSource().get(ServiceMetricTable.TRANSACTION_CALLS.getName())).longValue());
                 serviceMetric.setAvgResponseTime(((Number)searchHit.getSource().get(ServiceMetricTable.TRANSACTION_AVERAGE_DURATION.getName())).intValue());
                 serviceMetrics.add(serviceMetric);
diff --git a/apm-collector/apm-collector-storage/collector-storage-shardingjdbc-provider/src/main/java/org/apache/skywalking/apm/collector/storage/shardingjdbc/dao/ui/ServiceMetricShardingjdbcUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-shardingjdbc-provider/src/main/java/org/apache/skywalking/apm/collector/storage/shardingjdbc/dao/ui/ServiceMetricShardingjdbcUIDAO.java
index 348de86a2..a1b0233af 100644
--- a/apm-collector/apm-collector-storage/collector-storage-shardingjdbc-provider/src/main/java/org/apache/skywalking/apm/collector/storage/shardingjdbc/dao/ui/ServiceMetricShardingjdbcUIDAO.java
+++ b/apm-collector/apm-collector-storage/collector-storage-shardingjdbc-provider/src/main/java/org/apache/skywalking/apm/collector/storage/shardingjdbc/dao/ui/ServiceMetricShardingjdbcUIDAO.java
@@ -208,7 +208,8 @@ public ServiceMetricShardingjdbcUIDAO(ShardingjdbcClient client) {
                 int serviceId = rs.getInt(ServiceMetricTable.SERVICE_ID.getName());
                 if (!serviceIds.contains(serviceId)) {
                     ServiceMetric serviceMetric = new ServiceMetric();
-                    serviceMetric.setId(serviceId);
+                    serviceMetric.getService().setId(serviceId);
+                    serviceMetric.getService().setApplicationId(applicationId);
                     serviceMetric.setCalls(rs.getLong(ServiceMetricTable.TRANSACTION_CALLS.getName()));
                     serviceMetric.setAvgResponseTime(rs.getInt(ServiceMetricTable.TRANSACTION_AVERAGE_DURATION.getName()));
                     serviceMetrics.add(serviceMetric);
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 8dc09e70c..36cfb25fa 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
@@ -86,14 +86,16 @@ public ApplicationService(ModuleManager moduleManager) {
         long startSecondTimeBucket, long endSecondTimeBucket, Integer topN) {
         List<ServiceMetric> slowServices = serviceMetricUIDAO.getSlowService(applicationId, step, startTimeBucket, endTimeBucket, topN, MetricSource.Callee);
         slowServices.forEach(slowService -> {
-            ServiceName serviceName = serviceNameCacheService.get(slowService.getId());
+            ServiceName serviceName = serviceNameCacheService.get(slowService.getService().getId());
 
             try {
                 slowService.setCpm((int)(slowService.getCalls() / dateBetweenService.minutesBetween(serviceName.getApplicationId(), startSecondTimeBucket, endSecondTimeBucket)));
             } catch (ParseException e) {
                 logger.error(e.getMessage(), e);
             }
-            slowService.setName(serviceName.getServiceName());
+            slowService.getService().setApplicationId(serviceName.getApplicationId());
+            slowService.getService().setApplicationName(applicationCacheService.getApplicationById(serviceName.getApplicationId()).getApplicationCode());
+            slowService.getService().setName(serviceName.getServiceName());
         });
         return slowServices;
     }
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
index 94fda5fcc..8f2fa22a1 100644
--- 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
@@ -109,8 +109,10 @@ public SLATrend getServiceSLATrend(int serviceId, Step step, long startTimeBucke
         long startSecondTimeBucket, long endSecondTimeBucket, Integer topN) {
         List<ServiceMetric> slowServices = serviceMetricUIDAO.getSlowService(0, step, startTimeBucket, endTimeBucket, topN, MetricSource.Callee);
         slowServices.forEach(slowService -> {
-            ServiceName serviceName = serviceNameCacheService.get(slowService.getId());
-            slowService.setName(serviceName.getServiceName());
+            ServiceName serviceName = serviceNameCacheService.get(slowService.getService().getId());
+            slowService.getService().setName(serviceName.getServiceName());
+            slowService.getService().setApplicationId(serviceName.getApplicationId());
+            slowService.getService().setApplicationName(applicationCacheService.getApplicationById(serviceName.getApplicationId()).getApplicationCode());
             try {
                 slowService.setCpm((int)(slowService.getCalls() / dateBetweenService.minutesBetween(serviceName.getApplicationId(), startSecondTimeBucket, endSecondTimeBucket)));
             } catch (ParseException e) {
diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/ui/service/ApplicationServiceTest.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/ui/service/ApplicationServiceTest.java
index 64a38b156..c02ea58af 100644
--- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/ui/service/ApplicationServiceTest.java
+++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/ui/service/ApplicationServiceTest.java
@@ -115,9 +115,9 @@ public void getSlowService() throws ParseException {
         when(serviceMetricUIDAO.getSlowService(anyInt(), anyObject(), anyLong(), anyLong(), anyInt(), anyObject())).then(invocation -> {
             ServiceMetric serviceMetric = new ServiceMetric();
             serviceMetric.setCalls(200900);
-            serviceMetric.setName("test");
+            serviceMetric.getService().setName("test");
             serviceMetric.setAvgResponseTime(100);
-            serviceMetric.setId(1);
+            serviceMetric.getService().setId(1);
             return Collections.singletonList(serviceMetric);
         });
         when(serviceNameCacheService.get(anyInt())).then(invocation -> {
@@ -125,8 +125,9 @@ public void getSlowService() throws ParseException {
             serviceName.setServiceName("serviceName");
             return serviceName;
         });
+        mockCache();
         when(dateBetweenService.minutesBetween(anyInt(), anyLong(), anyLong())).then(invocation -> 20L);
-        List<ServiceMetric> slowService = applicationService.getSlowService(-1, duration.getStep(), startTimeBucket, endTimeBucket, startSecondTimeBucket, endSecondTimeBucket, 10);
+        List<ServiceMetric> slowService = applicationService.getSlowService(1, duration.getStep(), startTimeBucket, endTimeBucket, startSecondTimeBucket, endSecondTimeBucket, 10);
         Assert.assertTrue(slowService.get(0).getCpm() > 0);
     }
 
diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/ui/service/ServiceNameServiceTest.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/ui/service/ServiceNameServiceTest.java
index 3a01925e9..358c92aa6 100644
--- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/ui/service/ServiceNameServiceTest.java
+++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/test/java/org/apache/skywalking/apm/collector/ui/service/ServiceNameServiceTest.java
@@ -19,7 +19,7 @@
 
 import java.text.ParseException;
 import java.util.*;
-import org.apache.skywalking.apm.collector.cache.service.ServiceNameCacheService;
+import org.apache.skywalking.apm.collector.cache.service.*;
 import org.apache.skywalking.apm.collector.core.module.*;
 import org.apache.skywalking.apm.collector.storage.dao.ui.*;
 import org.apache.skywalking.apm.collector.storage.table.register.ServiceName;
@@ -42,6 +42,7 @@
     private IServiceNameServiceUIDAO serviceNameServiceUIDAO;
     private IServiceMetricUIDAO serviceMetricUIDAO;
     private ServiceNameCacheService serviceNameCacheService;
+    private ApplicationCacheService applicationCacheService;
     private DateBetweenService dateBetweenService;
     private ServiceNameService serverNameService;
     private Duration duration;
@@ -56,9 +57,11 @@ public void setUp() throws Exception {
         when(moduleManager.find(anyString())).then(invocation -> new MockModule());
         serverNameService = new ServiceNameService(moduleManager);
         serviceNameCacheService = mock(ServiceNameCacheService.class);
+        applicationCacheService = mock(ApplicationCacheService.class);
         serviceMetricUIDAO = mock(IServiceMetricUIDAO.class);
         dateBetweenService = mock(DateBetweenService.class);
         Whitebox.setInternalState(serverNameService, "serviceNameCacheService", serviceNameCacheService);
+        Whitebox.setInternalState(serverNameService, "applicationCacheService", applicationCacheService);
         Whitebox.setInternalState(serverNameService, "serviceMetricUIDAO", serviceMetricUIDAO);
         Whitebox.setInternalState(serverNameService, "dateBetweenService", dateBetweenService);
         duration = new Duration();
@@ -106,9 +109,10 @@ public void getSlowService() throws ParseException {
         when(serviceMetricUIDAO.getSlowService(anyInt(), anyObject(), anyLong(), anyLong(), anyInt(), anyObject())).then(invocation -> {
             ServiceMetric serviceMetric = new ServiceMetric();
             serviceMetric.setCalls(200901);
-            serviceMetric.setName("test");
+            serviceMetric.getService().setName("test");
             serviceMetric.setAvgResponseTime(100);
-            serviceMetric.setId(1);
+            serviceMetric.getService().setApplicationId(1);
+            serviceMetric.getService().setId(1);
             return Collections.singletonList(serviceMetric);
         });
         when(dateBetweenService.minutesBetween(anyInt(), anyLong(), anyLong())).then(invocation -> 20L);
@@ -121,7 +125,15 @@ private void mockCache() {
         Mockito.when(serviceNameCacheService.get(anyInt())).then(invocation -> {
             ServiceName serviceName = new ServiceName();
             serviceName.setServiceName("test_name");
+            serviceName.setApplicationId(1);
             return serviceName;
         });
+
+        Mockito.when(applicationCacheService.getApplicationById(anyInt())).then(invocation -> {
+            org.apache.skywalking.apm.collector.storage.table.register.Application application = new org.apache.skywalking.apm.collector.storage.table.register.Application();
+            application.setApplicationId(1);
+            application.setApplicationCode("test");
+            return application;
+        });
     }
 }
\ No newline at end of file
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 40ab994b9..330328cf5 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
@@ -35,8 +35,7 @@ type ServiceInfo {
 }
 
 type ServiceMetric {
-    id: ID!
-    name: String
+    service: ServiceInfo!
     # The unit is millisecond.
     avgResponseTime: Int!
     cpm: Int!


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services