From 8c2dfd1ed6d0a44989a89f18d4b9a816484ae277 Mon Sep 17 00:00:00 2001 From: Janek Lasocki-Biczysko Date: Mon, 17 Nov 2025 20:50:35 +0000 Subject: [PATCH 1/3] [client-v2] log duration in ISO-8601 --- .../com/clickhouse/client/api/Client.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) 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..d21c95c79 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: {})", durationSince(startTime), httpResponse.getCode()); 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); + } } From ef8486af60ef8b17efa03cb74b35d644d8d288aa Mon Sep 17 00:00:00 2001 From: Janek Lasocki-Biczysko Date: Mon, 17 Nov 2025 20:53:13 +0000 Subject: [PATCH 2/3] update CHANGELOG.md --- CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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) From 1d5368ea02ca9915e9df6bba75422abb9e91cb5d Mon Sep 17 00:00:00 2001 From: Janek Lasocki-Biczysko Date: Mon, 17 Nov 2025 21:04:30 +0000 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: windsurf-bot[bot] <189301087+windsurf-bot[bot]@users.noreply.github.com> --- client-v2/src/main/java/com/clickhouse/client/api/Client.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 d21c95c79..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 @@ -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: {})", durationSince(startTime), httpResponse.getCode()); + LOG.warn("Failed to get response. Server returned {}. Retrying. (Duration: {})", httpResponse.getCode(), durationSince(startTime)); selectedEndpoint = getNextAliveNode(); continue; } @@ -1603,7 +1603,7 @@ public CompletableFuture query(String sqlQuery, Map