Skip to content

Commit 7419ada

Browse files
authored
Use hashset to dedupe plugin names from Lang (#1072)
* Use hashset to dedupe * Ensure plugins are sent in deterministic, sorted order
1 parent 0de27c0 commit 7419ada

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

crates/common/src/worker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ pub struct WorkerConfig {
238238

239239
/// List of plugins used by lang.
240240
#[builder(default)]
241-
pub plugins: Vec<PluginInfo>,
241+
pub plugins: HashSet<PluginInfo>,
242242

243243
/// Skips the single worker+client+namespace+task_queue check
244244
#[builder(default = "false")]

crates/sdk-core-c-bridge/src/worker.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1262,13 +1262,15 @@ impl TryFrom<&WorkerOptions> for temporalio_sdk_core::WorkerConfig {
12621262
opt.plugins
12631263
.to_str_vec()
12641264
.into_iter()
1265+
.collect::<HashSet<_>>()
1266+
.into_iter()
12651267
.map(
12661268
|name| temporalio_common::protos::temporal::api::worker::v1::PluginInfo {
12671269
name: name.to_owned(),
12681270
version: String::new(),
12691271
},
12701272
)
1271-
.collect::<Vec<_>>(),
1273+
.collect::<HashSet<_>>(),
12721274
)
12731275
.build()
12741276
.map_err(|err| anyhow::anyhow!(err))

crates/sdk-core/src/worker/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,9 @@ impl WorkerHeartbeatManager {
11901190
}
11911191
});
11921192

1193+
let mut plugins: Vec<_> = config.plugins.clone().into_iter().collect();
1194+
plugins.sort_by(|a, b| a.name.cmp(&b.name));
1195+
11931196
let mut worker_heartbeat = WorkerHeartbeat {
11941197
worker_instance_key: worker_instance_key.to_string(),
11951198
host_info: Some(WorkerHostInfo {
@@ -1208,7 +1211,7 @@ impl WorkerHeartbeatManager {
12081211

12091212
status: (*heartbeat_manager_metrics.status.read()) as i32,
12101213
start_time,
1211-
plugins: config.plugins.clone(),
1214+
plugins,
12121215

12131216
// Some Metrics dependent fields are set below, and
12141217
// some fields like sdk_name, sdk_version, and worker_identity, must be set by

crates/sdk-core/tests/integ_tests/worker_heartbeat_tests.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,20 @@ async fn docker_worker_heartbeat_basic(#[values("otel", "prom", "no_metrics")] b
136136
.max_outstanding_workflow_tasks(5_usize)
137137
.max_cached_workflows(5_usize)
138138
.max_outstanding_activities(5_usize)
139-
.plugins(vec![
140-
PluginInfo {
141-
name: "plugin1".to_string(),
142-
version: "1".to_string(),
143-
},
144-
PluginInfo {
145-
name: "plugin2".to_string(),
146-
version: "2".to_string(),
147-
},
148-
]);
139+
.plugins(
140+
[
141+
PluginInfo {
142+
name: "plugin1".to_string(),
143+
version: "1".to_string(),
144+
},
145+
PluginInfo {
146+
name: "plugin2".to_string(),
147+
version: "2".to_string(),
148+
},
149+
]
150+
.into_iter()
151+
.collect::<HashSet<_>>(),
152+
);
149153
let mut worker = starter.worker().await;
150154
let worker_instance_key = worker.worker_instance_key();
151155

0 commit comments

Comments
 (0)