vector/aws/
timeout.rs

1//! Client timeout configuration for AWS operations.
2//use std::time::Duration;
3use vector_lib::configurable::configurable_component;
4
5use serde_with::serde_as;
6
7/// Client timeout configuration for AWS operations.
8#[serde_as]
9#[configurable_component]
10#[derive(Copy, Clone, Debug, Derivative)]
11#[derivative(Default)]
12#[serde(deny_unknown_fields)]
13pub struct AwsTimeout {
14    /// The connection timeout for AWS requests
15    ///
16    /// Limits the amount of time allowed to initiate a socket connection.
17    #[configurable(metadata(docs::examples = 20))]
18    #[configurable(metadata(docs::human_name = "Connect Timeout"))]
19    #[configurable(metadata(docs::type_unit = "seconds"))]
20    #[serde(skip_serializing_if = "Option::is_none")]
21    #[serde(rename = "connect_timeout_seconds")]
22    connect_timeout: Option<u64>,
23
24    /// The operation timeout for AWS requests
25    ///
26    /// Limits the amount of time allowed for an operation to be fully serviced; an
27    /// operation represents the full request/response lifecycle of a call to a service.
28    /// Take care when configuring this settings to allow enough time for the polling
29    /// interval configured in `poll_secs`
30    #[configurable(metadata(docs::examples = 20))]
31    #[configurable(metadata(docs::human_name = "Operation Timeout"))]
32    #[configurable(metadata(docs::type_unit = "seconds"))]
33    #[serde(skip_serializing_if = "Option::is_none")]
34    #[serde(rename = "operation_timeout_seconds")]
35    operation_timeout: Option<u64>,
36
37    /// The read timeout for AWS requests
38    ///
39    /// Limits the amount of time allowed to read the first byte of a response from the
40    /// time the request is initiated. Take care when configuring this settings to allow
41    /// enough time for the polling interval configured in `poll_secs`
42    #[configurable(metadata(docs::examples = 20))]
43    #[configurable(metadata(docs::human_name = "Read Timeout"))]
44    #[configurable(metadata(docs::type_unit = "seconds"))]
45    #[serde(skip_serializing_if = "Option::is_none")]
46    #[serde(rename = "read_timeout_seconds")]
47    read_timeout: Option<u64>,
48}
49
50impl AwsTimeout {
51    /// returns the connection timeout
52    pub const fn connect_timeout(&self) -> Option<u64> {
53        self.connect_timeout
54    }
55
56    /// returns the operation timeout
57    pub const fn operation_timeout(&self) -> Option<u64> {
58        self.operation_timeout
59    }
60
61    /// returns the read timeout
62    pub const fn read_timeout(&self) -> Option<u64> {
63        self.read_timeout
64    }
65}
66
67#[cfg(test)]
68mod tests {
69    use super::*;
70
71    #[test]
72    fn parsing_timeout_configuration() {
73        let config = toml::from_str::<AwsTimeout>(
74            r"
75            connect_timeout_seconds = 20
76            operation_timeout_seconds = 20
77            read_timeout_seconds = 60
78        ",
79        )
80        .unwrap();
81
82        assert_eq!(config.connect_timeout, Some(20));
83        assert_eq!(config.operation_timeout, Some(20));
84        assert_eq!(config.read_timeout, Some(60));
85    }
86}