You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2021/01/22 05:14:46 UTC
[skywalking] branch master updated: Support DNS period resolving
mechanism (#6240)
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 100823c Support DNS period resolving mechanism (#6240)
100823c is described below
commit 100823cb6e7f076de0ac7b5da2dd6789e21fcf38
Author: Leon Yang <13...@qq.com>
AuthorDate: Fri Jan 22 13:14:21 2021 +0800
Support DNS period resolving mechanism (#6240)
---
CHANGES.md | 1 +
.../skywalking/apm/agent/core/conf/Config.java | 5 ++++-
.../apm/agent/core/remote/GRPCChannelManager.java | 23 ++++++++++++++++++++++
docs/en/setup/service-agent/java-agent/README.md | 1 +
4 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/CHANGES.md b/CHANGES.md
index 210a0d8..10c79af 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -37,6 +37,7 @@ Release Notes.
* Fix RestTemplate plugin recording url tag with wrong port
* Support collecting logs and forwarding through gRPC.
* Support config `agent.sample_n_per_3_secs` can be changed in the runtime.
+* Support DNS periodic resolving mechanism to update backend service.
#### OAP-Backend
* Make meter receiver support MAL.
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 b7da770..4f4a981 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
@@ -163,11 +163,14 @@ public class Config {
* Get profile task list interval
*/
public static int GET_PROFILE_TASK_INTERVAL = 20;
-
/**
* Get agent dynamic config interval
*/
public static int GET_AGENT_DYNAMIC_CONFIG_INTERVAL = 20;
+ /**
+ * If true, skywalking agent will enable periodically resolving DNS to update receiver service addresses.
+ */
+ public static boolean IS_RESOLVE_DNS_PERIODICALLY = false;
}
public static class Profile {
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/GRPCChannelManager.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/GRPCChannelManager.java
index ca13a48..79d114d 100755
--- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/GRPCChannelManager.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/GRPCChannelManager.java
@@ -21,6 +21,8 @@ package org.apache.skywalking.apm.agent.core.remote;
import io.grpc.Channel;
import io.grpc.Status;
import io.grpc.StatusRuntimeException;
+
+import java.net.InetAddress;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
@@ -29,6 +31,8 @@ import java.util.Random;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
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;
@@ -37,6 +41,8 @@ import org.apache.skywalking.apm.agent.core.logging.api.ILog;
import org.apache.skywalking.apm.agent.core.logging.api.LogManager;
import org.apache.skywalking.apm.util.RunnableWithExceptionProtection;
+import static org.apache.skywalking.apm.agent.core.conf.Config.Collector.IS_RESOLVE_DNS_PERIODICALLY;
+
@DefaultImplementor
public class GRPCChannelManager implements BootService, Runnable {
private static final ILog LOGGER = LogManager.getLogger(GRPCChannelManager.class);
@@ -92,6 +98,23 @@ public class GRPCChannelManager implements BootService, Runnable {
@Override
public void run() {
LOGGER.debug("Selected collector grpc service running, reconnect:{}.", reconnect);
+ if (IS_RESOLVE_DNS_PERIODICALLY && reconnect) {
+ String backendService = Config.Collector.BACKEND_SERVICE.split(",")[0];
+ try {
+ String[] domainAndPort = backendService.split(":");
+
+ List<String> newGrpcServers = Arrays
+ .stream(InetAddress.getAllByName(domainAndPort[0]))
+ .map(InetAddress::getHostAddress)
+ .map(ip -> String.format("%s:%s", ip, domainAndPort[1]))
+ .collect(Collectors.toList());
+
+ grpcServers = newGrpcServers;
+ } catch (Throwable t) {
+ LOGGER.error(t, "Failed to resolve {} of backend service.", backendService);
+ }
+ }
+
if (reconnect) {
if (grpcServers.size() > 0) {
String server = "";
diff --git a/docs/en/setup/service-agent/java-agent/README.md b/docs/en/setup/service-agent/java-agent/README.md
index 24a03ba..b2fd2ad 100755
--- a/docs/en/setup/service-agent/java-agent/README.md
+++ b/docs/en/setup/service-agent/java-agent/README.md
@@ -95,6 +95,7 @@ property key | Description | Default |
`collector.grpc_upstream_timeout`|How long grpc client will timeout in sending data to upstream. Unit is second.|`30` seconds|
`collector.get_profile_task_interval`|Sniffer get profile task list interval.|`20`|
`collector.get_agent_dynamic_config_interval`|Sniffer get agent dynamic config interval|`20`|
+`collector.dns_period_resolve_active`|If true, skywalking agent will enable periodically resolving DNS to update receiver service addresses.|`false`|
`logging.level`|Log level: TRACE, DEBUG, INFO, WARN, ERROR, OFF. Default is info.|`INFO`|
`logging.file_name`|Log file name.|`skywalking-api.log`|
`logging.output`| Log output. Default is FILE. Use CONSOLE means output to stdout. |`FILE`|