From 885ae479e0e65f1e6598885b44a20cb510fe5002 Mon Sep 17 00:00:00 2001 From: "Xin,Zhang" Date: Fri, 8 Mar 2019 08:24:33 +0800 Subject: [PATCH] add instance id configuration item (#2328) * add instance id configuration item * add doc about instance uuid --- .../skywalking/apm/agent/core/conf/Config.java | 5 +++++ .../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 e7c3fb968..1791eb6bf 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 4709736c6..b3e29de27 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 fc0177ead..85df6900b 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`|