Skip to content

Commit e6f12b5

Browse files
authored
add max length configuration for service_name and instance_name (#609)
1 parent 6f80861 commit e6f12b5

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Release Notes.
99
* Fix the issue of createSpan failure caused by invalid request URL in HttpClient 4.x/5.x plugin
1010
* Optimize ElasticSearch 6.x 7.x plugin compatibility
1111
* Fix an issue with the httpasyncclient component where the isError state is incorrect.
12+
* Support customization for the length limitation of string configurations
13+
* Add max length configurations in `agent.config` file for service_name and instance_name
1214

1315
#### Documentation
1416

apm-commons/apm-util/src/main/java/org/apache/skywalking/apm/util/ConfigInitializer.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,20 @@ private static void initNextLevel(Properties properties, Class<?> recentConfigTy
8585
} else {
8686
// Convert the value into real type
8787
final Length lengthDefine = field.getAnnotation(Length.class);
88-
if (lengthDefine != null && propertyValue.length() > lengthDefine.value()) {
89-
StringUtil.cut(propertyValue, lengthDefine.value());
90-
System.err.printf("The config value will be truncated , because the length max than %d : %s -> %s%n", lengthDefine.value(), configKey, propertyValue);
88+
if (lengthDefine != null) {
89+
int lengthLimited = lengthDefine.value();
90+
String lengthKey = String.format("%s#length", configKey);
91+
if (properties.containsKey(lengthKey)) {
92+
try {
93+
lengthLimited = Integer.valueOf(properties.getProperty(lengthKey));
94+
} catch (NumberFormatException ex) {
95+
System.err.printf("The length config (%s=%s) is invalid. The value can not be cast to number.", lengthKey, properties.getProperty(lengthKey));
96+
}
97+
}
98+
if (propertyValue.length() > lengthLimited) {
99+
StringUtil.cut(propertyValue, lengthLimited);
100+
System.err.printf("The config value will be truncated , because the length max than %d : %s -> %s%n", lengthDefine.value(), configKey, propertyValue);
101+
}
91102
}
92103
Object convertedValue = convertToTypicalType(type, propertyValue);
93104
if (convertedValue != null) {

apm-sniffer/config/agent.config

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# ${service name} = [${group name}::]${logic name}
1919
# The group name is optional only.
2020
agent.service_name=${SW_AGENT_NAME:Your_ApplicationName}
21+
agent.service_name#length=${SW_AGENT_NAME_MAX_LENGTH:50}
2122

2223
# The agent namespace
2324
agent.namespace=${SW_AGENT_NAMESPACE:}
@@ -49,6 +50,7 @@ agent.is_open_debugging_class=${SW_AGENT_OPEN_DEBUG:false}
4950
# Instance name is the identity of an instance, should be unique in the service. If empty, SkyWalking agent will
5051
# generate an 32-bit uuid. BY Default, SkyWalking uses UUID@hostname as the instance name. Max length is 50(UTF-8 char)
5152
agent.instance_name=${SW_AGENT_INSTANCE_NAME:}
53+
agent.instance_name#length=${SW_AGENT_INSTANCE_NAME_MAX_LENGTH:50}
5254

5355
# service instance properties in json format. e.g. agent.instance_properties_json = {"org": "apache-skywalking"}
5456
agent.instance_properties_json=${SW_INSTANCE_PROPERTIES_JSON:}
@@ -307,4 +309,4 @@ plugin.redisson.redis_parameter_max_length=${SW_PLUGIN_REDISSON_REDIS_PARAMETER_
307309
# Specify which command should be converted to write operation
308310
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}
309311
# Specify which command should be converted to read operation
310-
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}
312+
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}

0 commit comments

Comments
 (0)