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.
910use mz_proto::{ProtoType, RustType, TryFromProtoError};
11use proptest_derive::Arbitrary;
12use serde::{Deserialize, Serialize};
13use std::time::Duration;
1415include!(concat!(env!("OUT_DIR"), "/mz_service.params.rs"));
1617/// gRPC client parameters.
18#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, Eq, Arbitrary)]
19pub struct GrpcClientParameters {
20/// Timeout to apply to initial connection establishment.
21pub connect_timeout: Option<Duration>,
22/// Time waited after the last received HTTP/2 frame before sending
23 /// a keep-alive PING to the server. Note that this is an HTTP/2
24 /// keep-alive, and is separate from TCP keep-alives.
25pub http2_keep_alive_interval: Option<Duration>,
26/// Time waited without response after a keep-alive PING before
27 /// terminating the connection.
28pub http2_keep_alive_timeout: Option<Duration>,
29}
3031impl GrpcClientParameters {
32/// Update the parameter values with the set ones from `other`.
33pub fn update(&mut self, other: Self) {
34let Self {
35 connect_timeout,
36 http2_keep_alive_interval,
37 http2_keep_alive_timeout,
38 } = self;
39let Self {
40 connect_timeout: other_connect_timeout,
41 http2_keep_alive_interval: other_http2_keep_alive_interval,
42 http2_keep_alive_timeout: other_http2_keep_alive_timeout,
43 } = other;
4445if let Some(v) = other_connect_timeout {
46*connect_timeout = Some(v);
47 }
48if let Some(v) = other_http2_keep_alive_interval {
49*http2_keep_alive_interval = Some(v);
50 }
51if let Some(v) = other_http2_keep_alive_timeout {
52*http2_keep_alive_timeout = Some(v);
53 }
54 }
5556/// Return whether all parameters are unset.
57pub fn all_unset(&self) -> bool {
58*self == Self::default()
59 }
60}
6162impl RustType<ProtoGrpcClientParameters> for GrpcClientParameters {
63fn into_proto(&self) -> ProtoGrpcClientParameters {
64 ProtoGrpcClientParameters {
65 connect_timeout: self.connect_timeout.into_proto(),
66 http2_keep_alive_interval: self.http2_keep_alive_interval.into_proto(),
67 http2_keep_alive_timeout: self.http2_keep_alive_timeout.into_proto(),
68 }
69 }
7071fn from_proto(proto: ProtoGrpcClientParameters) -> Result<Self, TryFromProtoError> {
72Ok(Self {
73 connect_timeout: proto.connect_timeout.into_rust()?,
74 http2_keep_alive_interval: proto.http2_keep_alive_interval.into_rust()?,
75 http2_keep_alive_timeout: proto.http2_keep_alive_timeout.into_rust()?,
76 })
77 }
78}