Skip to content

RUST-956 Include service_id in relevant events #469

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
merged 2 commits into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/client/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ impl Client {
}

let connection_info = connection.info();
let service_id = connection.service_id();
let request_id = crate::cmap::conn::next_request_id();

if let Some(ref server_api) = self.inner.options.server_api {
Expand Down Expand Up @@ -509,6 +510,7 @@ impl Client {
command_name: raw_cmd.name.clone(),
request_id,
connection: connection_info.clone(),
service_id,
};

handler.handle_command_started_event(command_started_event);
Expand Down Expand Up @@ -600,6 +602,7 @@ impl Client {
failure: err.clone(),
request_id,
connection: connection_info,
service_id,
};

handler.handle_command_failed_event(command_failed_event);
Expand Down Expand Up @@ -631,6 +634,7 @@ impl Client {
command_name: cmd_name.clone(),
request_id,
connection: connection_info,
service_id,
};
handler.handle_command_succeeded_event(command_succeeded_event);
});
Expand Down
4 changes: 4 additions & 0 deletions src/cmap/conn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ impl Connection {
}
}

pub(crate) fn service_id(&self) -> Option<ObjectId> {
self.generation.service_id()
}

pub(crate) fn address(&self) -> &ServerAddress {
&self.address
}
Expand Down
1 change: 1 addition & 0 deletions src/cmap/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ impl ConnectionPoolWorker {
self.emit_event(|handler| {
let event = PoolClearedEvent {
address: self.address.clone(),
service_id,
};

handler.handle_pool_cleared_event(event);
Expand Down
5 changes: 4 additions & 1 deletion src/event/cmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::time::Duration;

use serde::Deserialize;

use crate::{bson_util, options::ServerAddress};
use crate::{bson::oid::ObjectId, bson_util, options::ServerAddress};

/// We implement `Deserialize` for all of the event types so that we can more easily parse the CMAP
/// spec tests. However, we have no need to parse the address field from the JSON files (if it's
Expand Down Expand Up @@ -79,6 +79,9 @@ pub struct PoolClearedEvent {
#[serde(default = "self::empty_address")]
#[serde(skip)]
pub address: ServerAddress,

/// If the connection is to a load balancer, the id of the selected backend.
pub service_id: Option<ObjectId>,
}

/// Event emitted when a connection pool is cleared.
Expand Down
15 changes: 14 additions & 1 deletion src/event/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

use std::time::Duration;

use crate::{bson::Document, cmap::ConnectionInfo, error::Error};
use crate::{
bson::{oid::ObjectId, Document},
cmap::ConnectionInfo,
error::Error,
};

/// An event that triggers when a database command is initiated.
#[derive(Clone, Debug)]
Expand All @@ -26,6 +30,9 @@ pub struct CommandStartedEvent {

/// Information about the connect the command will be run on.
pub connection: ConnectionInfo,

/// If the client connection is to a load balancer, the id of the selected backend.
pub service_id: Option<ObjectId>,
}

/// An event that triggers when a database command completes without an error.
Expand All @@ -48,6 +55,9 @@ pub struct CommandSucceededEvent {

/// Information about the connect the command will be run on.
pub connection: ConnectionInfo,

/// If the client connection is to a load balancer, the id of the selected backend.
pub service_id: Option<ObjectId>,
}

/// An event that triggers when a command failed to complete successfully.
Expand All @@ -70,6 +80,9 @@ pub struct CommandFailedEvent {

/// Information about the connect the command will be run on.
pub connection: ConnectionInfo,

/// If the client connection is to a load balancer, the id of the selected backend.
pub service_id: Option<ObjectId>,
}

/// Applications can implement this trait to specify custom logic to run on each command event sent
Expand Down
2 changes: 2 additions & 0 deletions src/is_master.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ pub(crate) struct IsMasterCommandResponse {

/// The maximum number of write operations permitted in a write batch.
pub max_write_batch_size: i64,

/// If the connection is to a load balancer, the id of the selected backend.
pub service_id: Option<ObjectId>,
}

Expand Down