Skip to content

Commit d7569ec

Browse files
authored
RUST-956 Include service_id in relevant events (#469)
1 parent 5c0e71f commit d7569ec

File tree

6 files changed

+29
-2
lines changed

6 files changed

+29
-2
lines changed

src/client/executor.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ impl Client {
478478
}
479479

480480
let connection_info = connection.info();
481+
let service_id = connection.service_id();
481482
let request_id = crate::cmap::conn::next_request_id();
482483

483484
if let Some(ref server_api) = self.inner.options.server_api {
@@ -509,6 +510,7 @@ impl Client {
509510
command_name: raw_cmd.name.clone(),
510511
request_id,
511512
connection: connection_info.clone(),
513+
service_id,
512514
};
513515

514516
handler.handle_command_started_event(command_started_event);
@@ -600,6 +602,7 @@ impl Client {
600602
failure: err.clone(),
601603
request_id,
602604
connection: connection_info,
605+
service_id,
603606
};
604607

605608
handler.handle_command_failed_event(command_failed_event);
@@ -631,6 +634,7 @@ impl Client {
631634
command_name: cmd_name.clone(),
632635
request_id,
633636
connection: connection_info,
637+
service_id,
634638
};
635639
handler.handle_command_succeeded_event(command_succeeded_event);
636640
});

src/cmap/conn/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ impl Connection {
167167
}
168168
}
169169

170+
pub(crate) fn service_id(&self) -> Option<ObjectId> {
171+
self.generation.service_id()
172+
}
173+
170174
pub(crate) fn address(&self) -> &ServerAddress {
171175
&self.address
172176
}

src/cmap/worker.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ impl ConnectionPoolWorker {
503503
self.emit_event(|handler| {
504504
let event = PoolClearedEvent {
505505
address: self.address.clone(),
506+
service_id,
506507
};
507508

508509
handler.handle_pool_cleared_event(event);

src/event/cmap.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::time::Duration;
55

66
use serde::Deserialize;
77

8-
use crate::{bson_util, options::ServerAddress};
8+
use crate::{bson::oid::ObjectId, bson_util, options::ServerAddress};
99

1010
/// We implement `Deserialize` for all of the event types so that we can more easily parse the CMAP
1111
/// spec tests. However, we have no need to parse the address field from the JSON files (if it's
@@ -79,6 +79,9 @@ pub struct PoolClearedEvent {
7979
#[serde(default = "self::empty_address")]
8080
#[serde(skip)]
8181
pub address: ServerAddress,
82+
83+
/// If the connection is to a load balancer, the id of the selected backend.
84+
pub service_id: Option<ObjectId>,
8285
}
8386

8487
/// Event emitted when a connection pool is cleared.

src/event/command.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
44
use std::time::Duration;
55

6-
use crate::{bson::Document, cmap::ConnectionInfo, error::Error};
6+
use crate::{
7+
bson::{oid::ObjectId, Document},
8+
cmap::ConnectionInfo,
9+
error::Error,
10+
};
711

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

2731
/// Information about the connect the command will be run on.
2832
pub connection: ConnectionInfo,
33+
34+
/// If the client connection is to a load balancer, the id of the selected backend.
35+
pub service_id: Option<ObjectId>,
2936
}
3037

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

4956
/// Information about the connect the command will be run on.
5057
pub connection: ConnectionInfo,
58+
59+
/// If the client connection is to a load balancer, the id of the selected backend.
60+
pub service_id: Option<ObjectId>,
5161
}
5262

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

7181
/// Information about the connect the command will be run on.
7282
pub connection: ConnectionInfo,
83+
84+
/// If the client connection is to a load balancer, the id of the selected backend.
85+
pub service_id: Option<ObjectId>,
7386
}
7487

7588
/// Applications can implement this trait to specify custom logic to run on each command event sent

src/is_master.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ pub(crate) struct IsMasterCommandResponse {
195195

196196
/// The maximum number of write operations permitted in a write batch.
197197
pub max_write_batch_size: i64,
198+
199+
/// If the connection is to a load balancer, the id of the selected backend.
198200
pub service_id: Option<ObjectId>,
199201
}
200202

0 commit comments

Comments
 (0)