You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2018/10/28 15:44:40 UTC

[incubator-skywalking] branch bug-fix created (now 62a99fb)

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

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


      at 62a99fb  Keep service instance register based on UUID, but change name to a meaning string.

This branch includes the following new commits:

     new 62a99fb  Keep service instance register based on UUID, but change name to a meaning string.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[incubator-skywalking] 01/01: Keep service instance register based on UUID, but change name to a meaning string.

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 62a99fb06c51dc14abf4e19c8eacd02c4d9b8ccb
Author: Wu Sheng <wu...@foxmail.com>
AuthorDate: Sun Oct 28 23:44:24 2018 +0800

    Keep service instance register based on UUID, but change name to a meaning string.
---
 .../core/cache/ServiceInstanceInventoryCache.java  |  8 +++---
 .../core/register/ServiceInstanceInventory.java    | 30 +++++++++++++++-------
 .../service/IServiceInstanceInventoryRegister.java |  2 +-
 .../service/ServiceInstanceInventoryRegister.java  |  7 ++---
 .../cache/IServiceInstanceInventoryCacheDAO.java   |  2 +-
 .../mesh/ServiceMeshMetricDataDecorator.java       | 12 ++++++---
 .../v5/grpc/InstanceDiscoveryServiceHandler.java   | 17 +++++++++++-
 .../v5/rest/InstanceDiscoveryServletHandler.java   | 17 +++++++++++-
 .../cache/ServiceInstanceInventoryCacheDAO.java    |  4 +--
 .../h2/dao/H2ServiceInstanceInventoryCacheDAO.java |  4 +--
 10 files changed, 75 insertions(+), 28 deletions(-)

diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cache/ServiceInstanceInventoryCache.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cache/ServiceInstanceInventoryCache.java
index 5fc05aa..deac60b 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cache/ServiceInstanceInventoryCache.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/cache/ServiceInstanceInventoryCache.java
@@ -80,13 +80,13 @@ public class ServiceInstanceInventoryCache implements Service {
         return serviceInstanceInventory;
     }
 
