1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//! Client timeout configuration for AWS operations.
//use std::time::Duration;
use vector_lib::configurable::configurable_component;

use serde_with::serde_as;

/// Client timeout configuration for AWS operations.
#[serde_as]
#[configurable_component]
#[derive(Copy, Clone, Debug, Derivative)]
#[derivative(Default)]
#[serde(deny_unknown_fields)]
pub struct AwsTimeout {
    /// The connection timeout for AWS requests
    ///
    /// Limits the amount of time allowed to initiate a socket connection.
    #[configurable(metadata(docs::examples = 20))]
    #[configurable(metadata(docs::human_name = "Connect Timeout"))]
    #[configurable(metadata(docs::type_unit = "seconds"))]
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(rename = "connect_timeout_seconds")]
    connect_timeout: Option<u64>,

    /// The operation timeout for AWS requests
    ///
    /// Limits the amount of time allowed for an operation to be fully serviced; an
    /// operation represents the full request/response lifecycle of a call to a service.
    /// Take care when configuring this settings to allow enough time for the polling
    /// interval configured in `poll_secs`
    #[configurable(metadata(docs::examples = 20))]
    #[configurable(metadata(docs::human_name = "Operation Timeout"))]
    #[configurable(metadata(docs::type_unit = "seconds"))]
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(rename = "operation_timeout_seconds")]
    operation_timeout: Option<u64>,

    /// The read timeout for AWS requests
    ///
    /// Limits the amount of time allowed to read the first byte of a response from the
    /// time the request is initiated. Take care when configuring this settings to allow
    /// enough time for the polling interval configured in `poll_secs`
    #[configurable(metadata(docs::examples = 20))]
    #[configurable(metadata(docs::human_name = "Read Timeout"))]
    #[configurable(metadata(docs::type_unit = "seconds"))]
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(rename = "read_timeout_seconds")]
    read_timeout: Option<u64>,
}

impl AwsTimeout {
    /// returns the connection timeout
    pub const fn connect_timeout(&self) -> Option<u64> {
        self.connect_timeout
    }

    /// returns the operation timeout
    pub const fn operation_timeout(&self) -> Option<u64> {
        self.operation_timeout
    }

    /// returns the read timeout
    pub const fn read_timeout(&self) -> Option<u64> {
        self.read_timeout
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn parsing_timeout_configuration() {
        let config = toml::from_str::<AwsTimeout>(
            r"
            connect_timeout_seconds = 20
            operation_timeout_seconds = 20
            read_timeout_seconds = 60
        ",
        )
        .unwrap();

        assert_eq!(config.connect_timeout, Some(20));
        assert_eq!(config.operation_timeout, Some(20));
        assert_eq!(config.read_timeout, Some(60));
    }
}