You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@skywalking.apache.org by wu...@apache.org on 2018/03/22 06:57:37 UTC
[incubator-skywalking] 01/01: Support direct server setting in
agent.
This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch feature/direct_server
in repository https://gitbox.apache.org/repos/asf/incubator-skywalking.git
commit f3e6b25b707187ba9441ef99f30f9c3449ab7869
Author: wusheng <wu...@foxmail.com>
AuthorDate: Thu Mar 22 14:57:27 2018 +0800
Support direct server setting in agent.
---
.../skywalking/apm/agent/core/conf/Config.java | 17 +++++++--
.../core/remote/CollectorDiscoveryService.java | 40 +++++++++++++++-------
.../core/remote/DiscoveryRestServiceClient.java | 20 ++++++-----
apm-sniffer/config/agent.config | 10 ++++++
4 files changed, 65 insertions(+), 22 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 577a573..8dc54a0 100644
--- 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
@@ -80,12 +80,25 @@ public class Config {
*/
public static long DISCOVERY_CHECK_INTERVAL = 60;
/**
- * Collector REST-Service address. e.g. SERVERS="127.0.0.1:8080" for single collector node.
- * SERVERS="10.2.45.126:8080,10.2.45.127:7600" for multi collector nodes.
+ * Collector naming/jetty service addresses.
+ * Primary address setting.
+ *
+ * e.g.
+ * SERVERS="127.0.0.1:10800" for single collector node.
+ * SERVERS="10.2.45.126:10800,10.2.45.127:10800" for multi collector nodes.
*/
public static String SERVERS = "";
/**
+ * Collector agent_gRPC/grpc service addresses.
+ * Secondary address setting, only effect when #SERVERS is empty.
+ *
+ * By using this, no discovery mechanism provided. The agent only uses these addresses to uplink data.
+ *
+ */
+ public static String DIRECT_SERVERS = "";
+
+ /**
* Collector service discovery REST service name
*/
public static String DISCOVERY_SERVICE_NAME = "/agent/gRPC";
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/CollectorDiscoveryService.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/CollectorDiscoveryService.java
index b5d4f44..f29d6c9 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/CollectorDiscoveryService.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/CollectorDiscoveryService.java
@@ -18,15 +18,19 @@
package org.apache.skywalking.apm.agent.core.remote;
+import java.util.Arrays;
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.DefaultNamedThreadFactory;
import org.apache.skywalking.apm.agent.core.conf.Config;
+import org.apache.skywalking.apm.agent.core.conf.RemoteDownstreamConfig;
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 org.apache.skywalking.apm.util.StringUtil;
/**
* The <code>CollectorDiscoveryService</code> is responsible for start {@link DiscoveryRestServiceClient}.
@@ -38,22 +42,32 @@ public class CollectorDiscoveryService implements BootService {
private ScheduledFuture<?> future;
@Override
- public void beforeBoot() throws Throwable {
+ public void beforeBoot() {
}
@Override
- public void boot() throws Throwable {
+ public void boot() {
DiscoveryRestServiceClient discoveryRestServiceClient = new DiscoveryRestServiceClient();
- discoveryRestServiceClient.run();
- future = Executors.newSingleThreadScheduledExecutor(new DefaultNamedThreadFactory("CollectorDiscoveryService"))
- .scheduleAtFixedRate(new RunnableWithExceptionProtection(discoveryRestServiceClient,
- new RunnableWithExceptionProtection.CallbackWhenException() {
- @Override public void handle(Throwable t) {
- logger.error("unexpected exception.", t);
- }
- }), Config.Collector.DISCOVERY_CHECK_INTERVAL,
- Config.Collector.DISCOVERY_CHECK_INTERVAL, TimeUnit.SECONDS);
+ if (discoveryRestServiceClient.hasNamingServer()) {
+ discoveryRestServiceClient.run();
+ future = Executors.newSingleThreadScheduledExecutor(new DefaultNamedThreadFactory("CollectorDiscoveryService"))
+ .scheduleAtFixedRate(new RunnableWithExceptionProtection(discoveryRestServiceClient,
+ new RunnableWithExceptionProtection.CallbackWhenException() {
+ @Override
+ public void handle(Throwable t) {
+ logger.error("unexpected exception.", t);
+ }
+ }), Config.Collector.DISCOVERY_CHECK_INTERVAL,
+ Config.Collector.DISCOVERY_CHECK_INTERVAL, TimeUnit.SECONDS);
+ } else {
+ if (Config.Collector.DIRECT_SERVERS == null || Config.Collector.DIRECT_SERVERS.trim().length() == 0) {
+ logger.error("Collector server and direct server addresses are both not set.");
+ logger.error("Agent will not uplink any data.");
+ return;
+ }
+ RemoteDownstreamConfig.Collector.GRPC_SERVERS = Arrays.asList(Config.Collector.DIRECT_SERVERS.split(","));
+ }
}
@Override
@@ -63,6 +77,8 @@ public class CollectorDiscoveryService implements BootService {
@Override
public void shutdown() throws Throwable {
- future.cancel(true);
+ if (future != null) {
+ future.cancel(true);
+ }
}
}
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/DiscoveryRestServiceClient.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/DiscoveryRestServiceClient.java
index 565a7d7..620efef 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/DiscoveryRestServiceClient.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/DiscoveryRestServiceClient.java
@@ -22,10 +22,6 @@ package org.apache.skywalking.apm.agent.core.remote;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
-import java.io.IOException;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Random;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
@@ -36,6 +32,11 @@ import org.apache.skywalking.apm.agent.core.conf.Config;
import org.apache.skywalking.apm.agent.core.logging.api.ILog;
import org.apache.skywalking.apm.agent.core.logging.api.LogManager;
+import java.io.IOException;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Random;
+
import static org.apache.skywalking.apm.agent.core.conf.RemoteDownstreamConfig.Collector.GRPC_SERVERS;
/**
@@ -55,7 +56,7 @@ public class DiscoveryRestServiceClient implements Runnable {
public DiscoveryRestServiceClient() {
if (Config.Collector.SERVERS == null || Config.Collector.SERVERS.trim().length() == 0) {
- logger.warn("Collector server not configured.");
+ logger.warn("Collector server not set.");
return;
}
@@ -64,7 +65,10 @@ public class DiscoveryRestServiceClient implements Runnable {
if (serverList.length > 0) {
selectedServer = r.nextInt(serverList.length);
}
+ }
+ boolean hasNamingServer() {
+ return serverList != null && serverList.length > 0;
}
@Override
@@ -138,9 +142,9 @@ public class DiscoveryRestServiceClient implements Runnable {
}
HttpGet httpGet = new HttpGet("http://" + serverList[selectedServer] + Config.Collector.DISCOVERY_SERVICE_NAME);
RequestConfig requestConfig = RequestConfig.custom()
- .setConnectTimeout(HTTP_CONNECT_TIMEOUT)
- .setConnectionRequestTimeout(HTTP_CONNECTION_REQUEST_TIMEOUT)
- .setSocketTimeout(HTTP_SOCKET_TIMEOUT).build();
+ .setConnectTimeout(HTTP_CONNECT_TIMEOUT)
+ .setConnectionRequestTimeout(HTTP_CONNECTION_REQUEST_TIMEOUT)
+ .setSocketTimeout(HTTP_SOCKET_TIMEOUT).build();
httpGet.setConfig(requestConfig);
return httpGet;
}
diff --git a/apm-sniffer/config/agent.config b/apm-sniffer/config/agent.config
index 4600bbc..fde954d 100644
--- a/apm-sniffer/config/agent.config
+++ b/apm-sniffer/config/agent.config
@@ -17,11 +17,21 @@ agent.application_code=Your_ApplicationName
# agent.is_open_debugging_class = true
# Server addresses.
+# Primary address setting.
+#
# Mapping to `naming/jetty/ip:port` in `config/application.yml` of Collector.
# Examples:
# Single collector:SERVERS="127.0.0.1:8080"
# Collector cluster:SERVERS="10.2.45.126:8080,10.2.45.127:7600"
collector.servers=127.0.0.1:10800
+# Collector agent_gRPC/grpc service addresses.
+# Secondary address setting, only effect when "collector.servers" is empty.
+# By using this, no discovery mechanism provided. The agent only uses these addresses to uplink data.
+# Recommend to use this only when collector cluster IPs are unreachable from agent side. Such as:
+# 1. Agent and collector cluster are in different VPC in Cloud.
+# 2. Agent uplinks data to collector cluster through Internet.
+# collector.direct_servers=www.skywalking.service.io
+
# Logging level
logging.level=DEBUG
--
To stop receiving notification emails like this one, please contact
wusheng@apache.org.