This is an automated email from the ASF dual-hosted git repository.

kezhenxu94 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 327bff2ee1 chore: add a warning log when connecting to ES takes too 
long (#13321)
327bff2ee1 is described below

commit 327bff2ee11bc801bd667368f3e5aa4b45cb6789
Author: kezhenxu94 <kezhenx...@apache.org>
AuthorDate: Tue Jun 17 17:30:50 2025 +0800

    chore: add a warning log when connecting to ES takes too long (#13321)
---
 docs/en/changes/changes.md                                   |  1 +
 .../library/client/elasticsearch/ElasticSearchClient.java    | 12 +++++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/docs/en/changes/changes.md b/docs/en/changes/changes.md
index 4197af0820..09f1b8bf35 100644
--- a/docs/en/changes/changes.md
+++ b/docs/en/changes/changes.md
@@ -34,6 +34,7 @@
 * BanyanDB: Support custom `TopN pre-aggregation` rules configuration in file 
`bydb-topn.yml`.
 * refactor: implement OTEL handler with SPI for extensibility.
 * chore: add `toString` implementation for `StorageID`.
+* chore: add a warning log when connecting to ES takes too long.
 
 #### UI
 
diff --git 
a/oap-server/server-library/library-client/src/main/java/org/apache/skywalking/oap/server/library/client/elasticsearch/ElasticSearchClient.java
 
b/oap-server/server-library/library-client/src/main/java/org/apache/skywalking/oap/server/library/client/elasticsearch/ElasticSearchClient.java
index a30fd72ccf..9d3621c522 100644
--- 
a/oap-server/server-library/library-client/src/main/java/org/apache/skywalking/oap/server/library/client/elasticsearch/ElasticSearchClient.java
+++ 
b/oap-server/server-library/library-client/src/main/java/org/apache/skywalking/oap/server/library/client/elasticsearch/ElasticSearchClient.java
@@ -18,6 +18,7 @@
 
 package org.apache.skywalking.oap.server.library.client.elasticsearch;
 
+import com.google.common.base.Stopwatch;
 import com.google.common.base.Strings;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Iterables;
@@ -29,6 +30,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.function.Function;
 import java.util.function.Supplier;
@@ -149,14 +151,22 @@ public class ElasticSearchClient implements Client, 
HealthCheckable {
             cb.password(password);
         }
 
-        final ElasticSearch newOne = cb.build();
+        final var newOne = cb.build();
+        final var stopWatch = Stopwatch.createStarted();
         // Only swap the old / new after the new one established a new 
connection.
         final CompletableFuture<ElasticSearchVersion> f = newOne.connect();
         f.whenComplete((ignored, exception) -> {
+            stopWatch.stop();
             if (exception != null) {
                 log.error("Failed to recreate ElasticSearch client based on 
config", exception);
                 return;
             }
+            final var connectingTime = 
stopWatch.elapsed(TimeUnit.MILLISECONDS);
+            if (connectingTime > 1000) {
+                log.warn(
+                    "Connecting to ElasticSearch took {} ms, which is longer 
than expected and can impact performance.",
+                    connectingTime);
+            }
             if (es.compareAndSet(oldOne, newOne)) {
                 oldOne.close();
             } else {

Reply via email to