-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathcli.rs
More file actions
922 lines (885 loc) · 32.8 KB
/
cli.rs
File metadata and controls
922 lines (885 loc) · 32.8 KB
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
use clap::{Args, Parser, Subcommand, ValueEnum, ValueHint};
use clap_complete::engine::{ArgValueCompleter, CompletionCandidate};
use std::fmt::Display;
use std::path::PathBuf;
use crate::make_client;
use feldera_rest_api::types::{ClusterMonitorEventFieldSelector, CompilationProfile};
/// Autocompletion for pipeline names by trying to fetch them from the server.
fn pipeline_names(current: &std::ffi::OsStr) -> Vec<CompletionCandidate> {
let mut completions = vec![];
// We parse FELDERA_HOST and FELDERA_API_KEY from the environment
// using the `try_parse_from` method.
let cli = Cli::try_parse_from(["fda", "pipelines"]);
if let Ok(cli) = cli {
let client = make_client(cli.host, cli.insecure, cli.auth, cli.timeout).unwrap();
let r = futures::executor::block_on(async {
client
.list_pipelines()
.send()
.await
.map(|r| r.into_inner())
.unwrap_or_else(|_| vec![])
});
let current = current.to_string_lossy();
for pipeline in r {
if pipeline.name.starts_with(current.as_ref()) {
completions.push(CompletionCandidate::new(pipeline.name));
}
}
}
completions
}
#[derive(Parser)]
#[command(
name = "fda",
about = "A CLI to interact with the Feldera REST API.",
after_help = "Commands marked EXPERIMENTAL may change or be removed at any time.",
version
)]
pub struct Cli {
#[command(subcommand)]
pub command: Commands,
/// The format in which the outputs from feldera should be displayed.
///
/// Note that this flag may have no effect on some commands in case
/// the requested output format is not supported for it.
#[arg(
long,
env = "FELDERA_OUTPUT_FORMAT",
global = true,
help_heading = "Global Options",
default_value = "text"
)]
pub format: OutputFormat,
/// The Feldera host to connect to.
#[arg(
long,
env = "FELDERA_HOST",
value_hint = ValueHint::Url,
global = true,
help_heading = "Global Options",
default_value_t = String::from("https://try.feldera.com")
)]
pub host: String,
/// Accept invalid HTTPS certificates.
#[arg(
short = 'k',
long,
env = "FELDERA_TLS_INSECURE",
global = true,
default_value_t = false,
help_heading = "Global Options"
)]
pub insecure: bool,
/// Which API key to use for authentication.
///
/// The provided string should start with "apikey:" followed by the random characters.
///
/// If not specified, a request without authentication will be used.
#[arg(
long,
env = "FELDERA_API_KEY",
global = true,
hide_env_values = true,
help_heading = "Global Options"
)]
pub auth: Option<String>,
/// The client timeout for requests in seconds.
///
/// In almost all cases you should not need to set this value, but it can
/// be useful to limit the execution of certain commands (e.g., `query` or
/// `logs`).
///
/// By default, no timeout is set.
#[arg(
long,
env = "FELDERA_REQUEST_TIMEOUT",
global = true,
help_heading = "Global Options"
)]
pub timeout: Option<u64>,
}
#[derive(ValueEnum, Clone, Copy, Debug, PartialEq)]
#[value(rename_all = "snake_case")]
pub enum OutputFormat {
/// Return the output in a human-readable text format.
Text,
/// Return the output in JSON format.
///
/// This usually corresponds to the exact response returned from the server.
Json,
/// Request the output in Arrow IPC format.
///
/// This format can only be specified for SQL queries.
ArrowIpc,
/// Return the output in Parquet format.
///
/// This format can only be specified for SQL queries.
Parquet,
/// Returns the output in Prometheus format.
///
/// This format can only be specified for the `metrics` command.
Prometheus,
/// Returns a hash of the result instead of the result.
///
/// This format can only be specified for ad-hoc SQL queries.
/// The output in this case is a single string/line containing a SHA256 hash.
Hash,
}
impl Display for OutputFormat {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let output = match self {
OutputFormat::Text => "text",
OutputFormat::Json => "json",
OutputFormat::ArrowIpc => "arrow_ipc",
OutputFormat::Parquet => "parquet",
OutputFormat::Prometheus => "prometheus",
OutputFormat::Hash => "hash",
};
write!(f, "{}", output)
}
}
#[derive(Subcommand)]
pub enum Commands {
/// List the available pipelines.
#[command(next_help_heading = "Pipeline Commands")]
Pipelines,
/// Interact with a pipeline.
///
/// If no sub-command is specified retrieves all configuration data for the pipeline.
#[command(flatten)]
Pipeline(PipelineAction),
/// Manage API keys.
Apikey {
#[command(subcommand)]
action: ApiKeyActions,
},
/// Cluster information and status.
Cluster {
#[command(subcommand)]
action: ClusterAction,
},
/// EXPERIMENTAL: Debugging tools.
Debug {
#[command(subcommand)]
action: DebugActions,
},
}
#[derive(Subcommand)]
pub enum ApiKeyActions {
/// List available API keys
List,
/// Create a new API key
Create {
/// The name of the API key to create
name: String,
},
/// Delete an existing API key
#[clap(aliases = &["del"])]
Delete {
/// The name of the API key to delete
name: String,
},
}
#[derive(Subcommand)]
pub enum ClusterAction {
/// Retrieves all cluster events (status only) and prints them.
Events,
/// Retrieve specific cluster event.
Event {
/// Identifier (UUID) of the event or `latest`.
id: String,
/// Either `all` or `status` (default).
#[arg(default_value = "status")]
selector: ClusterMonitorEventFieldSelector,
},
}
#[derive(Subcommand)]
pub enum DebugActions {
/// EXPERIMENTAL: Print a MessagePack file, such as `steps.bin` in a checkpoint directory,
/// to stdout.
MsgpCat {
/// The MessagePack file to read.
#[arg(value_hint = ValueHint::FilePath)]
path: PathBuf,
},
/// EXPERIMENTAL: Reads metrics from a file and prints them in an easier-to-read form.
Metrics {
/// The Prometheus metrics file to read.
#[arg(value_hint = ValueHint::FilePath)]
path: PathBuf,
},
/// EXPERIMENTAL: Re-creates the pipeline(s) found in a support bundle.
Unbundle {
/// Support Bundle Zip File.
#[arg(value_hint = ValueHint::FilePath)]
path: PathBuf,
/// Only extract and show pipeline information without trying to create the pipelines.
#[arg(long)]
dry_run: bool,
/// Overwrite pipelines if they already exist.
#[arg(long)]
force: bool,
},
}
/// A list of possible configuration options.
#[derive(ValueEnum, Clone, Copy, Debug)]
#[value(rename_all = "snake_case")]
pub enum RuntimeConfigKey {
Workers,
Storage,
FaultTolerance,
CheckpointInterval,
CpuProfiler,
Tracing,
TracingEndpointJaeger,
MinBatchSizeRecords,
MaxBufferingDelayUsecs,
CpuCoresMin,
CpuCoresMax,
MemoryMbMin,
MemoryMbMax,
StorageMbMax,
StorageClass,
MinStorageBytes,
ClockResolutionUsecs,
Logging,
HttpWorkers,
IoWorkers,
DevTweaks,
}
#[derive(Subcommand)]
pub enum PipelineAction {
/// Create a new pipeline.
Create {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
/// A path to a file containing the SQL code.
///
/// If no path is provided, the pipeline will be created with an empty program.
/// See the `stdin` flag for reading from stdin instead.
#[arg(value_hint = ValueHint::FilePath, conflicts_with = "stdin")]
program_path: Option<String>,
/// A path to a file containing the Rust UDF functions.
#[arg(short = 'u', long, value_hint = ValueHint::FilePath, conflicts_with = "stdin")]
udf_rs: Option<String>,
/// A path to the TOML file containing the dependencies for the UDF functions.
#[arg(short = 't', long, value_hint = ValueHint::FilePath, conflicts_with = "stdin")]
udf_toml: Option<String>,
/// Override the runtime version of the pipeline.
///
/// If not specified, the default version of the platform will be used.
///
/// Note: This feature needs to be enabled in the platform configuration
/// and is still in development. Use for testing purposes only.
#[arg(long, short = 'r', env = "FELDERA_RUNTIME_VERSION")]
runtime_version: Option<String>,
/// The compilation profile to use.
#[arg(default_value = "optimized")]
profile: CompilationProfile,
/// Read the program code from stdin.
///
/// EXAMPLES:
///
/// * cat program.sql | fda create p1 -s
/// * echo "SELECT 1" | fda create p2 -s
/// * fda program get p2 | fda create p3 -s
#[arg(
verbatim_doc_comment,
short = 's',
long,
default_value_t = false,
conflicts_with = "program_path"
)]
stdin: bool,
},
/// Start a pipeline.
///
/// If the pipeline is compiling it will wait for the compilation to finish.
Start {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
/// Force the recompilation of the pipeline before starting.
///
/// This is useful for dev purposes in case the Feldera source-code has changed.
#[arg(long, short = 'r', default_value_t = false)]
recompile: bool,
/// Don't wait for pipeline to reach the status before returning.
#[arg(long, short = 'n', default_value_t = false)]
no_wait: bool,
/// Initial desired runtime status once the pipeline is started.
#[arg(long, short = 'i', default_value = "running")]
initial: String,
/// The bootstrap policy to use.
// TODO: auto-complete
#[arg(long, short = 'b', default_value = "await_approval")]
bootstrap_policy: String,
/// Do not dismiss any deployment error before starting.
#[arg(long, default_value_t = false)]
no_dismiss_error: bool,
},
/// Approve pipeline changes. Called in the AwaitingApproval state to allow
/// the pipeline to proceed with bootstrapping the modified components.
Approve {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
},
/// Checkpoint a fault-tolerant pipeline.
Checkpoint {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
/// Don't wait for pipeline to complete the checkpoint.
#[arg(long, short = 'n', default_value_t = false)]
no_wait: bool,
},
/// Pause a pipeline.
Pause {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
/// Don't wait for pipeline to reach the status before returning.
#[arg(long, short = 'n', default_value_t = false)]
no_wait: bool,
},
/// Resume a pipeline.
Resume {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
/// Don't wait for pipeline to reach the status before returning.
#[arg(long, short = 'n', default_value_t = false)]
no_wait: bool,
},
/// Stop a pipeline, then start it again.
///
/// This is a shortcut for calling `fda stop p1 && fda start p1`.
Restart {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
/// Force the recompilation of the pipeline before starting.
///
/// This is useful for dev purposes in case the Feldera source-code has changed.
#[arg(long, short = 'r', default_value_t = false)]
recompile: bool,
/// Checkpoint the pipeline before restarting it.
#[arg(long, short = 'c', default_value_t = false)]
checkpoint: bool,
/// Don't wait for pipeline to reach the status before returning.
#[arg(long, short = 'n', default_value_t = false)]
no_wait: bool,
/// Initial desired runtime status once the pipeline is restarted.
#[arg(long, short = 'i', default_value = "running")]
initial: String,
/// The bootstrap policy to use.
#[arg(long, short = 'b', default_value = "await_approval")]
bootstrap_policy: String,
/// Do not dismiss any deployment error before starting.
#[arg(long, default_value_t = false)]
no_dismiss_error: bool,
},
/// Stop a pipeline.
#[clap(aliases = &["shutdown"])]
Stop {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
/// Checkpoint the pipeline before stopping it.
#[arg(long, short = 'c', default_value_t = false)]
checkpoint: bool,
/// Don't wait for pipeline to reach the status before returning.
#[arg(long, short = 'n', default_value_t = false)]
no_wait: bool,
},
/// Retrieve the entire state of a pipeline.
///
/// EXAMPLES:
///
/// - `fda status test | jq .program_info.schema`
///
/// - `fda status test | jq .program_info.input_connectors`
///
/// - `fda status test | jq .deployment_config`
Status {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
},
/// Retrieve the runtime statistics of a pipeline.
#[clap(aliases = &["statistics"])]
Stats {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
},
/// Retrieve the pipeline metrics.
///
/// Metrics are available in `json` and `prometheus` output formats.
Metrics {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
},
/// Retrieve the logs of a pipeline.
#[clap(aliases = &["log"])]
Logs {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
/// Watch the log endpoint and emit new pipeline log messages as they are written.
///
/// When `true`, the command will listen to pipeline logs until the pipeline terminates or
/// the command is interrupted by the user. When `false`, the command outputs pipeline logs
/// accumulated so far and exits.
#[arg(long, short = 'w', default_value_t = false)]
watch: bool,
},
/// Interact with the program of the pipeline.
///
/// If no sub-command is specified retrieves the program.
Program {
#[command(subcommand)]
action: ProgramAction,
},
/// Retrieve the runtime configuration of a pipeline.
#[clap(aliases = &["cfg"])]
Config {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
},
/// Update the runtime configuration of a pipeline.
#[clap(aliases = &["set-cfg"])]
SetConfig {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
/// The key of the configuration to update.
key: RuntimeConfigKey,
/// The new value for the configuration.
value: String,
},
/// Recompile a pipeline with the Feldera runtime version included in the
/// currently installed Feldera platform.
UpdateRuntime {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
},
/// Delete a pipeline.
#[clap(aliases = &["del"])]
Delete {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
/// Clears any associated storage first to force deletion of the pipeline.
///
/// EXAMPLES:
///
/// - fda delete --force my-pipeline
///
/// Is equivalent to:
///
/// - fda clear my-pipeline && fda delete my-pipeline
#[arg(long, short = 'f')]
force: bool,
},
/// Control an input connector belonging to a table of a pipeline.
Connector {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
/// The name of the table or view.
relation_name: String,
/// The name of the connector.
connector_name: String,
#[command(subcommand)]
action: ConnectorAction,
},
/// Obtains a heap profile for a pipeline.
///
/// By default, or with `--pprof`, this command retrieves the heap profile
/// to a temporary file and then displays it with `pprof`. With `--output`,
/// this command instead writes the heap profile to the specified file.
///
/// Get `pprof` from <https://github.com/google/pprof>. There is at least
/// one other program named `pprof` that is unrelated and will not work.
HeapProfile {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
/// The `pprof` command to run as a subprocess. The name of the `pprof`
/// file will be provided as an additional command-line argument.
#[arg(long, short = 'p', default_value = "pprof -http :")]
pprof: String,
/// The file to write the profile to.
#[arg(value_hint = ValueHint::FilePath, long, short = 'o')]
output: Option<PathBuf>,
},
/// Obtains a circuit profile for a pipeline.
CircuitProfile {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
/// The ZIP file to write the profile to.
#[arg(value_hint = ValueHint::FilePath, long, short = 'o')]
output: Option<PathBuf>,
},
/// Download a support bundle which contains debug information about the pipeline.
SupportBundle {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
/// The ZIP file to write the bundle to.
#[arg(value_hint = ValueHint::FilePath, long, short = 'o')]
output: Option<PathBuf>,
/// Skip circuit profile collection.
#[arg(long)]
no_circuit_profile: bool,
/// Skip heap profile collection.
#[arg(long)]
no_heap_profile: bool,
/// Skip metrics collection.
#[arg(long)]
no_metrics: bool,
/// Skip logs collection.
#[arg(long)]
no_logs: bool,
/// Skip stats collection.
#[arg(long)]
no_stats: bool,
/// Skip pipeline configuration collection.
#[arg(long)]
no_pipeline_config: bool,
/// Skip system configuration collection.
#[arg(long)]
no_system_config: bool,
/// Skip dataflow graph collection.
#[arg(long)]
no_dataflow_graph: bool,
},
/// Enter the ad-hoc SQL shell for a pipeline.
Shell {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
/// Start the pipeline before entering the shell.
#[arg(long, short = 's', default_value_t = false)]
start: bool,
/// Initial desired runtime status once the pipeline is started
/// (ignored unless `--start` is provided).
#[arg(long, short = 'i', default_value = "running")]
initial: String,
/// The bootstrap policy to use.
#[arg(long, short = 'b', default_value = "await_approval")]
bootstrap_policy: String,
/// Do not dismiss any deployment error before starting.
#[arg(long, default_value_t = false, requires("start"))]
no_dismiss_error: bool,
},
/// Execute an ad-hoc query against a pipeline and return the result.
#[clap(aliases = &["exec"])]
Query {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
/// The SQL query to execute against the pipeline.
///
/// EXAMPLES:
///
/// * fda exec p1 "SELECT 1;"
#[arg(verbatim_doc_comment, conflicts_with = "stdin")]
sql: Option<String>,
/// Read the SQL query from stdin.
///
/// EXAMPLES:
///
/// * cat query.sql | fda exec p1 -s
/// * echo "SELECT 1" | fda exec p1 -s
#[arg(
verbatim_doc_comment,
short = 's',
long,
default_value_t = false,
conflicts_with = "sql"
)]
stdin: bool,
},
/// Generate a completion token for a SQL table/connector pair in a pipeline.
#[clap(aliases = &["generate-token", "generate-completion-token"])]
CompletionToken {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
/// The name of the SQL table to generate the token for.
table: String,
/// The name of the connector to generate the token for.
///
/// This can be read from the `name` field in the connector config.
connector: String,
},
/// Check the status of a completion token for a pipeline.
#[clap(aliases = &["check-token", "check-completion-token"])]
CompletionStatus {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
/// The token to check the status for.
///
/// A token can be optained by running `fda completion-token`.
/// Or when ingesting data over HTTP.
token: String,
},
/// Start a new transaction.
#[clap(aliases = &["transaction-start"])]
StartTransaction {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
},
/// Commit the current transaction.
///
/// Commits the currently active transaction for the specified pipeline.
/// Optionally waits for the commit to complete.
#[clap(aliases = &["commit", "transaction-commit"])]
CommitTransaction {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
/// The transaction ID to verify against the current active transaction.
/// If provided, the function verifies that the currently active transaction matches this ID.
#[arg(long = "tid", short = 't')]
transaction_id: Option<u64>,
/// Don't wait for the transaction to commit before returning.
#[arg(long, short = 'n', default_value_t = false)]
no_wait: bool,
},
/// Initiate rebalancing.
Rebalance {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
},
/// Clear the storage resources of a pipeline.
///
/// Note that the pipeline must be stopped before clearing its storage resources.
Clear {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
/// Don't wait for pipeline storage to clear before returning.
#[arg(long, short = 'n', default_value_t = false)]
no_wait: bool,
},
/// Benchmark the performance of a pipeline.
///
/// This command will perform the following steps
/// 1. ensure the benchmark is compiled with the latest platform version
/// 2. run the pipeline & record stats over time
/// 3. post-process and check recorded statistics
/// 4. aggregate basic performance metrics and output them in the specified format
Bench {
#[command(flatten)]
args: BenchmarkArgs,
},
/// Dismisses the deployment error of a pipeline.
DismissError {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
},
}
#[derive(Args, Debug)]
pub(crate) struct BenchmarkArgs {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
pub name: String,
/// Duration of the benchmark in seconds.
///
/// If not specified, the benchmark will run until the pipeline indicates it has processed all input.
#[arg(long, short = 'd')]
pub duration: Option<u64>,
/// Do not recompile the pipeline before starting.
///
/// If set to true, one might end up with a pipeline that's not
/// compiled with the latest feldera runtime.
#[arg(long, short = 'n', default_value_t = false)]
pub no_recompile: bool,
/// Do not wrap the benchmark in a transaction.
#[arg(long, default_value_t = false)]
pub no_transaction: bool,
/// If set upload results to feldera benchmark host.
///
/// For development purposes, you most likely don't want to set this to true.
///
/// Requires `benchmark_token` token to be set.
#[arg(long, short = 'u', default_value_t = false)]
pub upload: bool,
/// Slug or UUID of the project to add results to when uploading
/// (requires: `--upload`).
#[arg(long, short = 'p', env = "BENCHER_PROJECT")]
pub project: String,
/// Branch name, slug, or UUID. By default it will be set to `main`
/// (requires: `--upload`).
#[arg(long, default_value_t = String::from("main"))]
pub branch: String,
/// Use the specified branch name as the start point for `branch`
/// (requires: `--upload`).
///
/// - If `branch` already exists and the start point is different, a new
/// branch will be created.
#[arg(long)]
pub start_point: Option<String>,
/// Use the specified full `git` hash as the start point for `branch`
/// (requires: `--start-point` and `--upload`).
///
/// - If `start_point` already exists and the start point hash is different,
/// a new branch will be created
#[arg(long)]
pub start_point_hash: Option<String>,
/// The maximum number of historical branch versions to include
/// (requires: `--start-point` and `--upload`).
///
/// Versions beyond this number will be omitted.
#[arg(long, default_value_t = 255)]
pub start_point_max_versions: u32,
/// Clone thresholds from the start point branch
/// (requires: `--branch-start-point` and `--upload`).
#[arg(long)]
pub start_point_clone_thresholds: bool,
/// Reset the branch head to an empty state
/// (requires: `--branch-start-point` and `--upload`).
///
/// If `start_point` is specified, the new branch head will begin at that start point.
/// Otherwise, the branch head will be reset to an empty state
#[arg(long)]
pub start_point_reset: bool,
/// Where to upload benchmark results to
/// (requires: `--upload`).
#[arg(
long,
short = 'b',
env = "BENCHER_HOST",
value_hint = ValueHint::Url,
default_value_t = String::from("https://benchmarks.feldera.io/")
)]
pub benchmark_host: String,
/// Which API key to use for authentication with benchmarks server
/// (requires: `--upload`).
#[arg(long, short = 't', env = "BENCHER_API_TOKEN", hide_env_values = true)]
pub benchmark_token: Option<String>,
}
#[derive(Subcommand)]
pub enum ProgramAction {
/// Retrieve the program code.
///
/// By default, this returns the SQL code, but you can use the flags to retrieve
/// the Rust UDF code instead.
Get {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
/// Retrieve the Rust UDF code.
#[arg(short = 'u', long, default_value_t = false)]
udf_rs: bool,
/// Retrieve the TOML dependencies file for the UDF code.
#[arg(short = 't', long, default_value_t = false)]
udf_toml: bool,
},
/// Sets a new program.
Set {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
/// A path to a file containing the SQL code.
///
/// See the `stdin` flag for reading from stdin instead.
#[arg(value_hint = ValueHint::FilePath, conflicts_with = "stdin")]
program_path: Option<String>,
/// A path to a file containing the Rust UDF functions.
#[arg(short = 'u', long, value_hint = ValueHint::FilePath, conflicts_with = "stdin")]
udf_rs: Option<String>,
/// A path to the TOML file containing the dependencies for the UDF functions.
#[arg(short = 't', long, value_hint = ValueHint::FilePath, conflicts_with = "stdin")]
udf_toml: Option<String>,
/// Read the SQL program code from stdin.
///
/// EXAMPLES:
///
/// * cat program.sql | fda program set p1 -s
/// * echo "SELECT 1" | fda program set p1 -s
/// * fda program get p2 | fda program set p1 -s
#[arg(verbatim_doc_comment, short = 's', long, default_value_t = false)]
stdin: bool,
},
/// Retrieve the configuration of the program.
#[clap(aliases = &["cfg"])]
Config {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
},
/// Set the configuration of the program.
#[clap(aliases = &["set-cfg"])]
SetConfig {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
/// The updated configuration for the pipeline.
///
/// The profile accepts the following values:
/// `dev`, `unoptimized`, `optimized`
///
/// If not specified, the optimized profile will be used.
#[arg(short = 'p', long)]
profile: Option<CompilationProfile>,
/// Override the runtime version of the pipeline.
///
/// EXPERIMENTAL:
///
/// This feature is still in development and may change in future releases.
/// Use for testing purposes only. Note that currently no compatibility
/// guarantees are provided in case the runtime version does not match
/// the deployed platform version.
///
/// EXAMPLES:
///
/// - --runtime-version v0.100.0
/// - --runtime-version 2880dd6fe206d10c966cc23868ee41a3c9e4e543
/// (valid git commit hash of feldera/feldera main branch)
///
/// If not specified, the default version will be used.
#[arg(verbatim_doc_comment, short = 'r', long)]
runtime_version: Option<String>,
},
/// Retrieve the compilation status of the program.
Status {
/// The name of the pipeline.
#[arg(value_hint = ValueHint::Other, add = ArgValueCompleter::new(pipeline_names))]
name: String,
},
}
#[derive(Subcommand)]
pub enum ConnectorAction {
Start,
#[clap(aliases = &["stop"])]
Pause,
#[clap(aliases = &["status"])]
Stats,
}
#[cfg(test)]
mod tests {
use crate::cli::Cli;
use clap::Parser;
/// [clap] will panic inside `try_parse` if it finds anything invalid in the
/// parser definition, such as a duplicated command name, so this test keeps
/// really basic errors from passing through CI.
#[test]
fn basic_validation() {
let _ = Cli::try_parse();
}
}