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/skywalking.git


The following commit(s) were added to refs/heads/master by this push:
     new 6c347a1  agent support custom properties. (#3367)
6c347a1 is described below

commit 6c347a116940fbaadee0b7a50484eee65ad4ca20
Author: Jared Tan <jian....@daocloud.io>
AuthorDate: Tue Sep 17 14:44:42 2019 +0800

    agent support custom properties. (#3367)
    
    * agent support custom properties.
---
 .../skywalking/apm/agent/core/conf/Config.java     |  7 ++++
 .../remote/ServiceAndEndpointRegisterClient.java   | 13 ++++++-
 docs/en/setup/service-agent/java-agent/README.md   |  1 +
 .../oap/server/core/query/entity/Service.java      |  3 +-
 .../handler/v6/grpc/RegisterServiceHandler.java    | 44 +++++++++++++++++-----
 .../elasticsearch/query/MetadataQueryEsDAO.java    | 41 +++++++++++---------
 .../plugin/jdbc/h2/dao/H2MetadataQueryDAO.java     | 42 ++++++++++++---------
 7 files changed, 104 insertions(+), 47 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 376ee6b..ee28cfb 100755
--- 
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
@@ -89,6 +89,13 @@ public class Config {
          */
         public static String INSTANCE_UUID = "";
 
+        /*
+         * service instance properties
+         * e.g.
+         *   agent.instance_properties[org]=apache
+         */
+        public static Map<String, String> INSTANCE_PROPERTIES = new 
HashMap<String, String>();
+
         /**
          * How depth the agent goes, when log cause exceptions.
          */
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 51f98bd..92c22a5 100755
--- 
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
@@ -19,11 +19,12 @@
 package org.apache.skywalking.apm.agent.core.remote;
 
 import io.grpc.Channel;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.UUID;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
-
 import org.apache.skywalking.apm.agent.core.boot.BootService;
 import org.apache.skywalking.apm.agent.core.boot.DefaultImplementor;
 import org.apache.skywalking.apm.agent.core.boot.DefaultNamedThreadFactory;
@@ -39,6 +40,7 @@ import 
org.apache.skywalking.apm.agent.core.logging.api.LogManager;
 import org.apache.skywalking.apm.agent.core.os.OSUtil;
 import org.apache.skywalking.apm.network.common.Commands;
 import org.apache.skywalking.apm.network.common.KeyIntValuePair;
+import org.apache.skywalking.apm.network.common.KeyStringValuePair;
 import org.apache.skywalking.apm.network.register.v2.RegisterGrpc;
 import org.apache.skywalking.apm.network.register.v2.Service;
 import org.apache.skywalking.apm.network.register.v2.ServiceInstance;
@@ -58,6 +60,7 @@ import org.apache.skywalking.apm.util.StringUtil;
 public class ServiceAndEndpointRegisterClient implements BootService, 
Runnable, GRPCChannelListener {
     private static final ILog logger = 
LogManager.getLogger(ServiceAndEndpointRegisterClient.class);
     private static String INSTANCE_UUID;
+    private static List<KeyStringValuePair> SERVICE_INSTANCE_PROPERTIES;
 
     private volatile GRPCChannelStatus status = GRPCChannelStatus.DISCONNECT;
     private volatile RegisterGrpc.RegisterBlockingStub registerBlockingStub;
@@ -84,6 +87,13 @@ public class ServiceAndEndpointRegisterClient implements 
BootService, Runnable,
 
         INSTANCE_UUID = StringUtil.isEmpty(Config.Agent.INSTANCE_UUID) ? 
UUID.randomUUID().toString()
             .replaceAll("-", "") : Config.Agent.INSTANCE_UUID;
+
+        SERVICE_INSTANCE_PROPERTIES = new ArrayList<KeyStringValuePair>();
+
+        for (String key : Config.Agent.INSTANCE_PROPERTIES.keySet()) {
+            SERVICE_INSTANCE_PROPERTIES.add(KeyStringValuePair.newBuilder()
+                
.setKey(key).setValue(Config.Agent.INSTANCE_PROPERTIES.get(key)).build());
+        }
     }
 
     @Override
@@ -151,6 +161,7 @@ public class ServiceAndEndpointRegisterClient implements 
BootService, Runnable,
                                         .setInstanceUUID(INSTANCE_UUID)
                                         .setTime(System.currentTimeMillis())
                                         .addAllProperties(OSUtil.buildOSInfo())
+                                        
.addAllProperties(SERVICE_INSTANCE_PROPERTIES)
                                 ).build());
                             for (KeyIntValuePair serviceInstance : 
instanceMapping.getServiceInstancesList()) {
                                 if 
(INSTANCE_UUID.equals(serviceInstance.getKey())) {
diff --git a/docs/en/setup/service-agent/java-agent/README.md 
b/docs/en/setup/service-agent/java-agent/README.md
index 5b8a5b2..6f4f27a 100755
--- a/docs/en/setup/service-agent/java-agent/README.md
+++ b/docs/en/setup/service-agent/java-agent/README.md
@@ -73,6 +73,7 @@ property key | Description | Default |
 `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_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`|
 `agent.cool_down_threshold `|How long should the agent wait (in minute) before 
re-registering to the OAP server after receiving reset command.|`10`|
diff --git 
a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/entity/Service.java
 
b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/entity/Service.java
index 76ed34e..1c6b8e8 100644
--- 
a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/entity/Service.java
+++ 
b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/entity/Service.java
@@ -18,7 +18,8 @@
 
 package org.apache.skywalking.oap.server.core.query.entity;
 
-import lombok.*;
+import lombok.Getter;
+import lombok.Setter;
 
 /**
  * @author peng-yongsheng
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 6bdb842..e8d46bc 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
@@ -20,20 +20,44 @@ package 
org.apache.skywalking.oap.server.receiver.register.provider.handler.v6.g
 
 import com.google.gson.JsonObject;
 import io.grpc.stub.StreamObserver;
-import java.util.*;
-import org.apache.skywalking.apm.network.common.*;
-import org.apache.skywalking.apm.network.register.v2.*;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.skywalking.apm.network.common.Commands;
+import org.apache.skywalking.apm.network.common.KeyIntValuePair;
+import org.apache.skywalking.apm.network.common.KeyStringValuePair;
+import org.apache.skywalking.apm.network.register.v2.EndpointMapping;
+import org.apache.skywalking.apm.network.register.v2.EndpointMappingElement;
+import org.apache.skywalking.apm.network.register.v2.Endpoints;
+import org.apache.skywalking.apm.network.register.v2.NetAddressMapping;
+import org.apache.skywalking.apm.network.register.v2.NetAddresses;
+import org.apache.skywalking.apm.network.register.v2.RegisterGrpc;
+import 
org.apache.skywalking.apm.network.register.v2.ServiceAndNetworkAddressMappings;
+import 
org.apache.skywalking.apm.network.register.v2.ServiceInstanceRegisterMapping;
+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.StringUtil;
-import org.apache.skywalking.oap.server.core.*;
-import org.apache.skywalking.oap.server.core.cache.*;
-import org.apache.skywalking.oap.server.core.register.*;
-import org.apache.skywalking.oap.server.core.register.service.*;
+import org.apache.skywalking.oap.server.core.Const;
+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.IEndpointInventoryRegister;
+import 
org.apache.skywalking.oap.server.core.register.service.INetworkAddressInventoryRegister;
+import 
org.apache.skywalking.oap.server.core.register.service.IServiceInstanceInventoryRegister;
+import 
org.apache.skywalking.oap.server.core.register.service.IServiceInventoryRegister;
 import org.apache.skywalking.oap.server.core.source.DetectPoint;
 import org.apache.skywalking.oap.server.library.module.ModuleManager;
 import org.apache.skywalking.oap.server.library.server.grpc.GRPCHandler;
-import org.slf4j.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-import static 
org.apache.skywalking.oap.server.core.register.ServiceInstanceInventory.PropertyUtil.*;
+import static 
org.apache.skywalking.oap.server.core.register.ServiceInstanceInventory.PropertyUtil.HOST_NAME;
+import static 
org.apache.skywalking.oap.server.core.register.ServiceInstanceInventory.PropertyUtil.IPV4S;
+import static 
org.apache.skywalking.oap.server.core.register.ServiceInstanceInventory.PropertyUtil.LANGUAGE;
+import static 
org.apache.skywalking.oap.server.core.register.ServiceInstanceInventory.PropertyUtil.OS_NAME;
+import static 
org.apache.skywalking.oap.server.core.register.ServiceInstanceInventory.PropertyUtil.PROCESS_NO;
 
 /**
  * @author wusheng
@@ -106,6 +130,8 @@ public class RegisterServiceHandler extends 
RegisterGrpc.RegisterImplBase implem
                     case PROCESS_NO:
                         instanceProperties.addProperty(PROCESS_NO, 
property.getValue());
                         break;
+                    default:
+                        instanceProperties.addProperty(key, 
property.getValue());
                 }
             }
             instanceProperties.addProperty(IPV4S, 
ServiceInstanceInventory.PropertyUtil.ipv4sSerialize(ipv4s));
diff --git 
a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/MetadataQueryEsDAO.java
 
b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/MetadataQueryEsDAO.java
index 6c06f3a..63b52fa 100644
--- 
a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/MetadataQueryEsDAO.java
+++ 
b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/MetadataQueryEsDAO.java
@@ -20,6 +20,7 @@ package 
org.apache.skywalking.oap.server.storage.plugin.elasticsearch.query;
 
 import com.google.common.base.Strings;
 import com.google.gson.Gson;
+import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
 import java.io.IOException;
 import java.util.ArrayList;
@@ -249,26 +250,30 @@ public class MetadataQueryEsDAO extends EsDAO implements 
IMetadataQueryDAO {
             String propertiesString = 
(String)sourceAsMap.get(ServiceInstanceInventory.PROPERTIES);
             if (!Strings.isNullOrEmpty(propertiesString)) {
                 JsonObject properties = GSON.fromJson(propertiesString, 
JsonObject.class);
-                if (properties.has(LANGUAGE)) {
-                    
serviceInstance.setLanguage(LanguageTrans.INSTANCE.value(properties.get(LANGUAGE).getAsString()));
-                } else {
-                    serviceInstance.setLanguage(Language.UNKNOWN);
-                }
+                for (Map.Entry<String, JsonElement> property : 
properties.entrySet()) {
+                    String key = property.getKey();
+                    String value = property.getValue().getAsString();
+                    if (key.equals(LANGUAGE)) {
+                        
serviceInstance.setLanguage(LanguageTrans.INSTANCE.value(value));
+                    }
 
-                if (properties.has(OS_NAME)) {
-                    serviceInstance.getAttributes().add(new Attribute(OS_NAME, 
properties.get(OS_NAME).getAsString()));
-                }
-                if (properties.has(HOST_NAME)) {
-                    serviceInstance.getAttributes().add(new 
Attribute(HOST_NAME, properties.get(HOST_NAME).getAsString()));
-                }
-                if (properties.has(PROCESS_NO)) {
-                    serviceInstance.getAttributes().add(new 
Attribute(PROCESS_NO, properties.get(PROCESS_NO).getAsString()));
-                }
-                if (properties.has(IPV4S)) {
-                    List<String> ipv4s = 
ServiceInstanceInventory.PropertyUtil.ipv4sDeserialize(properties.get(IPV4S).getAsString());
-                    for (String ipv4 : ipv4s) {
-                        serviceInstance.getAttributes().add(new 
Attribute(ServiceInstanceInventory.PropertyUtil.IPV4S, ipv4));
+                    if (key.equals(OS_NAME)) {
+                        serviceInstance.getAttributes().add(new 
Attribute(OS_NAME, value));
+                    }
+                    if (key.equals(HOST_NAME)) {
+                        serviceInstance.getAttributes().add(new 
Attribute(HOST_NAME, value));
+                    }
+                    if (key.equals(PROCESS_NO)) {
+                        serviceInstance.getAttributes().add(new 
Attribute(PROCESS_NO, value));
                     }
+                    if (key.equals(IPV4S)) {
+                        List<String> ipv4s = 
ServiceInstanceInventory.PropertyUtil.ipv4sDeserialize(properties.get(IPV4S).getAsString());
+                        for (String ipv4 : ipv4s) {
+                            serviceInstance.getAttributes().add(new 
Attribute(ServiceInstanceInventory.PropertyUtil.IPV4S, ipv4));
+                        }
+                    }
+
+                    serviceInstance.getAttributes().add(new Attribute(key, 
value));
                 }
             } else {
                 serviceInstance.setLanguage(Language.UNKNOWN);
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/H2MetadataQueryDAO.java
 
b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2MetadataQueryDAO.java
index 7153c07..0fc0131 100644
--- 
a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2MetadataQueryDAO.java
+++ 
b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2MetadataQueryDAO.java
@@ -20,6 +20,7 @@ package 
org.apache.skywalking.oap.server.storage.plugin.jdbc.h2.dao;
 
 import com.google.common.base.Strings;
 import com.google.gson.Gson;
+import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
 import java.io.IOException;
 import java.sql.Connection;
@@ -27,6 +28,7 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 import org.apache.skywalking.oap.server.core.query.entity.Attribute;
 import org.apache.skywalking.oap.server.core.query.entity.Database;
 import org.apache.skywalking.oap.server.core.query.entity.Endpoint;
@@ -280,26 +282,30 @@ public class H2MetadataQueryDAO implements 
IMetadataQueryDAO {
                     String propertiesString = 
resultSet.getString(ServiceInstanceInventory.PROPERTIES);
                     if (!Strings.isNullOrEmpty(propertiesString)) {
                         JsonObject properties = 
GSON.fromJson(propertiesString, JsonObject.class);
-                        if (properties.has(LANGUAGE)) {
-                            
serviceInstance.setLanguage(LanguageTrans.INSTANCE.value(properties.get(LANGUAGE).getAsString()));
-                        } else {
-                            serviceInstance.setLanguage(Language.UNKNOWN);
-                        }
+                        for (Map.Entry<String, JsonElement> property : 
properties.entrySet()) {
+                            String key = property.getKey();
+                            String value = property.getValue().getAsString();
+                            if (key.equals(LANGUAGE)) {
+                                
serviceInstance.setLanguage(LanguageTrans.INSTANCE.value(value));
+                            }
 
-                        if (properties.has(OS_NAME)) {
-                            serviceInstance.getAttributes().add(new 
Attribute(OS_NAME, properties.get(OS_NAME).getAsString()));
-                        }
-                        if (properties.has(HOST_NAME)) {
-                            serviceInstance.getAttributes().add(new 
Attribute(HOST_NAME, properties.get(HOST_NAME).getAsString()));
-                        }
-                        if (properties.has(PROCESS_NO)) {
-                            serviceInstance.getAttributes().add(new 
Attribute(PROCESS_NO, properties.get(PROCESS_NO).getAsString()));
-                        }
-                        if (properties.has(IPV4S)) {
-                            List<String> ipv4s = 
ServiceInstanceInventory.PropertyUtil.ipv4sDeserialize(properties.get(IPV4S).getAsString());
-                            for (String ipv4 : ipv4s) {
-                                serviceInstance.getAttributes().add(new 
Attribute(ServiceInstanceInventory.PropertyUtil.IPV4S, ipv4));
+                            if (key.equals(OS_NAME)) {
+                                serviceInstance.getAttributes().add(new 
Attribute(OS_NAME, value));
+                            }
+                            if (key.equals(HOST_NAME)) {
+                                serviceInstance.getAttributes().add(new 
Attribute(HOST_NAME, value));
+                            }
+                            if (key.equals(PROCESS_NO)) {
+                                serviceInstance.getAttributes().add(new 
Attribute(PROCESS_NO, value));
                             }
+                            if (key.equals(IPV4S)) {
+                                List<String> ipv4s = 
ServiceInstanceInventory.PropertyUtil.ipv4sDeserialize(properties.get(IPV4S).getAsString());
+                                for (String ipv4 : ipv4s) {
+                                    serviceInstance.getAttributes().add(new 
Attribute(ServiceInstanceInventory.PropertyUtil.IPV4S, ipv4));
+                                }
+                            }
+
+                            serviceInstance.getAttributes().add(new 
Attribute(key, value));
                         }
                     } else {
                         serviceInstance.setLanguage(Language.UNKNOWN);

Reply via email to