From 42d79bf08d60a05c33a97820d2d500189b2209f8 Mon Sep 17 00:00:00 2001 From: Jared Tan Date: Mon, 25 May 2020 16:15:10 +0800 Subject: [PATCH] Fix too many mang ipv4 records reported by the agent when deployed in container. (#4817) --- .../apache/skywalking/apm/agent/core/conf/Config.java | 8 ++++++++ .../org/apache/skywalking/apm/agent/core/os/OSUtil.java | 9 ++++++--- .../apm/agent/core/remote/ServiceManagementClient.java | 3 ++- docs/en/setup/service-agent/java-agent/README.md | 1 + 4 files changed, 17 insertions(+), 4 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 8a4990d71..c3d9213f9 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 @@ -109,6 +109,14 @@ public class Config { * Keep tracing even the backend is not available. */ public static boolean KEEP_TRACING = false; + + } + + public static class OsInfo { + /** + * Limit the length of the ipv4 list size. + */ + public static int IPV4_LIST_SIZE = 10; } public static class Collector { diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/os/OSUtil.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/os/OSUtil.java index f054d87c7..307b5b3a4 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/os/OSUtil.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/os/OSUtil.java @@ -57,7 +57,7 @@ public class OSUtil { public static List getAllIPV4() { if (IPV4_LIST == null) { - IPV4_LIST = new LinkedList(); + IPV4_LIST = new LinkedList<>(); try { Enumeration interfs = NetworkInterface.getNetworkInterfaces(); while (interfs.hasMoreElements()) { @@ -103,8 +103,8 @@ public class OSUtil { return PROCESS_NO; } - public static List buildOSInfo() { - List osInfo = new ArrayList(); + public static List buildOSInfo(int ipv4Size) { + List osInfo = new ArrayList<>(); String osName = getOsName(); if (osName != null) { @@ -116,6 +116,9 @@ public class OSUtil { } List allIPV4 = getAllIPV4(); if (allIPV4.size() > 0) { + if (allIPV4.size() > ipv4Size) { + allIPV4 = allIPV4.subList(0, ipv4Size); + } for (String ipv4 : allIPV4) { osInfo.add(KeyStringValuePair.newBuilder().setKey("ipv4").setValue(ipv4).build()); } diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/ServiceManagementClient.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/ServiceManagementClient.java index 39116eaac..135a20558 100755 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/ServiceManagementClient.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/ServiceManagementClient.java @@ -119,7 +119,8 @@ public class ServiceManagementClient implements BootService, Runnable, GRPCChann .reportInstanceProperties(InstanceProperties.newBuilder() .setService(Config.Agent.SERVICE_NAME) .setServiceInstance(Config.Agent.INSTANCE_NAME) - .addAllProperties(OSUtil.buildOSInfo()) + .addAllProperties(OSUtil.buildOSInfo( + Config.OsInfo.IPV4_LIST_SIZE)) .addAllProperties(SERVICE_INSTANCE_PROPERTIES) .build()); instancePropertiesSubmitted = true; diff --git a/docs/en/setup/service-agent/java-agent/README.md b/docs/en/setup/service-agent/java-agent/README.md index a1b4f6037..f55260dbd 100755 --- a/docs/en/setup/service-agent/java-agent/README.md +++ b/docs/en/setup/service-agent/java-agent/README.md @@ -84,6 +84,7 @@ property key | Description | Default | `agent.force_reconnection_period `|Force reconnection period of grpc, based on grpc_channel_check_interval.|`1`| `agent.operation_name_threshold `|The operationName max length, setting this value > 190 is not recommended.|`150`| `agent.keep_tracing`|Keep tracing even the backend is not available if this value is `true`.|`false`| +`osinfo.ipv4_list_size`| Limit the length of the ipv4 list size. |`10`| `collector.grpc_channel_check_interval`|grpc channel status check interval.|`30`| `collector.heartbeat_period`|agent heartbeat report period. Unit, second.|`30`| `collector.backend_service`|Collector SkyWalking trace receiver service addresses.|`127.0.0.1:11800`|