From 0de899727357750a9d5fef8c1c2e2fc889515fd5 Mon Sep 17 00:00:00 2001 From: Scott Balmos <399112+sbalmos@users.noreply.github.com> Date: Sat, 8 Jul 2023 08:27:03 -0400 Subject: [PATCH 1/3] Fix demo logs source interval parsing --- src/sources/demo_logs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sources/demo_logs.rs b/src/sources/demo_logs.rs index fa92cd3ac0681..9d0454ed4f933 100644 --- a/src/sources/demo_logs.rs +++ b/src/sources/demo_logs.rs @@ -48,7 +48,7 @@ pub struct DemoLogsConfig { #[derivative(Default(value = "default_interval()"))] #[serde(default = "default_interval")] #[configurable(metadata(docs::examples = 1.0, docs::examples = 0.1, docs::examples = 0.01,))] - #[serde_as(as = "serde_with::DurationSeconds")] + #[serde_as(as = "serde_with::DurationSecondsWithFrac")] pub interval: Duration, /// The total number of lines to output. From 2236be5c6855bf4aad55647d5ca936345ea03b04 Mon Sep 17 00:00:00 2001 From: Scott Balmos <399112+sbalmos@users.noreply.github.com> Date: Sat, 8 Jul 2023 08:44:20 -0400 Subject: [PATCH 2/3] Add missing Configurable impl for DurationSecondsWithFrac --- lib/vector-config/src/external/serde_with.rs | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/vector-config/src/external/serde_with.rs b/lib/vector-config/src/external/serde_with.rs index 05de17e3bf605..5b2e84fef6420 100644 --- a/lib/vector-config/src/external/serde_with.rs +++ b/lib/vector-config/src/external/serde_with.rs @@ -105,6 +105,35 @@ impl Configurable for serde_with::DurationSeconds { + fn referenceable_name() -> Option<&'static str> { + // We're masking the type parameters here because we only deal with fractional seconds via this + // version, and handle whole seconds with `DurationSeconds`, which we + // expose as `serde_with::DurationSeconds`. + Some("serde_with::DurationFractionalSeconds") + } + + fn metadata() -> Metadata { + let mut metadata = Metadata::default(); + metadata.set_description("A span of time, in fractional seconds."); + metadata.add_custom_attribute(CustomAttribute::kv( + constants::DOCS_META_NUMERIC_TYPE, + NumberClass::FloatingPoint, + )); + metadata.add_custom_attribute(CustomAttribute::kv( + constants::DOCS_META_TYPE_UNIT, + "seconds", + )); + metadata + } + + fn generate_schema(_: &RefCell) -> Result { + // This boils down to a number schema, but we just need to shuttle around the metadata so + // that we can call the relevant schema generation function. + Ok(generate_number_schema::()) + } +} + impl Configurable for serde_with::DurationMilliSeconds { fn referenceable_name() -> Option<&'static str> { // We're masking the type parameters here because we only deal with whole milliseconds via this From 0dab1775672fe0ecefccd8db1cb4b4cfcf1f23a8 Mon Sep 17 00:00:00 2001 From: Scott Balmos <399112+sbalmos@users.noreply.github.com> Date: Fri, 14 Jul 2023 15:09:21 -0400 Subject: [PATCH 3/3] Fully replace all usages of DurationSeconds with DurationSecondsWithFrac. Remove DurationSeconds's Configurable impl. --- lib/vector-config/src/external/serde_with.rs | 31 +------------------- src/sources/gcp_pubsub.rs | 6 ++-- src/sources/internal_metrics.rs | 2 +- src/transforms/throttle.rs | 2 +- 4 files changed, 6 insertions(+), 35 deletions(-) diff --git a/lib/vector-config/src/external/serde_with.rs b/lib/vector-config/src/external/serde_with.rs index 5b2e84fef6420..30267e2253943 100644 --- a/lib/vector-config/src/external/serde_with.rs +++ b/lib/vector-config/src/external/serde_with.rs @@ -50,7 +50,7 @@ where impl Configurable for serde_with::DurationSeconds { fn referenceable_name() -> Option<&'static str> { // We're masking the type parameters here because we only deal with whole seconds via this - // version, and handle fractional seconds with `DurationSeconds`, which we + // version, and handle fractional seconds with `DurationSecondsWithFrac`, which we // expose as `serde_with::DurationFractionalSeconds`. Some("serde_with::DurationSeconds") } @@ -76,35 +76,6 @@ impl Configurable for serde_with::DurationSeconds { - fn referenceable_name() -> Option<&'static str> { - // We're masking the type parameters here because we only deal with fractional seconds via this - // version, and handle whole seconds with `DurationSeconds`, which we - // expose as `serde_with::DurationSeconds`. - Some("serde_with::DurationFractionalSeconds") - } - - fn metadata() -> Metadata { - let mut metadata = Metadata::default(); - metadata.set_description("A span of time, in fractional seconds."); - metadata.add_custom_attribute(CustomAttribute::kv( - constants::DOCS_META_NUMERIC_TYPE, - NumberClass::FloatingPoint, - )); - metadata.add_custom_attribute(CustomAttribute::kv( - constants::DOCS_META_TYPE_UNIT, - "seconds", - )); - metadata - } - - fn generate_schema(_: &RefCell) -> Result { - // This boils down to a number schema, but we just need to shuttle around the metadata so - // that we can call the relevant schema generation function. - Ok(generate_number_schema::()) - } -} - impl Configurable for serde_with::DurationSecondsWithFrac { fn referenceable_name() -> Option<&'static str> { // We're masking the type parameters here because we only deal with fractional seconds via this diff --git a/src/sources/gcp_pubsub.rs b/src/sources/gcp_pubsub.rs index d38688592d4fd..b92062553f4cd 100644 --- a/src/sources/gcp_pubsub.rs +++ b/src/sources/gcp_pubsub.rs @@ -162,7 +162,7 @@ pub struct PubsubConfig { /// How often to poll the currently active streams to see if they /// are all busy and so open a new stream. #[serde(default = "default_poll_time")] - #[serde_as(as = "serde_with::DurationSeconds")] + #[serde_as(as = "serde_with::DurationSecondsWithFrac")] #[configurable(metadata(docs::human_name = "Poll Time"))] pub poll_time_seconds: Duration, @@ -184,7 +184,7 @@ pub struct PubsubConfig { /// The amount of time, in seconds, to wait between retry attempts after an error. #[serde(default = "default_retry_delay")] - #[serde_as(as = "serde_with::DurationSeconds")] + #[serde_as(as = "serde_with::DurationSecondsWithFrac")] #[configurable(metadata(docs::human_name = "Retry Delay"))] pub retry_delay_secs: Duration, @@ -198,7 +198,7 @@ pub struct PubsubConfig { /// before sending a keepalive request. If this is set larger than /// `60`, you may see periodic errors sent from the server. #[serde(default = "default_keepalive")] - #[serde_as(as = "serde_with::DurationSeconds")] + #[serde_as(as = "serde_with::DurationSecondsWithFrac")] #[configurable(metadata(docs::human_name = "Keepalive"))] pub keepalive_secs: Duration, diff --git a/src/sources/internal_metrics.rs b/src/sources/internal_metrics.rs index 2b876aeaa8397..86e23c0e0c322 100644 --- a/src/sources/internal_metrics.rs +++ b/src/sources/internal_metrics.rs @@ -26,7 +26,7 @@ use crate::{ #[serde(deny_unknown_fields, default)] pub struct InternalMetricsConfig { /// The interval between metric gathering, in seconds. - #[serde_as(as = "serde_with::DurationSeconds")] + #[serde_as(as = "serde_with::DurationSecondsWithFrac")] #[serde(default = "default_scrape_interval")] #[configurable(metadata(docs::human_name = "Scrape Interval"))] pub scrape_interval_secs: Duration, diff --git a/src/transforms/throttle.rs b/src/transforms/throttle.rs index 740e99477bc2f..9c64f95a7d3cc 100644 --- a/src/transforms/throttle.rs +++ b/src/transforms/throttle.rs @@ -30,7 +30,7 @@ pub struct ThrottleConfig { threshold: u32, /// The time window in which the configured `threshold` is applied, in seconds. - #[serde_as(as = "serde_with::DurationSeconds")] + #[serde_as(as = "serde_with::DurationSecondsWithFrac")] #[configurable(metadata(docs::human_name = "Time Window"))] window_secs: Duration,