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/09 11:40:06 UTC

[GitHub] wu-sheng closed pull request #1335: [Collector]Add application name in service search view

wu-sheng closed pull request #1335: [Collector]Add application name in service search view
URL: https://github.com/apache/incubator-skywalking/pull/1335
 
 
   

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/ServiceInfo.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/service/ServiceInfo.java
index 808fe25f3..1a2572808 100644
--- 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
@@ -24,6 +24,8 @@
 public class ServiceInfo {
     private int id;
     private String name;
+    private int applicationId;
+    private String applicationName;
 
     public int getId() {
         return id;
@@ -40,4 +42,20 @@ public String getName() {
     public void setName(String name) {
         this.name = name;
     }
+
+    public int getApplicationId() {
+        return applicationId;
+    }
+
+    public void setApplicationId(int applicationId) {
+        this.applicationId = applicationId;
+    }
+
+    public String getApplicationName() {
+        return applicationName;
+    }
+
+    public void setApplicationName(String applicationName) {
+        this.applicationName = applicationName;
+    }
 }
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
index 5f7cde54d..d28846a3d 100644
--- 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
@@ -83,6 +83,7 @@ public ServiceNameServiceEsUIDAO(ElasticSearchClient client) {
             ServiceInfo serviceInfo = new ServiceInfo();
             serviceInfo.setId(((Number)searchHit.getSource().get(ServiceNameTable.SERVICE_ID.getName())).intValue());
             serviceInfo.setName((String)searchHit.getSource().get(ServiceNameTable.SERVICE_NAME.getName()));
+            serviceInfo.setApplicationId(((Number)searchHit.getSource().get(ServiceNameTable.APPLICATION_ID.getName())).intValue());
             serviceInfos.add(serviceInfo);
         }
         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/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
index 167b8f6a8..16923f2a6 100644
--- 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
@@ -57,8 +57,8 @@ public ServiceNameServiceH2UIDAO(H2Client client) {
 
     @Override
     public List<ServiceInfo> searchService(String keyword, int applicationId, long startTimeMillis, int topN) {
-        String dynamicSql = "select {0},{1} from {2} where {3} like ? and {4} = ? and {5} = ? and {6} >= ? limit ?";
-        String sql = SqlBuilder.buildSql(dynamicSql, ServiceNameTable.SERVICE_ID.getName(), ServiceNameTable.SERVICE_NAME.getName(), ServiceNameTable.TABLE, ServiceNameTable.SERVICE_NAME.getName(), ServiceNameTable.SRC_SPAN_TYPE.getName(), ServiceNameTable.APPLICATION_ID.getName(), ServiceNameTable.HEARTBEAT_TIME.getName());
+        String dynamicSql = "select {0},{1},{2} from {3} where {4} like ? and {5} = ? and {6} = ? and {7} >= ? limit ?";
+        String sql = SqlBuilder.buildSql(dynamicSql, ServiceNameTable.SERVICE_ID.getName(), ServiceNameTable.SERVICE_NAME.getName(), ServiceNameTable.APPLICATION_ID.getName(), ServiceNameTable.TABLE, ServiceNameTable.SERVICE_NAME.getName(), ServiceNameTable.SRC_SPAN_TYPE.getName(), ServiceNameTable.APPLICATION_ID.getName(), ServiceNameTable.HEARTBEAT_TIME.getName());
         Object[] params = new Object[] {keyword, SpanType.Entry_VALUE, applicationId, startTimeMillis, topN};
 
         List<ServiceInfo> serviceInfos = new LinkedList<>();
@@ -67,6 +67,7 @@ public ServiceNameServiceH2UIDAO(H2Client client) {
                 ServiceInfo serviceInfo = new ServiceInfo();
                 serviceInfo.setId(rs.getInt(ServiceNameTable.SERVICE_ID.getName()));
                 serviceInfo.setName(rs.getString(ServiceNameTable.SERVICE_NAME.getName()));
+                serviceInfo.setApplicationId(rs.getInt(ServiceNameTable.APPLICATION_ID.getName()));
                 serviceInfos.add(serviceInfo);
             }
         } catch (SQLException | H2ClientException e) {
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 964317f22..94fda5fcc 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
@@ -19,14 +19,15 @@
 package org.apache.skywalking.apm.collector.ui.service;
 
 import java.text.ParseException;
-import java.util.List;
+import java.util.*;
 import org.apache.skywalking.apm.collector.cache.CacheModule;
-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.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.*;
 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.table.register.*;
 import org.apache.skywalking.apm.collector.storage.ttl.ITTLConfigService;
 import org.apache.skywalking.apm.collector.storage.ui.common.*;
 import org.apache.skywalking.apm.collector.storage.ui.service.*;
@@ -41,6 +42,7 @@
 
     private static final Logger logger = LoggerFactory.getLogger(ServiceNameService.class);
 
+    private final ApplicationCacheService applicationCacheService;
     private final IServiceNameServiceUIDAO serviceNameServiceUIDAO;
     private final IServiceMetricUIDAO serviceMetricUIDAO;
     private final ServiceNameCacheService serviceNameCacheService;
@@ -48,6 +50,7 @@
     private final ITTLConfigService configService;
 
     public ServiceNameService(ModuleManager moduleManager) {
+        this.applicationCacheService = moduleManager.find(CacheModule.NAME).getService(ApplicationCacheService.class);
         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);
@@ -60,7 +63,16 @@ public int getCount() {
     }
 
     public List<ServiceInfo> searchService(String keyword, int applicationId, int topN) {
-        return serviceNameServiceUIDAO.searchService(keyword, applicationId, startTimeMillis(), topN);
+        List<ServiceInfo> services = serviceNameServiceUIDAO.searchService(keyword, applicationId, startTimeMillis(), topN);
+        services.forEach(service -> {
+            Application application = applicationCacheService.getApplicationById(service.getApplicationId());
+            if (Objects.nonNull(application)) {
+                service.setApplicationName(application.getApplicationCode());
+            } else {
+                service.setApplicationName(Const.EMPTY_STRING);
+            }
+        });
+        return services;
     }
 
     private long startTimeMillis() {
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 a33ad3d32..40ab994b9 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
@@ -30,6 +30,8 @@ type ServiceNode implements Node {
 type ServiceInfo {
     id: ID!
     name: String
+    applicationId: ID!
+    applicationName: String
 }
 
 type ServiceMetric {


 

----------------------------------------------------------------
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