Skip to content

Commit

Permalink
session_builder: expose custom_identity setter
Browse files Browse the repository at this point in the history
The exposed option enabled setting custom identity that is advertised
in STARTUP message by the driver, upon opening each connection.

Settable identity include:
- DRIVER_NAME
- DRIVER_VERSION
- APPLICATION_NAME
- APPLICATION_VERSION
- CLIENT_ID

All five are visible in Cassandra's `system_views.clients` in
`client_options` column.

DRIVER_NAME & DRIVER_VERSION are visible in ScyllaDB's `system.clients`.
  • Loading branch information
wprzytula committed Aug 1, 2024
1 parent 98e2935 commit 7f07d1c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
8 changes: 6 additions & 2 deletions scylla/src/transport/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ pub struct SessionConfig {
/// for e.g: if they do not want unexpected traffic
/// or they expect the topology to change frequently.
pub cluster_metadata_refresh_interval: Duration,

/// Driver and application self-identifying information,
/// to be sent to server in STARTUP message.
pub identity: SelfIdentity<'static>,
}

impl SessionConfig {
Expand Down Expand Up @@ -335,6 +339,7 @@ impl SessionConfig {
tracing_info_fetch_interval: Duration::from_millis(3),
tracing_info_fetch_consistency: Consistency::One,
cluster_metadata_refresh_interval: Duration::from_secs(60),
identity: SelfIdentity::default(),
}
}

Expand Down Expand Up @@ -515,8 +520,7 @@ impl Session {
keepalive_interval: config.keepalive_interval,
keepalive_timeout: config.keepalive_timeout,
tablet_sender: Some(tablet_sender),
// A temporary stub, removed in the next commit.
identity: SelfIdentity::default(),
identity: config.identity,
};

let pool_config = PoolConfig {
Expand Down
33 changes: 33 additions & 0 deletions scylla/src/transport/session_builder.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! SessionBuilder provides an easy way to create new Sessions
use super::connection::SelfIdentity;
use super::errors::NewSessionError;
use super::execution_profile::ExecutionProfileHandle;
use super::session::{AddressTranslator, Session, SessionConfig};
Expand Down Expand Up @@ -942,6 +943,38 @@ impl<K: SessionBuilderKind> GenericSessionBuilder<K> {
self.config.cluster_metadata_refresh_interval = interval;
self
}

/// Set the custom identity of the driver/application/instance,
/// to be sent as options in STARTUP message.
///
/// By default driver name and version are sent;
/// application name and version and client id are not sent.
///
/// # Example
/// ```
/// # use scylla::{Session, SessionBuilder};
/// # use scylla::transport::SelfIdentity;
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let (app_major, app_minor, app_patch) = (2, 1, 3);
/// let app_version = format!("{app_major}.{app_minor}.{app_patch}");
///
/// let session: Session = SessionBuilder::new()
/// .known_node("127.0.0.1:9042")
/// .custom_identity(
/// SelfIdentity::new()
/// .with_custom_driver_version("0.13.0-custom_build_17")
/// .with_application_name("my-app")
/// .with_application_version(app_version)
/// )
/// .build()
/// .await?;
/// # Ok(())
/// # }
/// ```
pub fn custom_identity(mut self, identity: SelfIdentity<'static>) -> Self {
self.config.identity = identity;
self
}
}

/// Creates a [`SessionBuilder`] with default configuration, same as [`SessionBuilder::new`]
Expand Down

0 comments on commit 7f07d1c

Please sign in to comment.