agent support custom properties. (#3367)
* agent support custom properties.
This commit is contained in:
parent
06c357da6c
commit
6c347a1169
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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())) {
|
||||
|
|
|
|||
|
|
@ -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`|
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@
|
|||
|
||||
package org.apache.skywalking.oap.server.core.query.entity;
|
||||
|
||||
import lombok.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
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));
|
||||
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 (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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
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));
|
||||
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 (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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue