frankgh commented on code in PR #135: URL: https://github.com/apache/cassandra-sidecar/pull/135#discussion_r1776120713
########## adapters/base/src/main/java/org/apache/cassandra/sidecar/adapters/base/db/ConnectedClientStats.java: ########## @@ -0,0 +1,210 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cassandra.sidecar.adapters.base.db; + +import java.util.Map; + +import com.datastax.driver.core.Row; +import org.apache.cassandra.sidecar.common.DataObjectBuilder; +import org.apache.cassandra.sidecar.db.DataObjectMappingException; +import org.jetbrains.annotations.NotNull; + +/** + * Representation of the connected clients metadata + */ +public class ConnectedClientStats +{ + + public final String address; + public final int port; + public final String hostname; + public final String username; + public final String connectionStage; + public final String protocolVersion; + public final Map<String, String> clientOptions; + public final String driverName; + public final String driverVersion; + public final boolean sslEnabled; + public final String sslProtocol; + public final String sslCipherSuite; + public final String keyspaceName; + public final int requestCount; + public final String authenticationMode; + public final Map<String, String> authMetadata; + + public static ConnectedClientStats.Builder builder() + { + return new ConnectedClientStats.Builder(); + } + + public static ConnectedClientStats from(@NotNull Row row) throws DataObjectMappingException + { + ConnectedClientStats.Builder builder = new ConnectedClientStats.Builder(); Review Comment: builder seems unnecessary here. Can we have a simple constructor and simplify? ########## adapters/base/src/main/java/org/apache/cassandra/sidecar/adapters/base/db/ConnectedClientStatsSummary.java: ########## @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cassandra.sidecar.adapters.base.db; + +import java.util.Map; +import java.util.stream.Collectors; + +import com.datastax.driver.core.ResultSet; +import org.apache.cassandra.sidecar.common.DataObjectBuilder; +import org.apache.cassandra.sidecar.db.DataObjectMappingException; +import org.jetbrains.annotations.NotNull; + +/** + * Representation of a summary of client connections stats + */ +public class ConnectedClientStatsSummary +{ + public final int totalConnectedClients; + public final Map<String, Long> connectionsByUser; + + public static ConnectedClientStatsSummary.Builder builder() + { + return new ConnectedClientStatsSummary.Builder(); + } + + public static ConnectedClientStatsSummary from(@NotNull ResultSet resultSet) throws DataObjectMappingException + { + + Map<String, Long> resultMap = resultSet.all().stream() + .collect(Collectors.toMap(r -> r.getString("username"), + r -> r.getLong("connection_count"))); + int totalConnections = resultMap.values().stream().mapToInt(Math::toIntExact).sum(); + + ConnectedClientStatsSummary.Builder builder = new ConnectedClientStatsSummary.Builder(); + builder.connectionsByUser(resultMap); + builder.totalConnectedClients(totalConnections); + + return builder.build(); + } + + private ConnectedClientStatsSummary(ConnectedClientStatsSummary.Builder builder) Review Comment: simplify by removing the builder? ########## client-common/src/main/java/org/apache/cassandra/sidecar/common/response/data/SidecarSchemaModificationException.java: ########## @@ -16,7 +16,7 @@ * limitations under the License. */ -package org.apache.cassandra.sidecar.exceptions; +package org.apache.cassandra.sidecar.common.response.data; Review Comment: can we preserve the package ? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

