Commit 5f81c006 authored by 彭勇升 pengys's avatar 彭勇升 pengys Committed by 吴晟
Browse files

#1176 (#1335)

Add application id and code into ServiceInfo.
parent d56ad5ec
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ package org.apache.skywalking.apm.collector.storage.ui.service;
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 class ServiceInfo {
    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;
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ public class ServiceNameServiceEsUIDAO extends EsDAO implements IServiceNameServ
            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;
+3 −2
Original line number Diff line number Diff line
@@ -57,8 +57,8 @@ public class ServiceNameServiceH2UIDAO extends H2DAO implements IServiceNameServ

    @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 class ServiceNameServiceH2UIDAO extends H2DAO implements IServiceNameServ
                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) {
+16 −4
Original line number Diff line number Diff line
@@ -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 @@ public class ServiceNameService {

    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 @@ public class ServiceNameService {
    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 class ServiceNameService {
    }

    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() {
+2 −0
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@ type ServiceNode implements Node {
type ServiceInfo {
    id: ID!
    name: String
    applicationId: ID!
    applicationName: String
}

type ServiceMetric {