Skip to content

Commit 5e843af

Browse files
authored
Merge pull request #2660 from janeklb/jlb/log-formatted-duration
[client-v2] log duration in ISO-8601
2 parents d38c31b + 1d5368e commit 5e843af

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
### 0.9.4
1+
## 0.9.5
2+
3+
### New Features
4+
- [client-v2] Log durations in ISO-8601 duration format
5+
6+
## 0.9.4
27

38
### New Features
49
- [client-v2] Added support for different compression algorithms when HTTP compression is enabled. (https://github.com/ClickHouse/clickhouse-java/pull/2645)

client-v2/src/main/java/com/clickhouse/client/api/Client.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ public boolean ping(long timeout) {
11321132
return true;
11331133
}
11341134
} catch (Exception e) {
1135-
LOG.debug("Failed to connect to the server (Duration: {})", System.nanoTime() - startTime, e);
1135+
LOG.debug("Failed to connect to the server (Duration: {})", durationSince(startTime), e);
11361136
return false;
11371137
}
11381138
}
@@ -1277,7 +1277,7 @@ public CompletableFuture<InsertResponse> insert(String tableName, List<?> data,
12771277

12781278
// Check response
12791279
if (httpResponse.getCode() == HttpStatus.SC_SERVICE_UNAVAILABLE) {
1280-
LOG.warn("Failed to get response. Server returned {}. Retrying. (Duration: {})", httpResponse.getCode(), System.nanoTime() - startTime);
1280+
LOG.warn("Failed to get response. Server returned {}. Retrying. (Duration: {})", httpResponse.getCode(), durationSince(startTime));
12811281
selectedEndpoint = getNextAliveNode();
12821282
continue;
12831283
}
@@ -1292,7 +1292,7 @@ public CompletableFuture<InsertResponse> insert(String tableName, List<?> data,
12921292
return new InsertResponse(metrics);
12931293
} catch (Exception e) {
12941294
lastException = httpClientHelper.wrapException(String.format("Query request failed (Attempt: %s/%s - Duration: %s)",
1295-
(i + 1), (maxRetries + 1), System.nanoTime() - startTime), e);
1295+
(i + 1), (maxRetries + 1), durationSince(startTime)), e);
12961296
if (httpClientHelper.shouldRetry(e, requestSettings.getAllSettings())) {
12971297
LOG.warn("Retrying.", e);
12981298
selectedEndpoint = getNextAliveNode();
@@ -1301,7 +1301,7 @@ public CompletableFuture<InsertResponse> insert(String tableName, List<?> data,
13011301
}
13021302
}
13031303
}
1304-
throw new ClientException("Insert request failed after attempts: " + (maxRetries + 1) + " - Duration: " + (System.nanoTime() - startTime), lastException);
1304+
throw new ClientException("Insert request failed after attempts: " + (maxRetries + 1) + " - Duration: " + durationSince(startTime), lastException);
13051305
};
13061306

13071307
return runAsyncOperation(supplier, requestSettings.getAllSettings());
@@ -1480,7 +1480,7 @@ public CompletableFuture<InsertResponse> insert(String tableName,
14801480

14811481
// Check response
14821482
if (httpResponse.getCode() == HttpStatus.SC_SERVICE_UNAVAILABLE) {
1483-
LOG.warn("Failed to get response. Server returned {}. Retrying. (Duration: {})", System.nanoTime() - startTime, httpResponse.getCode());
1483+
LOG.warn("Failed to get response. Server returned {}. Retrying. (Duration: {})", httpResponse.getCode(), durationSince(startTime));
14841484
selectedEndpoint = getNextAliveNode();
14851485
continue;
14861486
}
@@ -1494,7 +1494,7 @@ public CompletableFuture<InsertResponse> insert(String tableName,
14941494
return new InsertResponse(metrics);
14951495
} catch (Exception e) {
14961496
lastException = httpClientHelper.wrapException(String.format("Insert failed (Attempt: %s/%s - Duration: %s)",
1497-
(i + 1), (retries + 1), System.nanoTime() - startTime), e);
1497+
(i + 1), (retries + 1), durationSince(startTime)), e);
14981498
if (httpClientHelper.shouldRetry(e, requestSettings.getAllSettings())) {
14991499
LOG.warn("Retrying.", e);
15001500
selectedEndpoint = getNextAliveNode();
@@ -1511,7 +1511,7 @@ public CompletableFuture<InsertResponse> insert(String tableName,
15111511
}
15121512
}
15131513
}
1514-
LOG.warn("Insert request failed after attempts: " + (retries + 1) + " - Duration: " + (System.nanoTime() - startTime));
1514+
LOG.warn("Insert request failed after attempts: {} - Duration: {}", retries + 1, durationSince(startTime));
15151515
throw (lastException == null ? new ClientException("Failed to complete insert operation") : lastException);
15161516
};
15171517

@@ -1603,7 +1603,7 @@ public CompletableFuture<QueryResponse> query(String sqlQuery, Map<String, Objec
16031603

16041604
// Check response
16051605
if (httpResponse.getCode() == HttpStatus.SC_SERVICE_UNAVAILABLE) {
1606-
LOG.warn("Failed to get response. Server returned {}. Retrying. (Duration: {})", System.nanoTime() - startTime, httpResponse.getCode());
1606+
LOG.warn("Failed to get response. Server returned {}. Retrying. (Duration: {})", httpResponse.getCode(), durationSince(startTime));
16071607
selectedEndpoint = getNextAliveNode();
16081608
HttpAPIClientHelper.closeQuietly(httpResponse);
16091609
continue;
@@ -1628,7 +1628,7 @@ public CompletableFuture<QueryResponse> query(String sqlQuery, Map<String, Objec
16281628
} catch (Exception e) {
16291629
HttpAPIClientHelper.closeQuietly(httpResponse);
16301630
lastException = httpClientHelper.wrapException(String.format("Query request failed (Attempt: %s/%s - Duration: %s)",
1631-
(i + 1), (retries + 1), System.nanoTime() - startTime), e);
1631+
(i + 1), (retries + 1), durationSince(startTime)), e);
16321632
if (httpClientHelper.shouldRetry(e, requestSettings.getAllSettings())) {
16331633
LOG.warn("Retrying.", e);
16341634
selectedEndpoint = getNextAliveNode();
@@ -1637,7 +1637,7 @@ public CompletableFuture<QueryResponse> query(String sqlQuery, Map<String, Objec
16371637
}
16381638
}
16391639
}
1640-
LOG.warn("Query request failed after attempts: " + (retries + 1) + " - Duration: " + (System.nanoTime() - startTime));
1640+
LOG.warn("Query request failed after attempts: {} - Duration: {}", retries + 1, durationSince(startTime));
16411641
throw (lastException == null ? new ClientException("Failed to complete query") : lastException);
16421642
};
16431643

@@ -2115,4 +2115,7 @@ private Map<String, Object> buildRequestSettings(Map<String, Object> opSettings)
21152115
return requestSettings;
21162116
}
21172117

2118+
private Duration durationSince(long sinceNanos) {
2119+
return Duration.ofNanos(System.nanoTime() - sinceNanos);
2120+
}
21182121
}

0 commit comments

Comments
 (0)