forked from apache/cassandra-python-driver
-
Notifications
You must be signed in to change notification settings - Fork 49
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
Merged
dkropachev
merged 1 commit into
master
from
dk/485-report-application-information-to-server
Jun 12, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # Copyright 2025 ScyllaDB, Inc. | ||
| # | ||
| # Licensed 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. | ||
| from typing import Optional | ||
|
|
||
|
|
||
| class ApplicationInfoBase: | ||
| """ | ||
| A class that holds application information and adds it to startup message options | ||
| """ | ||
| def add_startup_options(self, options: dict[str, str]): | ||
| raise NotImplementedError() | ||
|
|
||
|
|
||
| class ApplicationInfo(ApplicationInfoBase): | ||
| application_name: Optional[str] | ||
| application_version: Optional[str] | ||
| client_id: Optional[str] | ||
|
|
||
| def __init__( | ||
| self, | ||
| application_name: Optional[str] = None, | ||
| application_version: Optional[str] = None, | ||
| client_id: Optional[str] = None | ||
| ): | ||
| if application_name and not isinstance(application_name, str): | ||
| raise TypeError('application_name must be a string') | ||
| if application_version and not isinstance(application_version, str): | ||
| raise TypeError('application_version must be a string') | ||
| if client_id and 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 | ||
|
|
||
| def add_startup_options(self, options: dict[str, str]): | ||
| if self.application_name: | ||
| options['APPLICATION_NAME'] = self.application_name | ||
| if self.application_version: | ||
| options['APPLICATION_VERSION'] = self.application_version | ||
| if self.client_id: | ||
| options['CLIENT_ID'] = self.client_id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| # Copyright 2025 ScyllaDB, Inc. | ||
| # | ||
| # Licensed 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. | ||
|
|
||
| import unittest | ||
|
|
||
| from cassandra.application_info import ApplicationInfo | ||
| from tests.integration import TestCluster, use_single_node, remove_cluster, xfail_scylla | ||
|
|
||
|
|
||
| def setup_module(): | ||
| use_single_node() | ||
|
|
||
|
|
||
| def teardown_module(): | ||
| remove_cluster() | ||
|
|
||
|
|
||
| @xfail_scylla("#scylladb/scylla-enterprise#5467 - not released yet") | ||
| class ApplicationInfoTest(unittest.TestCase): | ||
| attribute_to_startup_key = { | ||
| 'application_name': 'APPLICATION_NAME', | ||
| 'application_version': 'APPLICATION_VERSION', | ||
| 'client_id': 'CLIENT_ID', | ||
| } | ||
|
|
||
| def test_create_session_and_check_system_views_clients(self): | ||
| """ | ||
| Test to ensure that ApplicationInfo user provides endup in `client_options` of `system_views.clients` table | ||
| """ | ||
|
|
||
| for application_info_args in [ | ||
| { | ||
| 'application_name': None, | ||
| 'application_version': None, | ||
| 'client_id': None, | ||
| }, | ||
| { | ||
| 'application_name': 'some-application-name', | ||
| 'application_version': 'some-application-version', | ||
| 'client_id': 'some-client-id', | ||
| }, | ||
| { | ||
| 'application_name': 'some-application-name', | ||
| 'application_version': None, | ||
| 'client_id': None, | ||
| }, | ||
| { | ||
| 'application_name': None, | ||
| 'application_version': 'some-application-version', | ||
| 'client_id': None, | ||
| }, | ||
| { | ||
| 'application_name': None, | ||
| 'application_version': None, | ||
| 'client_id': 'some-client-id', | ||
| }, | ||
| ]: | ||
| with self.subTest(**application_info_args): | ||
| try: | ||
| cluster = TestCluster( | ||
| application_info=ApplicationInfo( | ||
| **application_info_args | ||
| )) | ||
|
|
||
| found = False | ||
| for row in cluster.connect().execute("select client_options from system_views.clients"): | ||
| if not row[0]: | ||
| continue | ||
| for attribute_key, startup_key in self.attribute_to_startup_key.items(): | ||
| expected_value = application_info_args.get(attribute_key) | ||
| if expected_value: | ||
| if row[0].get(startup_key) != expected_value: | ||
| break | ||
| else: | ||
| # Check that it is absent | ||
| if row[0].get(startup_key, None) is not None: | ||
| break | ||
| else: | ||
| found = True | ||
| assert found | ||
| finally: | ||
| cluster.shutdown() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.