add max length configuration for service_name and instance_name (#609)

This commit is contained in:
elmer 2023-09-15 11:48:36 +08:00 committed by GitHub
parent 6f80861657
commit e6f12b5a7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 4 deletions

View File

@ -9,6 +9,8 @@ Release Notes.
* Fix the issue of createSpan failure caused by invalid request URL in HttpClient 4.x/5.x plugin
* Optimize ElasticSearch 6.x 7.x plugin compatibility
* Fix an issue with the httpasyncclient component where the isError state is incorrect.
* Support customization for the length limitation of string configurations
* Add max length configurations in `agent.config` file for service_name and instance_name
#### Documentation

View File

@ -85,9 +85,20 @@ public class ConfigInitializer {
} else {
// Convert the value into real type
final Length lengthDefine = field.getAnnotation(Length.class);
if (lengthDefine != null && propertyValue.length() > lengthDefine.value()) {
StringUtil.cut(propertyValue, lengthDefine.value());
System.err.printf("The config value will be truncated , because the length max than %d : %s -> %s%n", lengthDefine.value(), configKey, propertyValue);
if (lengthDefine != null) {
int lengthLimited = lengthDefine.value();
String lengthKey = String.format("%s#length", configKey);
if (properties.containsKey(lengthKey)) {
try {
lengthLimited = Integer.valueOf(properties.getProperty(lengthKey));
} catch (NumberFormatException ex) {
System.err.printf("The length config (%s=%s) is invalid. The value can not be cast to number.", lengthKey, properties.getProperty(lengthKey));
}
}
if (propertyValue.length() > lengthLimited) {
StringUtil.cut(propertyValue, lengthLimited);
System.err.printf("The config value will be truncated , because the length max than %d : %s -> %s%n", lengthDefine.value(), configKey, propertyValue);
}
}
Object convertedValue = convertToTypicalType(type, propertyValue);
if (convertedValue != null) {

View File

@ -18,6 +18,7 @@
# ${service name} = [${group name}::]${logic name}
# The group name is optional only.
agent.service_name=${SW_AGENT_NAME:Your_ApplicationName}
agent.service_name#length=${SW_AGENT_NAME_MAX_LENGTH:50}
# The agent namespace
agent.namespace=${SW_AGENT_NAMESPACE:}
@ -49,6 +50,7 @@ agent.is_open_debugging_class=${SW_AGENT_OPEN_DEBUG:false}
# Instance name is the identity of an instance, should be unique in the service. If empty, SkyWalking agent will
# generate an 32-bit uuid. BY Default, SkyWalking uses UUID@hostname as the instance name. Max length is 50(UTF-8 char)
agent.instance_name=${SW_AGENT_INSTANCE_NAME:}
agent.instance_name#length=${SW_AGENT_INSTANCE_NAME_MAX_LENGTH:50}
# service instance properties in json format. e.g. agent.instance_properties_json = {"org": "apache-skywalking"}
agent.instance_properties_json=${SW_INSTANCE_PROPERTIES_JSON:}
@ -307,4 +309,4 @@ plugin.redisson.redis_parameter_max_length=${SW_PLUGIN_REDISSON_REDIS_PARAMETER_
# Specify which command should be converted to write operation
plugin.redisson.operation_mapping_write=${SW_PLUGIN_REDISSON_OPERATION_MAPPING_WRITE:getset,set,setbit,setex,setnx,setrange,strlen,mset,msetnx,psetex,incr,incrby,incrbyfloat,decr,decrby,append,hmset,hset,hsetnx,hincrby,hincrbyfloat,hdel,rpoplpush,rpush,rpushx,lpush,lpushx,lrem,ltrim,lset,brpoplpush,linsert,sadd,sdiff,sdiffstore,sinterstore,sismember,srem,sunion,sunionstore,sinter,zadd,zincrby,zinterstore,zrange,zrangebylex,zrangebyscore,zrank,zrem,zremrangebylex,zremrangebyrank,zremrangebyscore,zrevrange,zrevrangebyscore,zrevrank,zunionstore,xadd,xdel,del,xtrim}
# Specify which command should be converted to read operation
plugin.redisson.operation_mapping_read=${SW_PLUGIN_REDISSON_OPERATION_MAPPING_READ:getrange,getbit,mget,hvals,hkeys,hlen,hexists,hget,hgetall,hmget,blpop,brpop,lindex,llen,lpop,lrange,rpop,scard,srandmember,spop,sscan,smove,zlexcount,zscore,zscan,zcard,zcount,xget,get,xread,xlen,xrange,xrevrange}
plugin.redisson.operation_mapping_read=${SW_PLUGIN_REDISSON_OPERATION_MAPPING_READ:getrange,getbit,mget,hvals,hkeys,hlen,hexists,hget,hgetall,hmget,blpop,brpop,lindex,llen,lpop,lrange,rpop,scard,srandmember,spop,sscan,smove,zlexcount,zscore,zscan,zcard,zcount,xget,get,xread,xlen,xrange,xrevrange}