Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

cluster: add application_info #486

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

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

Conversation

dkropachev
Copy link
Collaborator

@dkropachev dkropachev commented Jun 5, 2025

Implement clustr.application_info to make driver send following startup options to server:

  1. APPLICATION_NAME - ID what application is using driver, example: repo of the application
  2. APPLICATION_VERSION - Version of the application, example: release version or commit id of the application
  3. CLIENT_ID - unique id of the client instance, example: pod name

All strings.

Fix: #485

Results:

cqlsh> SELECT * FROM system_views.clients;

 address    | port  | client_options                                                                                                                                                                             | connection_stage | driver_name            | driver_version | hostname   | keyspace_name | protocol_version | request_count | ssl_cipher_suite | ssl_enabled | ssl_protocol | username
------------+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------+------------------------+----------------+------------+---------------+------------------+---------------+------------------+-------------+--------------+-----------
 172.17.0.1 | 55756 | {'APPLICATION_NAME': 'app_name', 'APPLICATION_VERSION': '1.1.1', 'CLIENT_ID': 'my_client_id', 'CQL_VERSION': '3.4.7', 'DRIVER_NAME': 'ScyllaDB Python Driver', 'DRIVER_VERSION': '3.29.3'} |            ready | ScyllaDB Python Driver |         3.29.3 | 172.17.0.1 |          null |                5 |            16 |             null |       False |         null | anonymous
 172.17.0.1 | 55762 | {'APPLICATION_NAME': 'app_name', 'APPLICATION_VERSION': '1.1.1', 'CLIENT_ID': 'my_client_id', 'CQL_VERSION': '3.4.7', 'DRIVER_NAME': 'ScyllaDB Python Driver', 'DRIVER_VERSION': '3.29.3'} |            ready | ScyllaDB Python Driver |         3.29.3 | 172.17.0.1 |          null |                5 |             1 |             null |       False |         null | anonymous

(4 rows)

Pre-review checklist

  • I have split my patch into logically separate commits.
  • All commit messages clearly explain what they change and why.
  • I added relevant tests for new features and bug fixes.
  • All commits compile, pass static checks and pass test.
  • PR description sums up the changes and reasons why they should be introduced.
  • I have provided docstrings for the public items that I want to introduce.
  • I have adjusted the documentation in ./docs/source/.
  • I added appropriate Fixes: annotations to PR description.

@dkropachev dkropachev linked an issue Jun 5, 2025 that may be closed by this pull request
@dkropachev dkropachev self-assigned this Jun 5, 2025
@dkropachev dkropachev requested a review from Lorak-mmk June 5, 2025 02:20
Copy link

@Lorak-mmk Lorak-mmk left a comment

Choose a reason for hiding this comment

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

Please also add an integration test running on C* that uses the new API and verifies the data in client_info.

Comment on lines 722 to 717
application_info = None
"""
An instance of :class:`.cluster.ApplicationInfo` or one of its subclasses.

Defaults to None

When not None makes driver sends information about application that uses driver in startup frame
"""

Choose a reason for hiding this comment

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

Can we make the field private (I mean name starting with underscore)? It will be clearer that it is not meant to be edited by user, but only set using the constructor.

Choose a reason for hiding this comment

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

Also please add a type hint for the field.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Comment on lines 514 to 524
class ApplicationInfo(object):
def __init__(self, application_name=None, application_version=None, client_id=None):
if not isinstance(application_name, str):
raise TypeError('application_name must be a string')
if not isinstance(application_version, str):
raise TypeError('application_version must be a string')
if not isinstance(client_id, str):
raise TypeError('client_id must be a string')
self.application_name = application_name
self.application_version = application_version
self.client_id = client_id

Choose a reason for hiding this comment

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

I don't understand the purpose of this logic. You are defaulting all the args to None, but in the body you require them to be str, so the constructor will fail unless all the args are provided. Why not make them mandatory in this case? Or change the body to allow None - I don't know which semantics you intended here.

Also, could you add type hints? I know rest of the driver doesn't have them, but we can use them in new code to aid users.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed, added type hints.

Comment on lines 1355 to 1352
if application_info is not None:
if isinstance(application_info, type):
raise TypeError("application_info should not be a class, it should be an instance of ApplicationInfo class")
if not isinstance(application_info, ApplicationInfo):
raise TypeError(
"application_info should be an instance of ApplicationInfo class")
self.application_info = application_info

Choose a reason for hiding this comment

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

Why do you have two checks? What is the situation where the first check (isinstance(application_info, type)) will be triggered, but second one won't?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed

Choose a reason for hiding this comment

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

What was the purpose of having two checks? You must have had some reason to do this, and I'd like to understand it.

Comment on lines 798 to 803
self.orphaned_request_ids = set()
self._on_orphaned_stream_released = on_orphaned_stream_released
self.application_info = application_info

if ssl_options:

Choose a reason for hiding this comment

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

Could you make the field private (underscore), and add it to the class (with type hint)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Comment on lines 1443 to 1449
if self.application_info:
if self.application_info.application_name:
opts['APPLICATION_NAME'] = self.application_info.application_name
if self.application_info.application_version:
opts['APPLICATION_VERSION'] = self.application_info.application_version
if self.application_info.client_id:
opts['CLIENT_ID'] = self.application_info.client_id

Choose a reason for hiding this comment

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

Maybe a bit cleaner way would be to have a (private) method on ApplicationInfo that takes a dict and sets those values? That way Connection doesn't need to know ApplicationInfo internals.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good idea, done.

@dkropachev dkropachev force-pushed the dk/485-report-application-information-to-server branch 2 times, most recently from 8c02393 to d7d7385 Compare June 6, 2025 11:33
Implement clustr.application_info to make driver send following startup options to server:
1. `APPLICATION_NAME` - ID what application is using driver, example: repo of the application
2. `APPLICATION_VERSION` - Version of the application, example: release version or commit id of the application
3. `CLIENT_ID` - unique id of the client instance, example: pod name

All strings.
@dkropachev dkropachev force-pushed the dk/485-report-application-information-to-server branch from d7d7385 to 7e0a9d2 Compare June 6, 2025 11:46
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.

Report application information to server
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.