Class ApmServerClient


  • public class ApmServerClient
    extends java.lang.Object
    Load-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.

    • 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.Exception
        Executes a request to the APM Server and returns the result from the provided ApmServerClient.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 path
        connectionHandler - receives the HttpURLConnection and 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
      • supportsNonStringLabels

        public boolean supportsNonStringLabels()
      • supportsLogsEndpoint

        public boolean supportsLogsEndpoint()
      • supportsNumericUrlPort

        public boolean supportsNumericUrlPort()
      • isAtLeast

        public boolean isAtLeast​(Version apmServerVersion)