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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
use crate::{
duration::{ConfigDuration, LegacyUnit},
duration_setting,
};
duration_setting!(duration_timeout, "timeout", LegacyUnit::Secs);
duration_setting!(
duration_connect_timeout,
"connect_timeout",
LegacyUnit::Secs
);
// Subscription options docs: https://cloud.google.com/pubsub/docs/subscription-properties
/// Google Pub/Sub input connector configuration.
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize, ToSchema)]
pub struct PubSubInputConfig {
/// Set in order to use a Pub/Sub [emulator](https://cloud.google.com/pubsub/docs/emulator)
/// instead of the production service, e.g., 'localhost:8681'.
pub emulator: Option<String>,
/// The content of a Google Cloud credentials JSON file.
///
/// When this option is specified, the connector will use the provided credentials for
/// authentication. Otherwise, it will use Application Default Credentials (ADC) configured
/// in the environment where the Feldera service is running. See
/// [Google Cloud documentation](https://cloud.google.com/docs/authentication/provide-credentials-adc)
/// for information on configuring application default credentials.
///
/// When running Feldera in an environment where ADC are not configured,
/// e.g., a Docker container, use this option to ship Google Cloud credentials from another environment.
/// For example, if you use the
/// [`gcloud auth application-default login`](https://cloud.google.com/pubsub/docs/authentication#client-libs)
/// command for authentication in your local development environment, ADC are stored in the
/// `.config/gcloud/application_default_credentials.json` file in your home directory.
pub credentials: Option<String>,
/// Override the default service endpoint 'pubsub.googleapis.com'
pub endpoint: Option<String>,
/// gRPC channel pool size.
pub pool_size: Option<u32>,
/// gRPC request timeout, for example `30s`.
#[serde(
default,
alias = "timeout_seconds",
deserialize_with = "duration_timeout",
skip_serializing_if = "Option::is_none"
)]
#[schema(value_type = Option<String>)]
pub timeout: Option<ConfigDuration>,
/// gRPC connection timeout, for example `10s`.
#[serde(
default,
alias = "connect_timeout_seconds",
deserialize_with = "duration_connect_timeout",
skip_serializing_if = "Option::is_none"
)]
#[schema(value_type = Option<String>)]
pub connect_timeout: Option<ConfigDuration>,
/// Google Cloud project_id.
///
/// When not specified, the connector will use the project id associated
/// with the authenticated account.
pub project_id: Option<String>,
/// Subscription name.
pub subscription: String,
/// Reset subscription's backlog to a given snapshot on startup,
/// using the Pub/Sub `Seek` API.
///
/// This option is mutually exclusive with the `timestamp` option.
pub snapshot: Option<String>,
/// Reset subscription's backlog to a given timestamp on startup,
/// using the Pub/Sub `Seek` API.
///
/// The value of this option is an ISO 8601-encoded UTC time, e.g., "2024-08-17T16:39:57-08:00".
///
/// This option is mutually exclusive with the `snapshot` option.
pub timestamp: Option<String>,
}
impl crate::sensitive::SensitiveValues for PubSubInputConfig {
fn visit_sensitive_values(&self, visit: &mut dyn FnMut(&str, &str)) {
crate::sensitive::visit_optional("credentials", self.credentials.as_deref(), visit);
}
}
#[cfg(test)]
mod tests {
use super::*;
/// Wraps the fields under test in the `subscription` key the config
/// requires.
fn config_json(fields: &str) -> String {
let separator = if fields.is_empty() { "" } else { ", " };
format!(r#"{{"subscription": "test_subscription"{separator}{fields}}}"#)
}
/// The gRPC request timeout has no default of its own: with neither field
/// set the accessor yields `None`, which leaves the Pub/Sub client's own
/// timeout in place. Both spellings reach one field, so writing both is
/// rejected as a duplicate.
#[test]
fn timeout_accepts_both_spellings() {
for (fields, expected) in [
("", None),
(
r#""timeout": "750ms""#,
Some(ConfigDuration::from_millis(750)),
),
(
r#""timeout_seconds": 20"#,
Some(ConfigDuration::from_secs(20)),
),
] {
let json = config_json(fields);
let config: PubSubInputConfig = serde_json::from_str(&json).unwrap();
assert_eq!(config.timeout, expected, "parsing {json}");
}
}
/// See [`timeout_accepts_both_spellings`].
#[test]
fn connect_timeout_accepts_both_spellings() {
for (fields, expected) in [
("", None),
(
r#""connect_timeout": "5s""#,
Some(ConfigDuration::from_secs(5)),
),
(
r#""connect_timeout_seconds": 30"#,
Some(ConfigDuration::from_secs(30)),
),
] {
let json = config_json(fields);
let config: PubSubInputConfig = serde_json::from_str(&json).unwrap();
assert_eq!(config.connect_timeout, expected, "parsing {json}");
}
}
}