This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-skywalking.git


The following commit(s) were added to refs/heads/master by this push:
     new 621ed2c  [Collector] Add application id into service metric for UI 
(#1406)
621ed2c is described below

commit 621ed2c0e38ec08a6446d1a1c32e4a81a96e82c8
Author: 彭勇升 pengys <8082...@qq.com>
AuthorDate: Fri Jun 29 07:02:27 2018 +0800

    [Collector] Add application id into service metric for UI (#1406)
    
    * #1405
    Add application id into service metric for the page jump from overview page 
to service page.
    
    * Fixed test case error.
---
 .../collector/storage/ui/service/ServiceMetric.java   | 19 +++++++------------
 .../storage/es/dao/ui/ServiceMetricEsUIDAO.java       |  3 ++-
 .../dao/ui/ServiceMetricShardingjdbcUIDAO.java        |  3 ++-
 .../apm/collector/ui/service/ApplicationService.java  |  6 ++++--
 .../apm/collector/ui/service/ServiceNameService.java  |  6 ++++--
 .../collector/ui/service/ApplicationServiceTest.java  |  7 ++++---
 .../collector/ui/service/ServiceNameServiceTest.java  | 18 +++++++++++++++---
 .../main/resources/ui-graphql/service-layer.graphqls  |  3 +--
 8 files changed, 39 insertions(+), 26 deletions(-)

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 bb420b9..caf7575 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 @@ package 
org.apache.skywalking.apm.collector.storage.ui.service;
  * @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 9f9c17b..3ff8597 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 class ServiceMetricEsUIDAO extends EsDAO implements 
IServiceMetricUIDAO {
             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 348de86..a1b0233 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 class ServiceMetricShardingjdbcUIDAO extends 
ShardingjdbcDAO implements I
                 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 8dc09e7..36cfb25 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 class ApplicationService {
         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 94fda5f..8f2fa22 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 class ServiceNameService {
         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 64a38b1..c02ea58 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 class ApplicationServiceTest {
         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 class ApplicationServiceTest {
             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 3a01925..358c92a 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 @@ package org.apache.skywalking.apm.collector.ui.service;
 
 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 @@ public class ServiceNameServiceTest {
     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 class ServiceNameServiceTest {
         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 class ServiceNameServiceTest {
         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 @@ public class ServiceNameServiceTest {
         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 40ab994..330328c 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!

Reply via email to