|
18 | 18 |
|
19 | 19 | package org.apache.skywalking.oap.server.library.client.elasticsearch; |
20 | 20 |
|
| 21 | +import com.google.common.base.Stopwatch; |
21 | 22 | import com.google.common.base.Strings; |
22 | 23 | import com.google.common.collect.ImmutableMap; |
23 | 24 | import com.google.common.collect.Iterables; |
|
29 | 30 | import java.util.Map; |
30 | 31 | import java.util.Optional; |
31 | 32 | import java.util.concurrent.CompletableFuture; |
| 33 | +import java.util.concurrent.TimeUnit; |
32 | 34 | import java.util.concurrent.atomic.AtomicReference; |
33 | 35 | import java.util.function.Function; |
34 | 36 | import java.util.function.Supplier; |
@@ -149,14 +151,22 @@ public void connect() { |
149 | 151 | cb.password(password); |
150 | 152 | } |
151 | 153 |
|
152 | | - final ElasticSearch newOne = cb.build(); |
| 154 | + final var newOne = cb.build(); |
| 155 | + final var stopWatch = Stopwatch.createStarted(); |
153 | 156 | // Only swap the old / new after the new one established a new connection. |
154 | 157 | final CompletableFuture<ElasticSearchVersion> f = newOne.connect(); |
155 | 158 | f.whenComplete((ignored, exception) -> { |
| 159 | + stopWatch.stop(); |
156 | 160 | if (exception != null) { |
157 | 161 | log.error("Failed to recreate ElasticSearch client based on config", exception); |
158 | 162 | return; |
159 | 163 | } |
| 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 | + } |
160 | 170 | if (es.compareAndSet(oldOne, newOne)) { |
161 | 171 | oldOne.close(); |
162 | 172 | } else { |
|
0 commit comments