testisnullus commented on code in PR #1796: URL: https://github.com/apache/cassandra-gocql-driver/pull/1796#discussion_r1716642579
########## session.go: ########## @@ -780,6 +780,95 @@ func (s *Session) MapExecuteBatchCAS(batch *Batch, dest map[string]interface{}) return applied, iter, iter.err } +// connectionType is a custom type that represents the different stages +// of a client connection in a Cassandra cluster. It is used to filter and categorize +// connections based on their current state. +type connectionType string + +const ( + Ready connectionType = "ready" + Connecting connectionType = "connecting" + Idle connectionType = "idle" + Closed connectionType = "closed" + Failed connectionType = "failed" +) + +// ClientConnection represents a client connection to a Cassandra node. It holds detailed +// information about the connection, including the client address, connection stage, driver details, +// and various configuration options. +type ClientConnection struct { + Address string + Port int + ConnectionStage string + DriverName string + DriverVersion string + Hostname string + KeyspaceName *string + ProtocolVersion int + RequestCount int + SSLCipherSuite *string + SSLEnabled bool + SSLProtocol *string + Username string +} + +// RetrieveClientConnections retrieves a list of client connections from the +// `system_views.clients` table based on the specified connection type. The function +// queries the Cassandra database for connections with a given `connection_stage` and +// scans the results into a slice of `ClientConnection` structs. It handles nullable +// fields and returns the list of connections or an error if the operation fails. +func (s *Session) RetrieveClientConnections(connectionType connectionType) ([]*ClientConnection, error) { + const stmt = ` + SELECT address, port, connection_stage, driver_name, driver_version, + hostname, keyspace_name, protocol_version, request_count, + ssl_cipher_suite, ssl_enabled, ssl_protocol, username + FROM system_views.clients + WHERE connection_stage = ?` + + iter := s.control.query(stmt, connectionType) + if iter.NumRows() == 0 { + return nil, ErrKeyspaceDoesNotExist Review Comment: Oops, fixed, ty -- 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: commits-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org