-
Notifications
You must be signed in to change notification settings - Fork 121
/
Copy pathargs.rs
267 lines (218 loc) · 9.08 KB
/
args.rs
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
use clap::Parser;
use iggy::users::defaults::{DEFAULT_ROOT_PASSWORD, DEFAULT_ROOT_USERNAME};
use iggy::utils::duration::IggyDuration;
use std::str::FromStr;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
pub struct Args {
#[arg(long, default_value = "10")]
pub message_batches_limit: u64,
#[arg(long, default_value = DEFAULT_ROOT_USERNAME)]
pub username: String,
#[arg(long, default_value = DEFAULT_ROOT_PASSWORD)]
pub password: String,
#[arg(long, default_value = "1ms")]
pub interval: String,
#[arg(long, default_value = "example-stream")]
pub stream_id: String,
#[arg(long, default_value = "example-topic")]
pub topic_id: String,
#[arg(long, default_value = "1")]
pub partition_id: u32,
#[arg(long, default_value = "1")]
pub partitions_count: u32,
#[arg(long, default_value = "1")]
pub compression_algorithm: u8,
#[arg(long, default_value = "1")]
pub consumer_kind: u8,
#[arg(long, default_value = "1")]
pub consumer_id: u32,
#[arg(long, default_value = "1")]
pub messages_per_batch: u32,
#[arg(long, default_value = "0")]
pub offset: u64,
#[arg(long, default_value = "false")]
pub auto_commit: bool,
#[arg(long, default_value = "tcp")]
pub transport: String,
#[arg(long, default_value = "")]
pub encryption_key: String,
#[arg(long, default_value = "http://localhost:3000")]
pub http_api_url: String,
#[arg(long, default_value = "3")]
pub http_retries: u32,
#[arg(long, default_value = "true")]
pub tcp_reconnection_enabled: bool,
#[arg(long)]
pub tcp_reconnection_max_retries: Option<u32>,
#[arg(long, default_value = "1s")]
pub tcp_reconnection_interval: String,
#[arg(long, default_value = "5s")]
pub tcp_reconnection_reestablish_after: String,
#[arg(long, default_value = "5s")]
pub tcp_heartbeat_interval: String,
#[arg(long, default_value = "127.0.0.1:8090")]
pub tcp_server_address: String,
#[arg(long, default_value = "false")]
pub tcp_tls_enabled: bool,
#[arg(long, default_value = "localhost")]
pub tcp_tls_domain: String,
#[arg(long, default_value = "false")]
pub tcp_nodelay: bool,
#[arg(long, default_value = "127.0.0.1:0")]
pub quic_client_address: String,
#[arg(long, default_value = "127.0.0.1:8080")]
pub quic_server_address: String,
#[arg(long, default_value = "localhost")]
pub quic_server_name: String,
#[arg(long, default_value = "true")]
pub quic_reconnection_enabled: bool,
#[arg(long)]
pub quic_reconnection_max_retries: Option<u32>,
#[arg(long, default_value = "1s")]
pub quic_reconnection_interval: String,
#[arg(long, default_value = "5s")]
pub quic_reconnection_reestablish_after: String,
#[arg(long, default_value = "10000")]
pub quic_max_concurrent_bidi_streams: u64,
#[arg(long, default_value = "100000")]
pub quic_datagram_send_buffer_size: u64,
#[arg(long, default_value = "1200")]
pub quic_initial_mtu: u16,
#[arg(long, default_value = "100000")]
pub quic_send_window: u64,
#[arg(long, default_value = "100000")]
pub quic_receive_window: u64,
#[arg(long, default_value = "1048576")]
pub quic_response_buffer_size: u64,
#[arg(long, default_value = "5000")]
pub quic_keep_alive_interval: u64,
#[arg(long, default_value = "10000")]
pub quic_max_idle_timeout: u64,
#[arg(long, default_value = "false")]
pub quic_validate_certificate: bool,
#[arg(long, default_value = "5s")]
pub quic_heartbeat_interval: String,
}
impl Args {
#[inline]
pub fn new(stream_id: String, topic_id: String) -> Self {
Self {
stream_id,
topic_id,
..Default::default()
}
}
}
impl Default for Args {
fn default() -> Self {
Self {
message_batches_limit: 10,
username: DEFAULT_ROOT_PASSWORD.to_string(),
password: DEFAULT_ROOT_USERNAME.to_string(),
interval: "1ms".to_string(),
stream_id: "example-stream".to_string(),
topic_id: "example-topic".to_string(),
partition_id: 1,
partitions_count: 1,
compression_algorithm: 1,
consumer_kind: 1,
consumer_id: 1,
messages_per_batch: 1,
offset: 0,
auto_commit: false,
transport: "tcp".to_string(),
encryption_key: String::new(),
http_api_url: "http://localhost:3000".to_string(),
http_retries: 3,
tcp_reconnection_enabled: true,
tcp_reconnection_max_retries: Some(3),
tcp_reconnection_interval: "1s".to_string(),
tcp_reconnection_reestablish_after: "5s".to_string(),
tcp_heartbeat_interval: "5s".to_string(),
tcp_server_address: "127.0.0.1:8090".to_string(),
tcp_tls_enabled: false,
tcp_tls_domain: "localhost".to_string(),
tcp_nodelay: true,
quic_client_address: "127.0.0.1:0".to_string(),
quic_server_address: "127.0.0.1:8080".to_string(),
quic_server_name: "localhost".to_string(),
quic_reconnection_enabled: true,
quic_reconnection_max_retries: None,
quic_reconnection_interval: "1s".to_string(),
quic_reconnection_reestablish_after: "5s".to_string(),
quic_max_concurrent_bidi_streams: 10000,
quic_datagram_send_buffer_size: 100000,
quic_initial_mtu: 1200,
quic_send_window: 100000,
quic_receive_window: 100000,
quic_response_buffer_size: 1048576,
quic_keep_alive_interval: 5000,
quic_max_idle_timeout: 10000,
quic_validate_certificate: false,
quic_heartbeat_interval: "5s".to_string(),
}
}
}
impl Args {
pub fn to_sdk_args(&self) -> iggy::args::Args {
iggy::args::Args {
transport: self.transport.clone(),
encryption_key: self.encryption_key.clone(),
http_api_url: self.http_api_url.clone(),
http_retries: self.http_retries,
username: self.username.clone(),
password: self.password.clone(),
tcp_server_address: self.tcp_server_address.clone(),
tcp_reconnection_enabled: self.tcp_reconnection_enabled,
tcp_reconnection_max_retries: self.tcp_reconnection_max_retries,
tcp_reconnection_interval: self.tcp_reconnection_interval.clone(),
tcp_reconnection_reestablish_after: self.tcp_reconnection_reestablish_after.clone(),
tcp_heartbeat_interval: self.tcp_heartbeat_interval.clone(),
tcp_tls_enabled: self.tcp_tls_enabled,
tcp_tls_domain: self.tcp_tls_domain.clone(),
tcp_tls_ca_file: None,
tcp_nodelay: self.tcp_nodelay,
quic_client_address: self.quic_client_address.clone(),
quic_server_address: self.quic_server_address.clone(),
quic_server_name: self.quic_server_name.clone(),
quic_reconnection_enabled: self.quic_reconnection_enabled,
quic_reconnection_max_retries: self.quic_reconnection_max_retries,
quic_reconnection_reestablish_after: self.quic_reconnection_reestablish_after.clone(),
quic_reconnection_interval: self.quic_reconnection_interval.clone(),
quic_max_concurrent_bidi_streams: self.quic_max_concurrent_bidi_streams,
quic_datagram_send_buffer_size: self.quic_datagram_send_buffer_size,
quic_initial_mtu: self.quic_initial_mtu,
quic_send_window: self.quic_send_window,
quic_receive_window: self.quic_receive_window,
quic_response_buffer_size: self.quic_response_buffer_size,
quic_keep_alive_interval: self.quic_keep_alive_interval,
quic_max_idle_timeout: self.quic_max_idle_timeout,
quic_validate_certificate: self.quic_validate_certificate,
quic_heartbeat_interval: self.quic_heartbeat_interval.clone(),
}
}
pub fn get_interval(&self) -> Option<IggyDuration> {
match self.interval.to_lowercase().as_str() {
"" | "0" | "none" => None,
x => Some(IggyDuration::from_str(x).expect("Invalid interval format")),
}
}
}