|
23 | 23 | import com.clickhouse.client.api.internal.TableSchemaParser; |
24 | 24 | import com.clickhouse.client.api.internal.ValidationUtils; |
25 | 25 | import com.clickhouse.client.api.metadata.TableSchema; |
| 26 | +import com.clickhouse.client.api.internal.ClientStatisticsHolder; |
| 27 | +import com.clickhouse.client.api.metrics.ClientMetrics; |
26 | 28 | import com.clickhouse.client.api.query.GenericRecord; |
27 | 29 | import com.clickhouse.client.api.query.QueryResponse; |
28 | 30 | import com.clickhouse.client.api.query.QuerySettings; |
@@ -106,7 +108,7 @@ public class Client { |
106 | 108 | private static final Logger LOG = LoggerFactory.getLogger(Client.class); |
107 | 109 | private ExecutorService queryExecutor; |
108 | 110 |
|
109 | | - private Map<String, OperationStatistics.ClientStatistics> globalClientStats = new ConcurrentHashMap<>(); |
| 111 | + private Map<String, ClientStatisticsHolder> globalClientStats = new ConcurrentHashMap<>(); |
110 | 112 |
|
111 | 113 | private Client(Set<String> endpoints, Map<String,String> configuration) { |
112 | 114 | this.endpoints = endpoints; |
@@ -540,7 +542,7 @@ public CompletableFuture<InsertResponse> insert(String tableName, List<?> data, |
540 | 542 |
|
541 | 543 | String operationId = startOperation(); |
542 | 544 | settings.setOperationId(operationId); |
543 | | - globalClientStats.get(operationId).start("serialization"); |
| 545 | + globalClientStats.get(operationId).start(ClientMetrics.OP_SERIALIZATION); |
544 | 546 |
|
545 | 547 | if (data == null || data.isEmpty()) { |
546 | 548 | throw new IllegalArgumentException("Data cannot be empty"); |
@@ -574,7 +576,7 @@ public CompletableFuture<InsertResponse> insert(String tableName, List<?> data, |
574 | 576 | } |
575 | 577 | } |
576 | 578 |
|
577 | | - globalClientStats.get(operationId).stop("serialization"); |
| 579 | + globalClientStats.get(operationId).stop(ClientMetrics.OP_SERIALIZATION); |
578 | 580 | LOG.debug("Total serialization time: {}", globalClientStats.get(operationId).getElapsedTime("serialization")); |
579 | 581 | return insert(tableName, new ByteArrayInputStream(stream.toByteArray()), format, settings); |
580 | 582 | } |
@@ -609,8 +611,8 @@ public CompletableFuture<InsertResponse> insert(String tableName, |
609 | 611 | operationId = startOperation(); |
610 | 612 | settings.setOperationId(operationId); |
611 | 613 | } |
612 | | - OperationStatistics.ClientStatistics clientStats = globalClientStats.remove(operationId); |
613 | | - clientStats.start("insert"); |
| 614 | + ClientStatisticsHolder clientStats = globalClientStats.remove(operationId); |
| 615 | + clientStats.start(ClientMetrics.OP_DURATION); |
614 | 616 |
|
615 | 617 | CompletableFuture<InsertResponse> responseFuture = new CompletableFuture<>(); |
616 | 618 |
|
@@ -638,7 +640,6 @@ public CompletableFuture<InsertResponse> insert(String tableName, |
638 | 640 | responseFuture.completeExceptionally(new ClientException("Operation has likely timed out.", e)); |
639 | 641 | } |
640 | 642 | } |
641 | | - clientStats.stop("insert"); |
642 | 643 | LOG.debug("Total insert (InputStream) time: {}", clientStats.getElapsedTime("insert")); |
643 | 644 | } |
644 | 645 |
|
@@ -706,8 +707,8 @@ public CompletableFuture<QueryResponse> query(String sqlQuery, Map<String, Objec |
706 | 707 | if (settings.getFormat() == null) { |
707 | 708 | settings.setFormat(ClickHouseFormat.RowBinaryWithNamesAndTypes); |
708 | 709 | } |
709 | | - OperationStatistics.ClientStatistics clientStats = new OperationStatistics.ClientStatistics(); |
710 | | - clientStats.start("query"); |
| 710 | + ClientStatisticsHolder clientStats = new ClientStatisticsHolder(); |
| 711 | + clientStats.start(ClientMetrics.OP_DURATION); |
711 | 712 | ClickHouseClient client = createClient(); |
712 | 713 | ClickHouseRequest<?> request = client.read(getServerNode()); |
713 | 714 |
|
@@ -762,7 +763,7 @@ public CompletableFuture<Records> queryRecords(String sqlQuery, QuerySettings se |
762 | 763 | settings = new QuerySettings(); |
763 | 764 | } |
764 | 765 | settings.setFormat(ClickHouseFormat.RowBinaryWithNamesAndTypes); |
765 | | - OperationStatistics.ClientStatistics clientStats = new OperationStatistics.ClientStatistics(); |
| 766 | + ClientStatisticsHolder clientStats = new ClientStatisticsHolder(); |
766 | 767 | clientStats.start("query"); |
767 | 768 | ClickHouseClient client = createClient(); |
768 | 769 | ClickHouseRequest<?> request = client.read(getServerNode()); |
@@ -876,7 +877,7 @@ private ClickHouseRequest.Mutation createMutationRequest(ClickHouseRequest.Mutat |
876 | 877 |
|
877 | 878 | private String startOperation() { |
878 | 879 | String operationId = UUID.randomUUID().toString(); |
879 | | - globalClientStats.put(operationId, new OperationStatistics.ClientStatistics()); |
| 880 | + globalClientStats.put(operationId, new ClientStatisticsHolder()); |
880 | 881 | return operationId; |
881 | 882 | } |
882 | 883 |
|
|
0 commit comments