-    public int getServiceInstanceId(int serviceId, String serviceInstanceName) {
-        Integer serviceInstanceId = serviceInstanceNameCache.getIfPresent(ServiceInstanceInventory.buildId(serviceId, serviceInstanceName));
+    public int getServiceInstanceId(int serviceId, String uuid) {
+        Integer serviceInstanceId = serviceInstanceNameCache.getIfPresent(ServiceInstanceInventory.buildId(serviceId, uuid));
 
         if (Objects.isNull(serviceInstanceId) || serviceInstanceId == Const.NONE) {
-            serviceInstanceId = getCacheDAO().getServiceInstanceId(serviceId, serviceInstanceName);
+            serviceInstanceId = getCacheDAO().getServiceInstanceId(serviceId, uuid);
             if (serviceId != Const.NONE) {
-                serviceInstanceNameCache.put(ServiceInstanceInventory.buildId(serviceId, serviceInstanceName), serviceInstanceId);
+                serviceInstanceNameCache.put(ServiceInstanceInventory.buildId(serviceId, uuid), serviceInstanceId);
             }
         }
         return serviceInstanceId;
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/register/ServiceInstanceInventory.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/register/ServiceInstanceInventory.java
index 4dfdd54..ba21e3c 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/register/ServiceInstanceInventory.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/register/ServiceInstanceInventory.java
@@ -20,15 +20,20 @@ package org.apache.skywalking.oap.server.core.register;
 
 import com.google.gson.Gson;
 import com.google.gson.reflect.TypeToken;
-import java.util.*;
-import lombok.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import lombok.Getter;
+import lombok.Setter;
 import org.apache.skywalking.oap.server.core.Const;
 import org.apache.skywalking.oap.server.core.register.annotation.InventoryType;
 import org.apache.skywalking.oap.server.core.remote.annotation.StreamData;
 import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData;
 import org.apache.skywalking.oap.server.core.source.Scope;
 import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
-import org.apache.skywalking.oap.server.core.storage.annotation.*;
+import org.apache.skywalking.oap.server.core.storage.annotation.Column;
+import org.apache.skywalking.oap.server.core.storage.annotation.StorageEntity;
 import org.apache.skywalking.oap.server.library.util.BooleanUtils;
 
 /**
@@ -42,6 +47,7 @@ public class ServiceInstanceInventory extends RegisterSource {
     public static final String MODEL_NAME = "service_instance_inventory";
 
     public static final String NAME = "name";
+    public static final String INSTANCE_UUID = "instance_uuid";
     public static final String SERVICE_ID = "service_id";
     private static final String IS_ADDRESS = "is_address";
     private static final String ADDRESS_ID = "address_id";
@@ -51,7 +57,9 @@ public class ServiceInstanceInventory extends RegisterSource {
     public static final String IPV4S = "ipv4s";
     public static final String LANGUAGE = "language";
 
-    @Setter @Getter @Column(columnName = NAME, matchQuery = true) private String name = Const.EMPTY_STRING;
+    @Setter @Getter @Column(columnName = INSTANCE_UUID, matchQuery = true)
+    private String instanceUUID = Const.EMPTY_STRING;
+    @Setter @Getter @Column(columnName = NAME) private String name = Const.EMPTY_STRING;
     @Setter @Getter @Column(columnName = SERVICE_ID) private int serviceId;
     @Setter @Getter @Column(columnName = LANGUAGE) private int language;
     @Setter @Getter @Column(columnName = IS_ADDRESS) private int isAddress;
@@ -61,8 +69,8 @@ public class ServiceInstanceInventory extends RegisterSource {
     @Setter @Getter @Column(columnName = PROCESS_NO) private int processNo;
     @Setter @Getter @Column(columnName = IPV4S) private String ipv4s;
 
-    public static String buildId(int serviceId, String serviceInstanceName) {
-        return serviceId + Const.ID_SPLIT + serviceInstanceName + Const.ID_SPLIT + BooleanUtils.FALSE + Const.ID_SPLIT + Const.NONE;
+    public static String buildId(int serviceId, String uuid) {
+        return serviceId + Const.ID_SPLIT + uuid + Const.ID_SPLIT + BooleanUtils.FALSE + Const.ID_SPLIT + Const.NONE;
     }
 
     public static String buildId(int serviceId, int addressId) {
@@ -73,14 +81,14 @@ public class ServiceInstanceInventory extends RegisterSource {
         if (BooleanUtils.TRUE == isAddress) {
             return buildId(serviceId, addressId);
         } else {
-            return buildId(serviceId, name);
+            return buildId(serviceId, instanceUUID);
         }
     }
 
     @Override public int hashCode() {
         int result = 17;
         result = 31 * result + serviceId;
-        result = 31 * result + name.hashCode();
+        result = 31 * result + instanceUUID.hashCode();
         result = 31 * result + isAddress;
         result = 31 * result + addressId;
         return result;
@@ -97,7 +105,7 @@ public class ServiceInstanceInventory extends RegisterSource {
         ServiceInstanceInventory source = (ServiceInstanceInventory)obj;
         if (serviceId != source.getServiceId())
             return false;
-        if (!name.equals(source.getName()))
+        if (!instanceUUID.equals(source.getInstanceUUID()))
             return false;
         if (isAddress != source.getIsAddress())
             return false;
@@ -123,6 +131,7 @@ public class ServiceInstanceInventory extends RegisterSource {
         remoteBuilder.setDataStrings(1, osName);
         remoteBuilder.setDataStrings(2, hostName);
         remoteBuilder.setDataStrings(3, ipv4s);
+        remoteBuilder.setDataStrings(4, instanceUUID);
         return remoteBuilder;
     }
 
@@ -141,6 +150,7 @@ public class ServiceInstanceInventory extends RegisterSource {
         setOsName(remoteData.getDataStrings(1));
         setHostName(remoteData.getDataStrings(2));
         setIpv4s(remoteData.getDataStrings(3));
+        setInstanceUUID(remoteData.getDataStrings(4));
     }
 
     @Override public int remoteHashCode() {
@@ -165,6 +175,7 @@ public class ServiceInstanceInventory extends RegisterSource {
             inventory.setOsName((String)dbMap.get(OS_NAME));
             inventory.setHostName((String)dbMap.get(HOST_NAME));
             inventory.setIpv4s((String)dbMap.get(IPV4S));
+            inventory.setInstanceUUID((String)dbMap.get(INSTANCE_UUID));
             return inventory;
         }
 
@@ -184,6 +195,7 @@ public class ServiceInstanceInventory extends RegisterSource {
             map.put(OS_NAME, storageData.getOsName());
             map.put(HOST_NAME, storageData.getHostName());
             map.put(IPV4S, storageData.getIpv4s());
+            map.put(INSTANCE_UUID, storageData.getInstanceUUID());
             return map;
         }
     }
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/register/service/IServiceInstanceInventoryRegister.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/register/service/IServiceInstanceInventoryRegister.java
index 7ed7b4e..fa55825 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/register/service/IServiceInstanceInventoryRegister.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/register/service/IServiceInstanceInventoryRegister.java
@@ -26,7 +26,7 @@ import org.apache.skywalking.oap.server.library.module.Service;
  */
 public interface IServiceInstanceInventoryRegister extends Service {
 
-    int getOrCreate(int serviceId, String serviceInstanceName, long registerTime,
+    int getOrCreate(int serviceId, String serviceInstanceName, String uuid, long registerTime,
         ServiceInstanceInventory.AgentOsInfo osInfo);
 
     int getOrCreate(int serviceId, int addressId, long registerTime);
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/register/service/ServiceInstanceInventoryRegister.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/register/service/ServiceInstanceInventoryRegister.java
index af02992..8bb47a2 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/register/service/ServiceInstanceInventoryRegister.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/register/service/ServiceInstanceInventoryRegister.java
@@ -50,18 +50,19 @@ public class ServiceInstanceInventoryRegister implements IServiceInstanceInvento
         return serviceInstanceInventoryCache;
     }
 
-    @Override public int getOrCreate(int serviceId, String serviceInstanceName, long registerTime,
+    @Override public int getOrCreate(int serviceId, String serviceInstanceName, String uuid, long registerTime,
         ServiceInstanceInventory.AgentOsInfo osInfo) {
         if (logger.isDebugEnabled()) {
-            logger.debug("Get or create service instance by service instance name, service id: {}, service instance name: {}, registerTime: {}", serviceId, serviceInstanceName, registerTime);
+            logger.debug("Get or create service instance by service instance name, service id: {}, service instance name: {},uuid: {}, registerTime: {}", serviceId, serviceInstanceName, uuid, registerTime);
         }
 
-        int serviceInstanceId = getServiceInstanceInventoryCache().getServiceInstanceId(serviceId, serviceInstanceName);
+        int serviceInstanceId = getServiceInstanceInventoryCache().getServiceInstanceId(serviceId, uuid);
 
         if (serviceInstanceId == Const.NONE) {
             ServiceInstanceInventory serviceInstanceInventory = new ServiceInstanceInventory();
             serviceInstanceInventory.setServiceId(serviceId);
             serviceInstanceInventory.setName(serviceInstanceName);
+            serviceInstanceInventory.setInstanceUUID(uuid);
             serviceInstanceInventory.setIsAddress(BooleanUtils.FALSE);
             serviceInstanceInventory.setAddressId(Const.NONE);
 
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/cache/IServiceInstanceInventoryCacheDAO.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/cache/IServiceInstanceInventoryCacheDAO.java
index 9b75afa..11e3ee1 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/cache/IServiceInstanceInventoryCacheDAO.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/cache/IServiceInstanceInventoryCacheDAO.java
@@ -28,7 +28,7 @@ public interface IServiceInstanceInventoryCacheDAO extends DAO {
 
     ServiceInstanceInventory get(int serviceInstanceId);
 
-    int getServiceInstanceId(int serviceId, String serviceInstanceName);
+    int getServiceInstanceId(int serviceId, String uuid);
 
     int getServiceInstanceId(int serviceId, int addressId);
 }
diff --git a/oap-server/server-receiver-plugin/skywalking-mesh-receiver-plugin/src/main/java/org/apache/skywalking/aop/server/receiver/mesh/ServiceMeshMetricDataDecorator.java b/oap-server/server-receiver-plugin/skywalking-mesh-receiver-plugin/src/main/java/org/apache/skywalking/aop/server/receiver/mesh/ServiceMeshMetricDataDecorator.java
index e896d4b..887ecde 100644
--- a/oap-server/server-receiver-plugin/skywalking-mesh-receiver-plugin/src/main/java/org/apache/skywalking/aop/server/receiver/mesh/ServiceMeshMetricDataDecorator.java
+++ b/oap-server/server-receiver-plugin/skywalking-mesh-receiver-plugin/src/main/java/org/apache/skywalking/aop/server/receiver/mesh/ServiceMeshMetricDataDecorator.java
@@ -53,8 +53,10 @@ public class ServiceMeshMetricDataDecorator {
         }
         sourceServiceInstanceId = origin.getSourceServiceInstanceId();
         if (sourceServiceId != Const.NONE && sourceServiceInstanceId == Const.NONE) {
-            sourceServiceInstanceId = CoreRegisterLinker.getServiceInstanceInventoryRegister().getOrCreate(sourceServiceId, origin.getSourceServiceInstance(), origin.getEndTime(),
-                getOSInfoForMesh(origin.getSourceServiceInstance()));
+            sourceServiceInstanceId = CoreRegisterLinker.getServiceInstanceInventoryRegister()
+                .getOrCreate(sourceServiceId, origin.getSourceServiceInstance(), origin.getSourceServiceInstance(),
+                    origin.getEndTime(),
+                    getOSInfoForMesh(origin.getSourceServiceInstance()));
             if (sourceServiceInstanceId != Const.NONE) {
                 getNewDataBuilder().setSourceServiceInstanceId(sourceServiceInstanceId);
             } else {
@@ -72,8 +74,10 @@ public class ServiceMeshMetricDataDecorator {
         }
         destServiceInstanceId = origin.getDestServiceInstanceId();
         if (destServiceId != Const.NONE && destServiceInstanceId == Const.NONE) {
-            destServiceInstanceId = CoreRegisterLinker.getServiceInstanceInventoryRegister().getOrCreate(destServiceId, origin.getDestServiceInstance(), origin.getEndTime(),
-                getOSInfoForMesh(origin.getSourceServiceInstance()));
+            destServiceInstanceId = CoreRegisterLinker.getServiceInstanceInventoryRegister()
+                .getOrCreate(destServiceId, origin.getDestServiceInstance(), origin.getDestServiceInstance(),
+                    origin.getEndTime(),
+                    getOSInfoForMesh(origin.getSourceServiceInstance()));
             if (destServiceInstanceId != Const.NONE) {
                 getNewDataBuilder().setDestServiceInstanceId(destServiceInstanceId);
             } else {
diff --git a/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/grpc/InstanceDiscoveryServiceHandler.java b/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/grpc/InstanceDiscoveryServiceHandler.java
index 7e5364d..378162e 100644
--- a/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/grpc/InstanceDiscoveryServiceHandler.java
+++ b/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/grpc/InstanceDiscoveryServiceHandler.java
@@ -23,10 +23,13 @@ import java.util.Objects;
 import org.apache.skywalking.apm.network.language.agent.*;
 import org.apache.skywalking.oap.server.core.CoreModule;
 import org.apache.skywalking.oap.server.core.cache.ServiceInstanceInventoryCache;
+import org.apache.skywalking.oap.server.core.cache.ServiceInventoryCache;
 import org.apache.skywalking.oap.server.core.register.ServiceInstanceInventory;
+import org.apache.skywalking.oap.server.core.register.ServiceInventory;
 import org.apache.skywalking.oap.server.core.register.service.*;
 import org.apache.skywalking.oap.server.library.module.ModuleManager;
 import org.apache.skywalking.oap.server.library.server.grpc.GRPCHandler;
+import org.apache.skywalking.oap.server.library.util.StringUtils;
 import org.slf4j.*;
 
 /**
@@ -36,11 +39,13 @@ public class InstanceDiscoveryServiceHandler extends InstanceDiscoveryServiceGrp
 
     private static final Logger logger = LoggerFactory.getLogger(InstanceDiscoveryServiceHandler.class);
 
+    private final ServiceInventoryCache serviceInventoryCache;
     private final ServiceInstanceInventoryCache serviceInstanceInventoryCache;
     private final IServiceInventoryRegister serviceInventoryRegister;
     private final IServiceInstanceInventoryRegister serviceInstanceInventoryRegister;
 
     public InstanceDiscoveryServiceHandler(ModuleManager moduleManager) {
+        this.serviceInventoryCache = moduleManager.find(CoreModule.NAME).getService(ServiceInventoryCache.class);
         this.serviceInstanceInventoryCache = moduleManager.find(CoreModule.NAME).getService(ServiceInstanceInventoryCache.class);
         this.serviceInventoryRegister = moduleManager.find(CoreModule.NAME).getService(IServiceInventoryRegister.class);
         this.serviceInstanceInventoryRegister = moduleManager.find(CoreModule.NAME).getService(IServiceInstanceInventoryRegister.class);
@@ -56,7 +61,17 @@ public class InstanceDiscoveryServiceHandler extends InstanceDiscoveryServiceGrp
         agentOsInfo.setProcessNo(osinfo.getProcessNo());
         agentOsInfo.getIpv4s().addAll(osinfo.getIpv4SList());
 
-        int serviceInstanceId = serviceInstanceInventoryRegister.getOrCreate(request.getApplicationId(), request.getAgentUUID(), request.getRegisterTime(), agentOsInfo);
+        ServiceInventory serviceInventory = serviceInventoryCache.get(request.getApplicationId());
+
+        String instanceName = serviceInventory.getName();
+        if (osinfo.getProcessNo() != 0) {
+            instanceName += "-pid:" + osinfo.getProcessNo();
+        }
+        if (StringUtils.isNotEmpty(osinfo.getHostname())) {
+            instanceName += "@" + osinfo.getHostname();
+        }
+
+        int serviceInstanceId = serviceInstanceInventoryRegister.getOrCreate(request.getApplicationId(), instanceName, request.getAgentUUID(), request.getRegisterTime(), agentOsInfo);
         ApplicationInstanceMapping.Builder builder = ApplicationInstanceMapping.newBuilder();
         builder.setApplicationId(request.getApplicationId());
         builder.setApplicationInstanceId(serviceInstanceId);
diff --git a/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/rest/InstanceDiscoveryServletHandler.java b/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/rest/InstanceDiscoveryServletHandler.java
index c2edc07..4b8ba9e 100644
--- a/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/rest/InstanceDiscoveryServletHandler.java
+++ b/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v5/rest/InstanceDiscoveryServletHandler.java
@@ -22,10 +22,13 @@ import com.google.gson.*;
 import java.io.IOException;
 import javax.servlet.http.HttpServletRequest;
 import org.apache.skywalking.oap.server.core.CoreModule;
+import org.apache.skywalking.oap.server.core.cache.ServiceInventoryCache;
 import org.apache.skywalking.oap.server.core.register.ServiceInstanceInventory;
+import org.apache.skywalking.oap.server.core.register.ServiceInventory;
 import org.apache.skywalking.oap.server.core.register.service.IServiceInstanceInventoryRegister;
 import org.apache.skywalking.oap.server.library.module.ModuleManager;
 import org.apache.skywalking.oap.server.library.server.jetty.*;
+import org.apache.skywalking.oap.server.library.util.StringUtils;
 import org.slf4j.*;
 
 /**
@@ -36,6 +39,7 @@ public class InstanceDiscoveryServletHandler extends JettyJsonHandler {
     private static final Logger logger = LoggerFactory.getLogger(InstanceDiscoveryServletHandler.class);
 
     private final IServiceInstanceInventoryRegister serviceInstanceInventoryRegister;
+    private final ServiceInventoryCache serviceInventoryCache;
     private final Gson gson = new Gson();
 
     private static final String APPLICATION_ID = "ai";
@@ -45,6 +49,7 @@ public class InstanceDiscoveryServletHandler extends JettyJsonHandler {
     private static final String OS_INFO = "oi";
 
     public InstanceDiscoveryServletHandler(ModuleManager moduleManager) {
+        this.serviceInventoryCache = moduleManager.find(CoreModule.NAME).getService(ServiceInventoryCache.class);
         this.serviceInstanceInventoryRegister = moduleManager.find(CoreModule.NAME).getService(IServiceInstanceInventoryRegister.class);
     }
 
@@ -73,7 +78,17 @@ public class InstanceDiscoveryServletHandler extends JettyJsonHandler {
             JsonArray ipv4s = osInfoJson.get("ipv4s").getAsJsonArray();
             ipv4s.forEach(ipv4 -> agentOsInfo.getIpv4s().add(ipv4.getAsString()));
 
-            int instanceId = serviceInstanceInventoryRegister.getOrCreate(applicationId, agentUUID, registerTime, agentOsInfo);
+            ServiceInventory serviceInventory = serviceInventoryCache.get(applicationId);
+
+            String instanceName = serviceInventory.getName();
+            if (agentOsInfo.getProcessNo() != 0) {
+                instanceName += "-pid:" + agentOsInfo.getProcessNo();
+            }
+            if (StringUtils.isNotEmpty(agentOsInfo.getHostname())) {
+                instanceName += "@" + agentOsInfo.getHostname();
+            }
+
+            int instanceId = serviceInstanceInventoryRegister.getOrCreate(applicationId, instanceName, agentUUID, registerTime, agentOsInfo);
             responseJson.addProperty(APPLICATION_ID, applicationId);
             responseJson.addProperty(INSTANCE_ID, instanceId);
         } catch (IOException e) {
diff --git a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/cache/ServiceInstanceInventoryCacheDAO.java b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/cache/ServiceInstanceInventoryCacheDAO.java
index d0c97a7..3abc5fb 100644
--- a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/cache/ServiceInstanceInventoryCacheDAO.java
+++ b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/cache/ServiceInstanceInventoryCacheDAO.java
@@ -62,8 +62,8 @@ public class ServiceInstanceInventoryCacheDAO extends EsDAO implements IServiceI
         }
     }
 
-    @Override public int getServiceInstanceId(int serviceId, String serviceInstanceName) {
-        String id = ServiceInstanceInventory.buildId(serviceId, serviceInstanceName);
+    @Override public int getServiceInstanceId(int serviceId, String uuid) {
+        String id = ServiceInstanceInventory.buildId(serviceId, uuid);
         return get(id);
     }
 
diff --git a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2ServiceInstanceInventoryCacheDAO.java b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2ServiceInstanceInventoryCacheDAO.java
index 645a8bc..dfa2f54 100644
--- a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2ServiceInstanceInventoryCacheDAO.java
+++ b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2ServiceInstanceInventoryCacheDAO.java
@@ -45,8 +45,8 @@ public class H2ServiceInstanceInventoryCacheDAO extends H2SQLExecutor implements
         }
     }
 
-    @Override public int getServiceInstanceId(int serviceId, String serviceInstanceName) {
-        String id = ServiceInstanceInventory.buildId(serviceId, serviceInstanceName);
+    @Override public int getServiceInstanceId(int serviceId, String uuid) {
+        String id = ServiceInstanceInventory.buildId(serviceId, uuid);
         return getByID(id);
     }