Class ApmServerClient
- java.lang.Object
-
- co.elastic.apm.agent.report.ApmServerClient
-
public class ApmServerClient extends java.lang.ObjectLoad-balances traffic and handles fail-overs to multiple APM Servers.In contrast to most load-balancing algorithms, this does not round-robin for every new request. The reasoning is that we want to be able to reuse the TCP connections to the APM Server as much as possible so that initiating a new request is as fast as possible. That's why we only round-robin to the next APM Server URL in the event of a connection error.
To achieve load-balancing, we shuffle the list of provided APM Server URLs. The more agents need to communicate with the same set of servers, the more even the load distribution will be. That's because of the random order the APM Servers will be in the shuffled list. The assumption is that we only need to multiple APM Servers if lots of agents are in use and therefore one server does not scale anymore.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceApmServerClient.ConnectionHandler<T>
-
Constructor Summary
Constructors Constructor Description ApmServerClient(ReporterConfiguration reporterConfiguration)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <V> Vexecute(java.lang.String path, ApmServerClient.ConnectionHandler<V> connectionHandler)Executes a request to the APM Server and returns the result from the providedApmServerClient.ConnectionHandler.<T> java.util.List<T>executeForAllUrls(java.lang.String path, ApmServerClient.ConnectionHandler<T> connectionHandler)booleanisAtLeast(Version apmServerVersion)voidstart()voidstart(java.util.List<java.net.URL> shuffledUrls)booleansupportsLogsEndpoint()booleansupportsNonStringLabels()booleansupportsNumericUrlPort()
-
-
-
Constructor Detail
-
ApmServerClient
public ApmServerClient(ReporterConfiguration reporterConfiguration)
-
-
Method Detail
-
start
public void start()
-
start
public void start(java.util.List<java.net.URL> shuffledUrls)
-
execute
@Nullable public <V> V execute(java.lang.String path, ApmServerClient.ConnectionHandler<V> connectionHandler) throws java.lang.ExceptionExecutes a request to the APM Server and returns the result from the providedApmServerClient.ConnectionHandler. If there's a connection error executing the request, the request is retried with the next APM Server url. The maximum amount of retries is the number of configured APM Server URLs.- Type Parameters:
V- the result type- Parameters:
path- the APM Server pathconnectionHandler- receives theHttpURLConnectionand returns the result- Returns:
- the result of the provided
Callable - Throws:
java.lang.Exception- in case all retries yield an exception, the last will be thrown
-
executeForAllUrls
public <T> java.util.List<T> executeForAllUrls(java.lang.String path, ApmServerClient.ConnectionHandler<T> connectionHandler)
-
supportsNonStringLabels
public boolean supportsNonStringLabels()
-
supportsLogsEndpoint
public boolean supportsLogsEndpoint()
-
supportsNumericUrlPort
public boolean supportsNumericUrlPort()
-
isAtLeast
public boolean isAtLeast(Version apmServerVersion)
-
-