Skip to content

Commit 7071c0e

Browse files
committed
Convert leftover derive_builders
1 parent 9f4b04e commit 7071c0e

File tree

7 files changed

+61
-72
lines changed

7 files changed

+61
-72
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ license-file = "LICENSE.txt"
1515

1616
[workspace.dependencies]
1717
bon = "3"
18-
derive_builder = "0.20"
1918
derive_more = { version = "2.0", features = [
2019
"constructor",
2120
"display",

crates/common/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ async-trait = "0.1"
2525
base64 = "0.22"
2626
bon = { workspace = true }
2727
dirs = { version = "6.0", optional = true }
28-
derive_builder = { workspace = true }
2928
derive_more = { workspace = true }
3029
opentelemetry = { workspace = true, optional = true }
3130
prost = { workspace = true }

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,25 +1323,22 @@ impl TryFrom<&TunerHolder> for temporalio_sdk_core::TunerHolder {
13231323
}
13241324

13251325
let resource_based = first.map(|f| {
1326-
temporalio_sdk_core::ResourceBasedSlotsOptionsBuilder::default()
1326+
temporalio_sdk_core::ResourceBasedSlotsOptions::builder()
13271327
.target_mem_usage(f.target_memory_usage)
13281328
.target_cpu_usage(f.target_cpu_usage)
13291329
.build()
1330-
.expect("Failed to build ResourceBasedSlotsOptions")
13311330
});
13321331

1333-
let mut builder = temporalio_sdk_core::TunerHolderOptionsBuilder::default();
1334-
builder
1332+
let builder = temporalio_sdk_core::TunerHolderOptions::builder()
13351333
.workflow_slot_options(holder.workflow_slot_supplier.try_into()?)
13361334
.activity_slot_options(holder.activity_slot_supplier.try_into()?)
13371335
.local_activity_slot_options(holder.local_activity_slot_supplier.try_into()?)
1338-
.nexus_slot_options(holder.nexus_task_slot_supplier.try_into()?);
1339-
if let Some(rb) = resource_based {
1340-
builder.resource_based_options(rb);
1341-
}
1336+
.nexus_slot_options(holder.nexus_task_slot_supplier.try_into()?)
1337+
.maybe_resource_based_options(resource_based);
1338+
13421339
builder
13431340
.build()
1344-
.context("Failed building tuner holder options")?
1341+
.map_err(|e| anyhow::anyhow!("Failed building tuner holder options: {}", e))?
13451342
.build_tuner_holder()
13461343
.context("Failed building tuner holder")
13471344
}

crates/sdk-core/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ crossbeam-channel = "0.5"
4141
crossbeam-queue = "0.3"
4242
crossbeam-utils = "0.8"
4343
dashmap = "6.1"
44-
derive_builder = { workspace = true }
4544
derive_more = { workspace = true }
4645
enum_dispatch = "0.3"
4746
enum-iterator = "2"

crates/sdk-core/benches/workflow_replay_bench.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::{
1515
};
1616
use temporalio_common::{
1717
protos::{DEFAULT_WORKFLOW_TYPE, canned_histories},
18-
telemetry::metrics::{MetricKeyValue, MetricParametersBuilder, NewAttributes},
18+
telemetry::metrics::{MetricKeyValue, MetricParameters, NewAttributes},
1919
};
2020
use temporalio_sdk::{WfContext, WorkflowFunction};
2121
use temporalio_sdk_core::{CoreRuntime, replay::HistoryForReplay};
@@ -87,22 +87,19 @@ pub fn bench_metrics(c: &mut Criterion) {
8787
b.iter_batched(
8888
|| {
8989
let c = meter.counter(
90-
MetricParametersBuilder::default()
90+
MetricParameters::builder()
9191
.name("c")
92-
.build()
93-
.unwrap(),
92+
.build(),
9493
);
9594
let h = meter.histogram(
96-
MetricParametersBuilder::default()
95+
MetricParameters::builder()
9796
.name("h")
98-
.build()
99-
.unwrap(),
97+
.build(),
10098
);
10199
let g = meter.gauge(
102-
MetricParametersBuilder::default()
100+
MetricParameters::builder()
103101
.name("g")
104-
.build()
105-
.unwrap(),
102+
.build(),
106103
);
107104

108105
let vals = [1, 2, 3, 4, 5];

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

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,20 @@ pub struct TunerHolder {
2525

2626
/// Can be used to construct a [TunerHolder] without needing to manually construct each
2727
/// [SlotSupplier]. Useful for lang bridges to allow more easily passing through user options.
28-
#[derive(Clone, Debug, derive_builder::Builder)]
29-
#[builder(build_fn(validate = "Self::validate"))]
28+
#[derive(Clone, Debug, bon::Builder)]
29+
#[builder(finish_fn(vis = "", name = build_internal))]
3030
#[non_exhaustive]
3131
pub struct TunerHolderOptions {
3232
/// Options for workflow slots
33-
#[builder(default, setter(strip_option))]
3433
pub workflow_slot_options: Option<SlotSupplierOptions<WorkflowSlotKind>>,
3534
/// Options for activity slots
36-
#[builder(default, setter(strip_option))]
3735
pub activity_slot_options: Option<SlotSupplierOptions<ActivitySlotKind>>,
3836
/// Options for local activity slots
39-
#[builder(default, setter(strip_option))]
4037
pub local_activity_slot_options: Option<SlotSupplierOptions<LocalActivitySlotKind>>,
4138
/// Options for nexus slots
42-
#[builder(default, setter(strip_option))]
4339
pub nexus_slot_options: Option<SlotSupplierOptions<NexusSlotKind>>,
4440
/// Options that will apply to all resource based slot suppliers. Must be set if any slot
4541
/// options are [SlotSupplierOptions::ResourceBased]
46-
#[builder(default, setter(strip_option))]
4742
pub resource_based_options: Option<ResourceBasedSlotsOptions>,
4843
}
4944

@@ -150,35 +145,42 @@ pub enum SlotSupplierOptions<SK: SlotKind> {
150145
Custom(Arc<dyn SlotSupplier<SlotKind = SK> + Send + Sync>),
151146
}
152147

153-
impl TunerHolderOptionsBuilder {
148+
impl<State: tuner_holder_options_builder::IsComplete> TunerHolderOptionsBuilder<State> {
149+
/// Build the [TunerHolderOptions] with validation
150+
pub fn build(self) -> Result<TunerHolderOptions, String> {
151+
let options = self.build_internal();
152+
validate_tuner_holder_options(&options)?;
153+
Ok(options)
154+
}
155+
154156
/// Create a [TunerHolder] from this builder
155157
pub fn build_tuner_holder(self) -> Result<TunerHolder, anyhow::Error> {
156-
let s = self.build()?;
158+
let s = self.build().map_err(|e: String| anyhow::anyhow!(e))?;
157159
s.build_tuner_holder()
158160
}
161+
}
159162

160-
fn validate(&self) -> Result<(), String> {
161-
let any_is_resource_based = matches!(
162-
self.workflow_slot_options,
163-
Some(Some(SlotSupplierOptions::ResourceBased(_)))
164-
) || matches!(
165-
self.activity_slot_options,
166-
Some(Some(SlotSupplierOptions::ResourceBased(_)))
167-
) || matches!(
168-
self.local_activity_slot_options,
169-
Some(Some(SlotSupplierOptions::ResourceBased(_)))
170-
) || matches!(
171-
self.nexus_slot_options,
172-
Some(Some(SlotSupplierOptions::ResourceBased(_)))
163+
fn validate_tuner_holder_options(options: &TunerHolderOptions) -> Result<(), String> {
164+
let any_is_resource_based = matches!(
165+
options.workflow_slot_options,
166+
Some(SlotSupplierOptions::ResourceBased(_))
167+
) || matches!(
168+
options.activity_slot_options,
169+
Some(SlotSupplierOptions::ResourceBased(_))
170+
) || matches!(
171+
options.local_activity_slot_options,
172+
Some(SlotSupplierOptions::ResourceBased(_))
173+
) || matches!(
174+
options.nexus_slot_options,
175+
Some(SlotSupplierOptions::ResourceBased(_))
176+
);
177+
if any_is_resource_based && options.resource_based_options.is_none() {
178+
return Err(
179+
"`resource_based_options` must be set if any slot options are ResourceBased"
180+
.to_string(),
173181
);
174-
if any_is_resource_based && matches!(self.resource_based_options, None | Some(None)) {
175-
return Err(
176-
"`resource_based_options` must be set if any slot options are ResourceBased"
177-
.to_string(),
178-
);
179-
}
180-
Ok(())
181182
}
183+
Ok(())
182184
}
183185

184186
/// Can be used to construct a `TunerHolder` from individual slot suppliers. Any supplier which is
@@ -348,11 +350,10 @@ mod tests {
348350

349351
#[test]
350352
fn tuner_holder_options_nexus_resource_based() {
351-
let resource_opts = ResourceBasedSlotsOptionsBuilder::default()
353+
let resource_opts = ResourceBasedSlotsOptions::builder()
352354
.target_mem_usage(0.8)
353355
.target_cpu_usage(0.9)
354-
.build()
355-
.unwrap();
356+
.build();
356357

357358
let options = TunerHolderOptions {
358359
workflow_slot_options: None,
@@ -403,7 +404,7 @@ mod tests {
403404
#[test]
404405
fn tuner_holder_options_builder_validates_resource_based_requirements() {
405406
// Should fail when nexus uses ResourceBased but resource_based_options is not set
406-
let result = TunerHolderOptionsBuilder::default()
407+
let result = TunerHolderOptions::builder()
407408
.nexus_slot_options(SlotSupplierOptions::ResourceBased(
408409
ResourceSlotOptions::new(5, 100, Duration::from_millis(100)),
409410
))
@@ -420,11 +421,10 @@ mod tests {
420421

421422
#[test]
422423
fn tuner_holder_options_all_slot_types() {
423-
let resource_opts = ResourceBasedSlotsOptionsBuilder::default()
424+
let resource_opts = ResourceBasedSlotsOptions::builder()
424425
.target_mem_usage(0.8)
425426
.target_cpu_usage(0.9)
426-
.build()
427-
.unwrap();
427+
.build();
428428

429429
let options = TunerHolderOptions {
430430
workflow_slot_options: Some(SlotSupplierOptions::FixedSize { slots: 10 }),

crates/sdk-core/src/worker/tuner/resource_based.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,10 @@ impl ResourceBasedTuner<RealSysInfo> {
4343
/// Create an instance attempting to target the provided memory and cpu thresholds as values
4444
/// between 0 and 1.
4545
pub fn new(target_mem_usage: f64, target_cpu_usage: f64) -> Self {
46-
let opts = ResourceBasedSlotsOptionsBuilder::default()
46+
let opts = ResourceBasedSlotsOptions::builder()
4747
.target_mem_usage(target_mem_usage)
4848
.target_cpu_usage(target_cpu_usage)
49-
.build()
50-
.expect("default resource based slot options can't fail to build");
49+
.build();
5150
let controller = ResourceController::new_with_sysinfo(opts, Arc::new(RealSysInfo::new()));
5251
Self::new_from_controller(controller)
5352
}
@@ -163,7 +162,7 @@ pub(crate) struct ResourceBasedSlotsForType<MI, SK> {
163162
_slot_kind: PhantomData<SK>,
164163
}
165164
/// Allows for the full customization of the PID options for a resource based tuner
166-
#[derive(Clone, Debug, derive_builder::Builder)]
165+
#[derive(Clone, Debug, bon::Builder)]
167166
#[non_exhaustive]
168167
pub struct ResourceBasedSlotsOptions {
169168
/// A value in the range [0.0, 1.0] representing the target memory usage.
@@ -172,30 +171,30 @@ pub struct ResourceBasedSlotsOptions {
172171
pub target_cpu_usage: f64,
173172

174173
/// See [pid::Pid::p]
175-
#[builder(default = "5.0")]
174+
#[builder(default = 5.0)]
176175
pub mem_p_gain: f64,
177176
/// See [pid::Pid::i]
178-
#[builder(default = "0.0")]
177+
#[builder(default = 0.0)]
179178
pub mem_i_gain: f64,
180179
/// See [pid::Pid::d]
181-
#[builder(default = "1.0")]
180+
#[builder(default = 1.0)]
182181
pub mem_d_gain: f64,
183182
/// If the mem PID controller outputs a value higher than this, we say the mem half of things
184183
/// will allow a slot
185-
#[builder(default = "0.25")]
184+
#[builder(default = 0.25)]
186185
pub mem_output_threshold: f64,
187186
/// See [pid::Pid::d]
188-
#[builder(default = "5.0")]
187+
#[builder(default = 5.0)]
189188
pub cpu_p_gain: f64,
190189
/// See [pid::Pid::i]
191-
#[builder(default = "0.0")]
190+
#[builder(default = 0.0)]
192191
pub cpu_i_gain: f64,
193192
/// See [pid::Pid::d]
194-
#[builder(default = "1.0")]
193+
#[builder(default = 1.0)]
195194
pub cpu_d_gain: f64,
196195
/// If the CPU PID controller outputs a value higher than this, we say the CPU half of things
197196
/// will allow a slot
198-
#[builder(default = "0.05")]
197+
#[builder(default = 0.05)]
199198
pub cpu_output_threshold: f64,
200199
}
201200
struct PidControllers {
@@ -765,11 +764,10 @@ mod tests {
765764
}
766765

767766
fn test_options() -> ResourceBasedSlotsOptions {
768-
ResourceBasedSlotsOptionsBuilder::default()
767+
ResourceBasedSlotsOptions::builder()
769768
.target_mem_usage(0.8)
770769
.target_cpu_usage(1.0)
771770
.build()
772-
.expect("default resource based slot options can't fail to build")
773771
}
774772

775773
#[test]

0 commit comments

Comments
 (0)