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 2019/03/08 00:24:38 UTC

[incubator-skywalking] branch master updated: add instance id configuration item (#2328)

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 885ae47  add instance id configuration item (#2328)
885ae47 is described below

commit 885ae479e0e65f1e6598885b44a20cb510fe5002
Author: Xin,Zhang <zh...@apache.org>
AuthorDate: Fri Mar 8 08:24:33 2019 +0800

    add instance id configuration item (#2328)
    
    * add instance id configuration item
    
    * add doc about instance uuid
---
 .../org/apache/skywalking/apm/agent/core/conf/Config.java    |  5 +++++
 .../agent/core/remote/ServiceAndEndpointRegisterClient.java  | 12 ++++++++----
 docs/en/setup/service-agent/java-agent/README.md             |  1 +
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java
index e7c3fb9..1791eb6 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java
@@ -80,6 +80,11 @@ public class Config {
          * Deactive V1 header in default
          */
         public static boolean ACTIVE_V1_HEADER = false;
+
+        /**
+         * The identify of the instance
+         */
+        public static String INSTANCE_UUID = "";
     }
 
     public static class Collector {
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/ServiceAndEndpointRegisterClient.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/ServiceAndEndpointRegisterClient.java
index 4709736..b3e29de 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/ServiceAndEndpointRegisterClient.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/ServiceAndEndpointRegisterClient.java
@@ -46,6 +46,7 @@ import org.apache.skywalking.apm.network.register.v2.ServiceInstances;
 import org.apache.skywalking.apm.network.register.v2.ServiceRegisterMapping;
 import org.apache.skywalking.apm.network.register.v2.Services;
 import org.apache.skywalking.apm.util.RunnableWithExceptionProtection;
+import org.apache.skywalking.apm.util.StringUtil;
 
 /**
  * @author wusheng
@@ -53,7 +54,7 @@ import org.apache.skywalking.apm.util.RunnableWithExceptionProtection;
 @DefaultImplementor
 public class ServiceAndEndpointRegisterClient implements BootService, Runnable, GRPCChannelListener {
     private static final ILog logger = LogManager.getLogger(ServiceAndEndpointRegisterClient.class);
-    private static final String PROCESS_UUID = UUID.randomUUID().toString().replaceAll("-", "");
+    private static String INSTANCE_UUID;
 
     private volatile GRPCChannelStatus status = GRPCChannelStatus.DISCONNECT;
     private volatile RegisterGrpc.RegisterBlockingStub registerBlockingStub;
@@ -76,6 +77,9 @@ public class ServiceAndEndpointRegisterClient implements BootService, Runnable,
     @Override
     public void prepare() throws Throwable {
         ServiceManager.INSTANCE.findService(GRPCChannelManager.class).addChannelListener(this);
+
+        INSTANCE_UUID = StringUtil.isEmpty(Config.Agent.INSTANCE_UUID) ? UUID.randomUUID().toString()
+            .replaceAll("-", "") : Config.Agent.INSTANCE_UUID;
     }
 
     @Override
@@ -127,12 +131,12 @@ public class ServiceAndEndpointRegisterClient implements BootService, Runnable,
                                 .addInstances(
                                     ServiceInstance.newBuilder()
                                         .setServiceId(RemoteDownstreamConfig.Agent.SERVICE_ID)
-                                        .setInstanceUUID(PROCESS_UUID)
+                                        .setInstanceUUID(INSTANCE_UUID)
                                         .setTime(System.currentTimeMillis())
                                         .addAllProperties(OSUtil.buildOSInfo())
                                 ).build());
                             for (KeyIntValuePair serviceInstance : instanceMapping.getServiceInstancesList()) {
-                                if (PROCESS_UUID.equals(serviceInstance.getKey())) {
+                                if (INSTANCE_UUID.equals(serviceInstance.getKey())) {
                                     int serviceInstanceId = serviceInstance.getValue();
                                     if (serviceInstanceId != DictionaryUtil.nullValue()) {
                                         RemoteDownstreamConfig.Agent.SERVICE_INSTANCE_ID = serviceInstanceId;
@@ -143,7 +147,7 @@ public class ServiceAndEndpointRegisterClient implements BootService, Runnable,
                             serviceInstancePingStub.doPing(ServiceInstancePingPkg.newBuilder()
                                 .setServiceInstanceId(RemoteDownstreamConfig.Agent.SERVICE_INSTANCE_ID)
                                 .setTime(System.currentTimeMillis())
-                                .setServiceInstanceUUID(PROCESS_UUID)
+                                .setServiceInstanceUUID(INSTANCE_UUID)
                                 .build());
 
                             NetworkAddressDictionary.INSTANCE.syncRemoteDictionary(registerBlockingStub);
diff --git a/docs/en/setup/service-agent/java-agent/README.md b/docs/en/setup/service-agent/java-agent/README.md
index fc0177e..85df690 100644
--- a/docs/en/setup/service-agent/java-agent/README.md
+++ b/docs/en/setup/service-agent/java-agent/README.md
@@ -64,6 +64,7 @@ property key | Description | Default |
 `agent.ignore_suffix`|If the operation name of the first span is included in this set, this segment should be ignored.|Not set|
 `agent.is_open_debugging_class`|If true, skywalking agent will save all instrumented classes files in `/debugging` folder.Skywalking team may ask for these files in order to resolve compatible problem.|Not set|
 `agent.active_v2_header`|Active V2 header in default.|`true`|
+`agent.instance_uuid` |Instance uuid is the identity of an instance, skywalking treat same instance uuid as one instance.if empty, skywalking agent will generate an 32-bit uuid.   |`""`|
 `agent.active_v1_header `|Deactive V1 header in default.|`false`|
 `collector.grpc_channel_check_interval`|grpc channel status check interval.|`30`|
 `collector.app_and_service_register_check_interval`|application and service registry check interval.|`3`|