vector/aws/
timeout.rs

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