Skip to content

Commit 327bff2

Browse files
authored
chore: add a warning log when connecting to ES takes too long (#13321)
1 parent 57746c2 commit 327bff2

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

docs/en/changes/changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
* BanyanDB: Support custom `TopN pre-aggregation` rules configuration in file `bydb-topn.yml`.
3535
* refactor: implement OTEL handler with SPI for extensibility.
3636
* chore: add `toString` implementation for `StorageID`.
37+
* chore: add a warning log when connecting to ES takes too long.
3738

3839
#### UI
3940

oap-server/server-library/library-client/src/main/java/org/apache/skywalking/oap/server/library/client/elasticsearch/ElasticSearchClient.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package org.apache.skywalking.oap.server.library.client.elasticsearch;
2020

21+
import com.google.common.base.Stopwatch;
2122
import com.google.common.base.Strings;
2223
import com.google.common.collect.ImmutableMap;
2324
import com.google.common.collect.Iterables;
@@ -29,6 +30,7 @@
2930
import java.util.Map;
3031
import java.util.Optional;
3132
import java.util.concurrent.CompletableFuture;
33+
import java.util.concurrent.TimeUnit;
3234
import java.util.concurrent.atomic.AtomicReference;
3335
import java.util.function.Function;
3436
import java.util.function.Supplier;
@@ -149,14 +151,22 @@ public void connect() {
149151
cb.password(password);
150152
}
151153

152-
final ElasticSearch newOne = cb.build();
154+
final var newOne = cb.build();
155+
final var stopWatch = Stopwatch.createStarted();
153156
// Only swap the old / new after the new one established a new connection.
154157
final CompletableFuture<ElasticSearchVersion> f = newOne.connect();
155158
f.whenComplete((ignored, exception) -> {
159+
stopWatch.stop();
156160
if (exception != null) {
157161
log.error("Failed to recreate ElasticSearch client based on config", exception);
158162
return;
159163
}
164+
final var connectingTime = stopWatch.elapsed(TimeUnit.MILLISECONDS);
165+
if (connectingTime > 1000) {
166+
log.warn(
167+
"Connecting to ElasticSearch took {} ms, which is longer than expected and can impact performance.",
168+
connectingTime);
169+
}
160170
if (es.compareAndSet(oldOne, newOne)) {
161171
oldOne.close();
162172
} else {

0 commit comments

Comments
 (0)