|
21 | 21 | import com.clickhouse.client.api.internal.TableSchemaParser; |
22 | 22 | import com.clickhouse.client.api.internal.ValidationUtils; |
23 | 23 | import com.clickhouse.client.api.metadata.TableSchema; |
| 24 | +import com.clickhouse.client.api.internal.ClientStatisticsHolder; |
| 25 | +import com.clickhouse.client.api.metrics.ClientMetrics; |
24 | 26 | import com.clickhouse.client.api.query.GenericRecord; |
25 | 27 | import com.clickhouse.client.api.query.QueryResponse; |
26 | 28 | import com.clickhouse.client.api.query.QuerySettings; |
@@ -103,7 +105,7 @@ public class Client { |
103 | 105 | private static final Logger LOG = LoggerFactory.getLogger(Client.class); |
104 | 106 | private ExecutorService queryExecutor; |
105 | 107 |
|
106 | | - private Map<String, OperationStatistics.ClientStatistics> globalClientStats = new ConcurrentHashMap<>(); |
| 108 | + private Map<String, ClientStatisticsHolder> globalClientStats = new ConcurrentHashMap<>(); |
107 | 109 |
|
108 | 110 | private Client(Set<String> endpoints, Map<String,String> configuration) { |
109 | 111 | this.endpoints = endpoints; |
@@ -526,7 +528,7 @@ public CompletableFuture<InsertResponse> insert(String tableName, List<?> data, |
526 | 528 |
|
527 | 529 | String operationId = startOperation(); |
528 | 530 | settings.setOperationId(operationId); |
529 | | - globalClientStats.get(operationId).start("serialization"); |
| 531 | + globalClientStats.get(operationId).start(ClientMetrics.OP_SERIALIZATION); |
530 | 532 |
|
531 | 533 | if (data == null || data.isEmpty()) { |
532 | 534 | throw new IllegalArgumentException("Data cannot be empty"); |
@@ -560,7 +562,7 @@ public CompletableFuture<InsertResponse> insert(String tableName, List<?> data, |
560 | 562 | } |
561 | 563 | } |
562 | 564 |
|
563 | | - globalClientStats.get(operationId).stop("serialization"); |
| 565 | + globalClientStats.get(operationId).stop(ClientMetrics.OP_SERIALIZATION); |
564 | 566 | LOG.debug("Total serialization time: {}", globalClientStats.get(operationId).getElapsedTime("serialization")); |
565 | 567 | return insert(tableName, new ByteArrayInputStream(stream.toByteArray()), format, settings); |
566 | 568 | } |
@@ -598,8 +600,8 @@ public CompletableFuture<InsertResponse> insert(String tableName, |
598 | 600 | operationId = startOperation(); |
599 | 601 | settings.setOperationId(operationId); |
600 | 602 | } |
601 | | - OperationStatistics.ClientStatistics clientStats = globalClientStats.remove(operationId); |
602 | | - clientStats.start("insert"); |
| 603 | + ClientStatisticsHolder clientStats = globalClientStats.remove(operationId); |
| 604 | + clientStats.start(ClientMetrics.OP_DURATION); |
603 | 605 |
|
604 | 606 | CompletableFuture<InsertResponse> responseFuture = new CompletableFuture<>(); |
605 | 607 |
|
@@ -627,7 +629,6 @@ public CompletableFuture<InsertResponse> insert(String tableName, |
627 | 629 | responseFuture.completeExceptionally(new ClientException("Operation has likely timed out.", e)); |
628 | 630 | } |
629 | 631 | } |
630 | | - clientStats.stop("insert"); |
631 | 632 | LOG.debug("Total insert (InputStream) time: {}", clientStats.getElapsedTime("insert")); |
632 | 633 | } |
633 | 634 |
|
@@ -695,8 +696,8 @@ public CompletableFuture<QueryResponse> query(String sqlQuery, Map<String, Objec |
695 | 696 | if (settings.getFormat() == null) { |
696 | 697 | settings.setFormat(ClickHouseFormat.RowBinaryWithNamesAndTypes); |
697 | 698 | } |
698 | | - OperationStatistics.ClientStatistics clientStats = new OperationStatistics.ClientStatistics(); |
699 | | - clientStats.start("query"); |
| 699 | + ClientStatisticsHolder clientStats = new ClientStatisticsHolder(); |
| 700 | + clientStats.start(ClientMetrics.OP_DURATION); |
700 | 701 | ClickHouseClient client = createClient(); |
701 | 702 | ClickHouseRequest<?> request = client.read(getServerNode()); |
702 | 703 |
|
@@ -751,7 +752,7 @@ public CompletableFuture<Records> queryRecords(String sqlQuery, QuerySettings se |
751 | 752 | settings = new QuerySettings(); |
752 | 753 | } |
753 | 754 | settings.setFormat(ClickHouseFormat.RowBinaryWithNamesAndTypes); |
754 | | - OperationStatistics.ClientStatistics clientStats = new OperationStatistics.ClientStatistics(); |
| 755 | + ClientStatisticsHolder clientStats = new ClientStatisticsHolder(); |
755 | 756 | clientStats.start("query"); |
756 | 757 | ClickHouseClient client = createClient(); |
757 | 758 | ClickHouseRequest<?> request = client.read(getServerNode()); |
@@ -865,7 +866,7 @@ private ClickHouseRequest.Mutation createMutationRequest(ClickHouseRequest.Mutat |
865 | 866 |
|
866 | 867 | private String startOperation() { |
867 | 868 | String operationId = UUID.randomUUID().toString(); |
868 | | - globalClientStats.put(operationId, new OperationStatistics.ClientStatistics()); |
| 869 | + globalClientStats.put(operationId, new ClientStatisticsHolder()); |
869 | 870 | return operationId; |
870 | 871 | } |
871 | 872 | } |
0 commit comments