From 8ef626bfb1a74d7eac13f652f9c583cf0f0c0d51 Mon Sep 17 00:00:00 2001 From: Serhii Avsheniuk Date: Mon, 23 Jun 2025 13:01:31 +0200 Subject: [PATCH 1/3] Fix bug with incorrect usage of Integer where Long is expected. Metrics returned from the server can overflow Integer e.g. when elapsed time is higher than 2 seconds (it's in nanoseconds). --- .../api/data_formats/internal/ProcessParser.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/ProcessParser.java b/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/ProcessParser.java index 3f583dbb9..1b124df16 100644 --- a/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/ProcessParser.java +++ b/client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/ProcessParser.java @@ -22,7 +22,7 @@ public class ProcessParser { }; public static void parseSummary(String text, OperationMetrics metrics) { - Map map = parse(text == null ? "{}" : text); + Map map = parse(text == null ? "{}" : text); for (ServerMetrics m : ServerMetrics.values()) { metrics.updateMetric(m, -1); @@ -30,7 +30,7 @@ public static void parseSummary(String text, OperationMetrics metrics) { for (int i = 0; i < SUMMARY_FIELDS.length; i++) { String field = SUMMARY_FIELDS[i]; - Integer value = map.get(field); + Long value = map.get(field); if (value != null) { metrics.updateMetric(SUMMARY_METRICS[i], value); } @@ -38,7 +38,7 @@ public static void parseSummary(String text, OperationMetrics metrics) { } - public static Map parse(String json) { + public static Map parse(String json) { if (json == null) { throw new IllegalArgumentException("json is null"); } @@ -50,7 +50,7 @@ public static Map parse(String json) { throw new IllegalArgumentException("JSON must start with '{' and end with '}'"); } - Map result = new HashMap<>(); + Map result = new HashMap<>(); String content = json.substring(1, json.length() - 1).trim(); if (content.isEmpty()) { @@ -79,7 +79,7 @@ public static Map parse(String json) { } try { - int value = Integer.parseInt(valueStr); + long value = Long.parseLong(valueStr); result.put(key, value); } catch (NumberFormatException e) { // ignore error From 6a5d073371d66845cd93de19b44be074aa775bb2 Mon Sep 17 00:00:00 2001 From: Serhii Avsheniuk Date: Mon, 23 Jun 2025 13:01:51 +0200 Subject: [PATCH 2/3] Use generic name instead of specific metric name. --- .../main/java/com/clickhouse/client/api/internal/Gauge.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client-v2/src/main/java/com/clickhouse/client/api/internal/Gauge.java b/client-v2/src/main/java/com/clickhouse/client/api/internal/Gauge.java index f83f653fc..e76f6761e 100644 --- a/client-v2/src/main/java/com/clickhouse/client/api/internal/Gauge.java +++ b/client-v2/src/main/java/com/clickhouse/client/api/internal/Gauge.java @@ -6,8 +6,8 @@ public class Gauge implements Metric { private volatile long value; - public Gauge(long readRows) { - this.value = readRows; + public Gauge(long value) { + this.value = value; } public void set(long value) { From ea6f9161b18de04d906325b5b77c1310a1e77384 Mon Sep 17 00:00:00 2001 From: Serhii Avsheniuk Date: Mon, 23 Jun 2025 13:02:11 +0200 Subject: [PATCH 3/3] Update misleading Javadocs for client side metrics. Stopwatch metrics always convert nanoseconds to milliseconds when getLong() is called on them. --- .../java/com/clickhouse/client/api/metrics/ClientMetrics.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client-v2/src/main/java/com/clickhouse/client/api/metrics/ClientMetrics.java b/client-v2/src/main/java/com/clickhouse/client/api/metrics/ClientMetrics.java index c21becbcf..2711ef18e 100644 --- a/client-v2/src/main/java/com/clickhouse/client/api/metrics/ClientMetrics.java +++ b/client-v2/src/main/java/com/clickhouse/client/api/metrics/ClientMetrics.java @@ -3,12 +3,12 @@ public enum ClientMetrics { /** - * Operation duration in nanoseconds. + * Operation duration in milliseconds. */ OP_DURATION("client.opDuration"), /** - * Duration of the operation serialization step in nanoseconds. + * Duration of the operation serialization step in milliseconds. */ OP_SERIALIZATION("client.opSerialization");