diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fb83abdc..d5c9b58b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ -### 0.9.4 +## 0.9.5 + +### New Features +- [client-v2] Log durations in ISO-8601 duration format + +## 0.9.4 ### New Features - [client-v2] Added support for different compression algorithms when HTTP compression is enabled. (https://github.com/ClickHouse/clickhouse-java/pull/2645) diff --git a/client-v2/src/main/java/com/clickhouse/client/api/Client.java b/client-v2/src/main/java/com/clickhouse/client/api/Client.java index b17562b74..c5604ea39 100644 --- a/client-v2/src/main/java/com/clickhouse/client/api/Client.java +++ b/client-v2/src/main/java/com/clickhouse/client/api/Client.java @@ -1132,7 +1132,7 @@ public boolean ping(long timeout) { return true; } } catch (Exception e) { - LOG.debug("Failed to connect to the server (Duration: {})", System.nanoTime() - startTime, e); + LOG.debug("Failed to connect to the server (Duration: {})", durationSince(startTime), e); return false; } } @@ -1277,7 +1277,7 @@ public CompletableFuture insert(String tableName, List data, // Check response if (httpResponse.getCode() == HttpStatus.SC_SERVICE_UNAVAILABLE) { - LOG.warn("Failed to get response. Server returned {}. Retrying. (Duration: {})", httpResponse.getCode(), System.nanoTime() - startTime); + LOG.warn("Failed to get response. Server returned {}. Retrying. (Duration: {})", httpResponse.getCode(), durationSince(startTime)); selectedEndpoint = getNextAliveNode(); continue; } @@ -1292,7 +1292,7 @@ public CompletableFuture insert(String tableName, List data, return new InsertResponse(metrics); } catch (Exception e) { lastException = httpClientHelper.wrapException(String.format("Query request failed (Attempt: %s/%s - Duration: %s)", - (i + 1), (maxRetries + 1), System.nanoTime() - startTime), e); + (i + 1), (maxRetries + 1), durationSince(startTime)), e); if (httpClientHelper.shouldRetry(e, requestSettings.getAllSettings())) { LOG.warn("Retrying.", e); selectedEndpoint = getNextAliveNode(); @@ -1301,7 +1301,7 @@ public CompletableFuture insert(String tableName, List data, } } } - throw new ClientException("Insert request failed after attempts: " + (maxRetries + 1) + " - Duration: " + (System.nanoTime() - startTime), lastException); + throw new ClientException("Insert request failed after attempts: " + (maxRetries + 1) + " - Duration: " + durationSince(startTime), lastException); }; return runAsyncOperation(supplier, requestSettings.getAllSettings()); @@ -1480,7 +1480,7 @@ public CompletableFuture insert(String tableName, // Check response if (httpResponse.getCode() == HttpStatus.SC_SERVICE_UNAVAILABLE) { - LOG.warn("Failed to get response. Server returned {}. Retrying. (Duration: {})", System.nanoTime() - startTime, httpResponse.getCode()); + LOG.warn("Failed to get response. Server returned {}. Retrying. (Duration: {})", httpResponse.getCode(), durationSince(startTime)); selectedEndpoint = getNextAliveNode(); continue; } @@ -1494,7 +1494,7 @@ public CompletableFuture insert(String tableName, return new InsertResponse(metrics); } catch (Exception e) { lastException = httpClientHelper.wrapException(String.format("Insert failed (Attempt: %s/%s - Duration: %s)", - (i + 1), (retries + 1), System.nanoTime() - startTime), e); + (i + 1), (retries + 1), durationSince(startTime)), e); if (httpClientHelper.shouldRetry(e, requestSettings.getAllSettings())) { LOG.warn("Retrying.", e); selectedEndpoint = getNextAliveNode(); @@ -1511,7 +1511,7 @@ public CompletableFuture insert(String tableName, } } } - LOG.warn("Insert request failed after attempts: " + (retries + 1) + " - Duration: " + (System.nanoTime() - startTime)); + LOG.warn("Insert request failed after attempts: {} - Duration: {}", retries + 1, durationSince(startTime)); throw (lastException == null ? new ClientException("Failed to complete insert operation") : lastException); }; @@ -1603,7 +1603,7 @@ public CompletableFuture query(String sqlQuery, Map query(String sqlQuery, Map query(String sqlQuery, Map buildRequestSettings(Map opSettings) return requestSettings; } + private Duration durationSince(long sinceNanos) { + return Duration.ofNanos(System.nanoTime() - sinceNanos); + } }