mz_service/
params.rs

1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
9
10use serde::{Deserialize, Serialize};
11use std::time::Duration;
12
13/// gRPC client parameters.
14#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, Eq)]
15pub struct GrpcClientParameters {
16    /// Timeout to apply to initial connection establishment.
17    pub connect_timeout: Option<Duration>,
18    /// Time waited after the last received HTTP/2 frame before sending
19    /// a keep-alive PING to the server. Note that this is an HTTP/2
20    /// keep-alive, and is separate from TCP keep-alives.
21    pub http2_keep_alive_interval: Option<Duration>,
22    /// Time waited without response after a keep-alive PING before
23    /// terminating the connection.
24    pub http2_keep_alive_timeout: Option<Duration>,
25}
26
27impl GrpcClientParameters {
28    /// Update the parameter values with the set ones from `other`.
29    pub fn update(&mut self, other: Self) {
30        let Self {
31            connect_timeout,
32            http2_keep_alive_interval,
33            http2_keep_alive_timeout,
34        } = self;
35        let Self {
36            connect_timeout: other_connect_timeout,
37            http2_keep_alive_interval: other_http2_keep_alive_interval,
38            http2_keep_alive_timeout: other_http2_keep_alive_timeout,
39        } = other;
40
41        if let Some(v) = other_connect_timeout {
42            *connect_timeout = Some(v);
43        }
44        if let Some(v) = other_http2_keep_alive_interval {
45            *http2_keep_alive_interval = Some(v);
46        }
47        if let Some(v) = other_http2_keep_alive_timeout {
48            *http2_keep_alive_timeout = Some(v);
49        }
50    }
51
52    /// Return whether all parameters are unset.
53    pub fn all_unset(&self) -> bool {
54        *self == Self::default()
55    }
56}