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/12/30 06:04:02 UTC

[skywalking] 01/01: Support customized instance name by a new UUID naming policy.

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

wusheng pushed a commit to branch inst-name-override
in repository https://gitbox.apache.org/repos/asf/skywalking.git

commit 62a92b7c35e8d5f27b5de5c31694ee4453ef19d5
Author: Wu Sheng <wu...@foxmail.com>
AuthorDate: Mon Dec 30 14:03:43 2019 +0800

    Support customized instance name by a new UUID naming policy.
---
 docs/en/setup/service-agent/java-agent/README.md   |  6 ++---
 .../handler/v6/grpc/RegisterServiceHandler.java    | 30 +++++++++++++++-------
 2 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/docs/en/setup/service-agent/java-agent/README.md b/docs/en/setup/service-agent/java-agent/README.md
index abae8b8..56a9a86 100755
--- a/docs/en/setup/service-agent/java-agent/README.md
+++ b/docs/en/setup/service-agent/java-agent/README.md
@@ -75,11 +75,11 @@ property key | Description | Default |
 `agent.service_name` | Application(5.x)/Service(6.x) code is showed in sky-walking-ui. Suggestion: set a unique name for each service, service instance nodes share the same code | `Your_ApplicationName` |
 `agent.sample_n_per_3_secs`|Negative or zero means off, by default.SAMPLE_N_PER_3_SECS means sampling N TraceSegment in 3 seconds tops.|Not set|
 `agent.authentication`|Authentication active is based on backend setting, see application.yml for more details.For most scenarios, this needs backend extensions, only basic match auth provided in default implementation.|Not set|
-`agent.span_limit_per_segment`|The max number of spans in a single segment. Through this config item, skywalking keep your application memory cost estimated.|300 |
+`agent.span_limit_per_segment`|The max number of spans in a single segment. Through this config item, SkyWalking keep your application memory cost estimated.|300 |
 `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.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.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. Using `NAME:` as UUID prefix could set the customized instance name. Such as, set it as `NAME:SVR-INSTANCE-A`,  `SVR-INSTANCE-A` is the instance name. Otherwise, use `ServiceName`-pid:`id`@`hostname` as the instance name. |`""`|
 `agent.instance_properties[key]=value` | Add service instance custom properties. | Not set|
 `agent.cause_exception_depth`|How depth the agent goes, when log all cause exceptions.|`5`|
 `agent.active_v1_header `|Deactivate V1 header in default.|`false`|
diff --git a/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v6/grpc/RegisterServiceHandler.java b/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v6/grpc/RegisterServiceHandler.java
index 3e9a605..e568a29 100644
--- a/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v6/grpc/RegisterServiceHandler.java
+++ b/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v6/grpc/RegisterServiceHandler.java
@@ -65,6 +65,7 @@ import static org.apache.skywalking.oap.server.core.register.ServiceInstanceInve
 public class RegisterServiceHandler extends RegisterGrpc.RegisterImplBase implements GRPCHandler {
 
     private static final Logger logger = LoggerFactory.getLogger(RegisterServiceHandler.class);
+    private static final String INSTANCE_CUSTOMIZED_NAME_PREFIX = "NAME:";
 
     private final ServiceInventoryCache serviceInventoryCache;
     private final ServiceInstanceInventoryCache serviceInstanceInventoryCache;
@@ -109,6 +110,12 @@ public class RegisterServiceHandler extends RegisterGrpc.RegisterImplBase implem
         request.getInstancesList().forEach(instance -> {
             ServiceInventory serviceInventory = serviceInventoryCache.get(instance.getServiceId());
 
+            String instanceUUID = instance.getInstanceUUID();
+            String instanceName = null;
+            if (instanceUUID.startsWith(INSTANCE_CUSTOMIZED_NAME_PREFIX)) {
+                instanceName = instanceUUID.substring(INSTANCE_CUSTOMIZED_NAME_PREFIX.length());
+            }
+
             JsonObject instanceProperties = new JsonObject();
             List<String> ipv4s = new ArrayList<>();
 
@@ -136,19 +143,24 @@ public class RegisterServiceHandler extends RegisterGrpc.RegisterImplBase implem
             }
             instanceProperties.addProperty(IPV4S, ServiceInstanceInventory.PropertyUtil.ipv4sSerialize(ipv4s));
 
-            String instanceName = serviceInventory.getName();
-            if (instanceProperties.has(PROCESS_NO)) {
-                instanceName += "-pid:" + instanceProperties.get(PROCESS_NO).getAsString();
-            }
-            if (instanceProperties.has(HOST_NAME)) {
-                instanceName += "@" + instanceProperties.get(HOST_NAME).getAsString();
+            if (instanceName == null) {
+                /**
+                 * After 7.0.0, only active this naming rule when instance name has not been set in UUID parameter.
+                 */
+                instanceName = serviceInventory.getName();
+                if (instanceProperties.has(PROCESS_NO)) {
+                    instanceName += "-pid:" + instanceProperties.get(PROCESS_NO).getAsString();
+                }
+                if (instanceProperties.has(HOST_NAME)) {
+                    instanceName += "@" + instanceProperties.get(HOST_NAME).getAsString();
+                }
             }
 
-            int serviceInstanceId = serviceInstanceInventoryRegister.getOrCreate(instance.getServiceId(), instanceName, instance.getInstanceUUID(), instance.getTime(), instanceProperties);
+            int serviceInstanceId = serviceInstanceInventoryRegister.getOrCreate(instance.getServiceId(), instanceName, instanceUUID, instance.getTime(), instanceProperties);
 
             if (serviceInstanceId != Const.NONE) {
-                logger.info("register service instance id={} [UUID:{}]", serviceInstanceId, instance.getInstanceUUID());
-                builder.addServiceInstances(KeyIntValuePair.newBuilder().setKey(instance.getInstanceUUID()).setValue(serviceInstanceId));
+                logger.info("register service instance id={} [UUID:{}]", serviceInstanceId, instanceUUID);
+                builder.addServiceInstances(KeyIntValuePair.newBuilder().setKey(instanceUUID).setValue(serviceInstanceId));
             }
         });