Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue-1774: Method to retrieve info about client connections was added #1796

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

testisnullus
Copy link

In this PR a new custom type connectionType was added to categorize different stages of client connections within a Cassandra cluster. Additionally, the ClientConnection struct was introduced to encapsulate detailed information about each connection, such as client address, connection stage, driver details, and SSL configuration. A new method, RetrieveClientConnections, was implemented to retrieve client connections based on their connection stage from the system_views.clients table.

@testisnullus testisnullus changed the title issue-1774: Function to retrieve info about client connections was added issue-1774: Method to retrieve info about client connections was added Aug 13, 2024
session.go Outdated
// 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) {
query := "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 = ?"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should follow the general pattern of code styling for similar methods that are used for querying some system/system_views tables. So you should define this query as a string const and use idents as well. You may find some examples in the Session.KeyspaceMetadata() method

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, fixed

session.go Outdated
Comment on lines 799 to 833
type ClientConnection struct {
Address string `json:"address"`
Port int `json:"port"`
ConnectionStage string `json:"connection_stage"`
DriverName string `json:"driver_name"`
DriverVersion string `json:"driver_version"`
Hostname string `json:"hostname"`
KeyspaceName *string `json:"keyspace_name"`
ProtocolVersion int `json:"protocol_version"`
RequestCount int `json:"request_count"`
SSLCipherSuite *string `json:"ssl_cipher_suite"`
SSLEnabled bool `json:"ssl_enabled"`
SSLProtocol *string `json:"ssl_protocol"`
Username string `json:"username"`
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these json tags really necessary?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed, removed

session.go Outdated

iter := s.control.query(stmt, connectionType)
if iter.NumRows() == 0 {
return nil, ErrKeyspaceDoesNotExist

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I missed this before. I think you should return an error related to connectionType, not keyspace

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, fixed, ty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants