Skip to content

Commit 1906cd2

Browse files
committed
Use Duration for const for delays
1 parent f4690f1 commit 1906cd2

File tree

5 files changed

+15
-27
lines changed

5 files changed

+15
-27
lines changed

opentelemetry-otlp/src/exporter/http/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl HttpExporterBuilder {
120120
.or(env::var(OTEL_EXPORTER_OTLP_TIMEOUT).ok())
121121
{
122122
Some(val) => match val.parse() {
123-
Ok(seconds) => Duration::from_millis(seconds),
123+
Ok(milli_seconds) => Duration::from_millis(milli_seconds),
124124
Err(_) => self.exporter_config.timeout,
125125
},
126126
None => self.exporter_config.timeout,

opentelemetry-otlp/src/exporter/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const OTEL_EXPORTER_OTLP_PROTOCOL_HTTP_JSON: &str = "http/json";
5252
/// Max waiting time for the backend to process each signal batch, defaults to 10 seconds.
5353
pub const OTEL_EXPORTER_OTLP_TIMEOUT: &str = "OTEL_EXPORTER_OTLP_TIMEOUT";
5454
/// Default max waiting time for the backend to process each signal batch.
55-
pub const OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT: u64 = 10000;
55+
pub const OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT: Duration = Duration::from_millis(10000);
5656

5757
// Endpoints per protocol https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md
5858
#[cfg(feature = "grpc-tonic")]
@@ -87,7 +87,7 @@ impl Default for ExportConfig {
8787
// don't use default_endpoint(protocol) here otherwise we
8888
// won't know if user provided a value
8989
protocol,
90-
timeout: Duration::from_millis(OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT),
90+
timeout: OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT,
9191
}
9292
}
9393
}

opentelemetry-otlp/src/exporter/tonic/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ impl TonicExporterBuilder {
200200
.or(env::var(OTEL_EXPORTER_OTLP_TIMEOUT).ok())
201201
{
202202
Some(val) => match val.parse() {
203-
Ok(seconds) => Duration::from_millis(seconds),
203+
Ok(milli_seconds) => Duration::from_millis(milli_seconds),
204204
Err(_) => config.timeout,
205205
},
206206
None => config.timeout,

opentelemetry-sdk/src/logs/batch_log_processor.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use std::{
3939
/// Delay interval between two consecutive exports.
4040
pub(crate) const OTEL_BLRP_SCHEDULE_DELAY: &str = "OTEL_BLRP_SCHEDULE_DELAY";
4141
/// Default delay interval between two consecutive exports.
42-
pub(crate) const OTEL_BLRP_SCHEDULE_DELAY_DEFAULT: u64 = 1_000;
42+
pub(crate) const OTEL_BLRP_SCHEDULE_DELAY_DEFAULT: Duration = Duration::from_millis(1_000);
4343
/// Maximum allowed time to export data.
4444
#[cfg(feature = "experimental_logs_batch_log_processor_with_async_runtime")]
4545
pub(crate) const OTEL_BLRP_EXPORT_TIMEOUT: &str = "OTEL_BLRP_EXPORT_TIMEOUT";
@@ -616,7 +616,7 @@ impl Default for BatchConfigBuilder {
616616
fn default() -> Self {
617617
BatchConfigBuilder {
618618
max_queue_size: OTEL_BLRP_MAX_QUEUE_SIZE_DEFAULT,
619-
scheduled_delay: Duration::from_millis(OTEL_BLRP_SCHEDULE_DELAY_DEFAULT),
619+
scheduled_delay: OTEL_BLRP_SCHEDULE_DELAY_DEFAULT,
620620
max_export_batch_size: OTEL_BLRP_MAX_EXPORT_BATCH_SIZE_DEFAULT,
621621
#[cfg(feature = "experimental_logs_batch_log_processor_with_async_runtime")]
622622
max_export_timeout: Duration::from_millis(OTEL_BLRP_EXPORT_TIMEOUT_DEFAULT),
@@ -736,7 +736,7 @@ mod tests {
736736
#[test]
737737
fn test_default_const_values() {
738738
assert_eq!(OTEL_BLRP_SCHEDULE_DELAY, "OTEL_BLRP_SCHEDULE_DELAY");
739-
assert_eq!(OTEL_BLRP_SCHEDULE_DELAY_DEFAULT, 1_000);
739+
assert_eq!(OTEL_BLRP_SCHEDULE_DELAY_DEFAULT.as_millis(), 1_000);
740740
#[cfg(feature = "experimental_logs_batch_log_processor_with_async_runtime")]
741741
assert_eq!(OTEL_BLRP_EXPORT_TIMEOUT, "OTEL_BLRP_EXPORT_TIMEOUT");
742742
#[cfg(feature = "experimental_logs_batch_log_processor_with_async_runtime")]
@@ -763,10 +763,7 @@ mod tests {
763763

764764
let config = temp_env::with_vars_unset(env_vars, BatchConfig::default);
765765

766-
assert_eq!(
767-
config.scheduled_delay,
768-
Duration::from_millis(OTEL_BLRP_SCHEDULE_DELAY_DEFAULT)
769-
);
766+
assert_eq!(config.scheduled_delay, OTEL_BLRP_SCHEDULE_DELAY_DEFAULT);
770767
#[cfg(feature = "experimental_logs_batch_log_processor_with_async_runtime")]
771768
assert_eq!(
772769
config.max_export_timeout,
@@ -809,10 +806,7 @@ mod tests {
809806

810807
assert_eq!(config.max_queue_size, 256);
811808
assert_eq!(config.max_export_batch_size, 256);
812-
assert_eq!(
813-
config.scheduled_delay,
814-
Duration::from_millis(OTEL_BLRP_SCHEDULE_DELAY_DEFAULT)
815-
);
809+
assert_eq!(config.scheduled_delay, OTEL_BLRP_SCHEDULE_DELAY_DEFAULT);
816810
#[cfg(feature = "experimental_logs_batch_log_processor_with_async_runtime")]
817811
assert_eq!(
818812
config.max_export_timeout,
@@ -852,7 +846,7 @@ mod tests {
852846
assert_eq!(builder.config.max_export_batch_size, 500);
853847
assert_eq!(
854848
builder.config.scheduled_delay,
855-
Duration::from_millis(OTEL_BLRP_SCHEDULE_DELAY_DEFAULT)
849+
OTEL_BLRP_SCHEDULE_DELAY_DEFAULT
856850
);
857851
assert_eq!(
858852
builder.config.max_queue_size,

opentelemetry-sdk/src/trace/span_processor.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub(crate) const OTEL_BSP_MAX_EXPORT_BATCH_SIZE_DEFAULT: usize = 512;
6565
/// Maximum allowed time to export data.
6666
pub(crate) const OTEL_BSP_EXPORT_TIMEOUT: &str = "OTEL_BSP_EXPORT_TIMEOUT";
6767
/// Default maximum allowed time to export data.
68-
pub(crate) const OTEL_BSP_EXPORT_TIMEOUT_DEFAULT: u64 = 30_000;
68+
pub(crate) const OTEL_BSP_EXPORT_TIMEOUT_DEFAULT: Duration = Duration::from_millis(30_000);
6969
/// Environment variable to configure max concurrent exports for batch span
7070
/// processor.
7171
pub(crate) const OTEL_BSP_MAX_CONCURRENT_EXPORTS: &str = "OTEL_BSP_MAX_CONCURRENT_EXPORTS";
@@ -710,7 +710,7 @@ impl Default for BatchConfigBuilder {
710710
max_queue_size: OTEL_BSP_MAX_QUEUE_SIZE_DEFAULT,
711711
scheduled_delay: Duration::from_millis(OTEL_BSP_SCHEDULE_DELAY_DEFAULT),
712712
max_export_batch_size: OTEL_BSP_MAX_EXPORT_BATCH_SIZE_DEFAULT,
713-
max_export_timeout: Duration::from_millis(OTEL_BSP_EXPORT_TIMEOUT_DEFAULT),
713+
max_export_timeout: OTEL_BSP_EXPORT_TIMEOUT_DEFAULT,
714714
max_concurrent_exports: OTEL_BSP_MAX_CONCURRENT_EXPORTS_DEFAULT,
715715
}
716716
.init_from_env_vars()
@@ -905,7 +905,7 @@ mod tests {
905905
);
906906
assert_eq!(OTEL_BSP_MAX_EXPORT_BATCH_SIZE_DEFAULT, 512);
907907
assert_eq!(OTEL_BSP_EXPORT_TIMEOUT, "OTEL_BSP_EXPORT_TIMEOUT");
908-
assert_eq!(OTEL_BSP_EXPORT_TIMEOUT_DEFAULT, 30000);
908+
assert_eq!(OTEL_BSP_EXPORT_TIMEOUT_DEFAULT.as_millis(), 30000);
909909
}
910910

911911
#[test]
@@ -928,10 +928,7 @@ mod tests {
928928
config.scheduled_delay,
929929
Duration::from_millis(OTEL_BSP_SCHEDULE_DELAY_DEFAULT)
930930
);
931-
assert_eq!(
932-
config.max_export_timeout,
933-
Duration::from_millis(OTEL_BSP_EXPORT_TIMEOUT_DEFAULT)
934-
);
931+
assert_eq!(config.max_export_timeout, OTEL_BSP_EXPORT_TIMEOUT_DEFAULT);
935932
assert_eq!(config.max_queue_size, OTEL_BSP_MAX_QUEUE_SIZE_DEFAULT);
936933
assert_eq!(
937934
config.max_export_batch_size,
@@ -971,10 +968,7 @@ mod tests {
971968
config.scheduled_delay,
972969
Duration::from_millis(OTEL_BSP_SCHEDULE_DELAY_DEFAULT)
973970
);
974-
assert_eq!(
975-
config.max_export_timeout,
976-
Duration::from_millis(OTEL_BSP_EXPORT_TIMEOUT_DEFAULT)
977-
);
971+
assert_eq!(config.max_export_timeout, OTEL_BSP_EXPORT_TIMEOUT_DEFAULT);
978972
}
979973

980974
#[test]

0 commit comments

Comments
 (0)