vector/tap/
mod.rs

1//! Tap subcommand
2mod cmd;
3
4use clap::Parser;
5pub(crate) use cmd::cmd;
6pub use cmd::tap;
7use url::Url;
8use vector_lib::api_client::gql::TapEncodingFormat;
9
10use crate::config::api::default_graphql_url;
11
12/// Tap options
13#[derive(Parser, Debug, Clone)]
14#[command(rename_all = "kebab-case")]
15pub struct Opts {
16    /// Interval to sample events at, in milliseconds
17    #[arg(default_value = "500", short = 'i', long)]
18    interval: u32,
19
20    /// GraphQL API server endpoint
21    #[arg(short, long)]
22    url: Option<Url>,
23
24    /// Maximum number of events to sample each interval
25    #[arg(default_value = "100", short = 'l', long)]
26    limit: u32,
27
28    /// Encoding format for events printed to screen
29    #[arg(default_value = "json", short = 'f', long)]
30    format: TapEncodingFormat,
31
32    /// Components IDs to observe (comma-separated; accepts glob patterns)
33    #[arg(value_delimiter(','))]
34    component_id_patterns: Vec<String>,
35
36    /// Components (sources, transforms) IDs whose outputs to observe (comma-separated; accepts glob patterns)
37    #[arg(value_delimiter(','), long)]
38    outputs_of: Vec<String>,
39
40    /// Components (transforms, sinks) IDs whose inputs to observe (comma-separated; accepts glob patterns)
41    #[arg(value_delimiter(','), long)]
42    inputs_of: Vec<String>,
43
44    /// Quiet output includes only events
45    #[arg(short, long)]
46    quiet: bool,
47
48    /// Include metadata such as the event's associated component ID
49    #[arg(short, long)]
50    meta: bool,
51
52    /// Whether to reconnect if the underlying API connection drops. By default, tap will attempt to reconnect if the connection drops.
53    #[arg(short, long)]
54    no_reconnect: bool,
55
56    /// Specifies a duration (in milliseconds) to sample logs (e.g. specifying 10000 will sample logs for 10 seconds then exit)
57    #[arg(short = 'd', long)]
58    duration_ms: Option<u64>,
59}
60
61impl Opts {
62    /// Component ID patterns to tap
63    ///
64    /// If no patterns are provided, tap all components' outputs
65    pub fn outputs_patterns(&self) -> Vec<String> {
66        if self.component_id_patterns.is_empty()
67            && self.outputs_of.is_empty()
68            && self.inputs_of.is_empty()
69        {
70            vec!["*".to_string()]
71        } else {
72            self.outputs_of
73                .iter()
74                .cloned()
75                .chain(self.component_id_patterns.iter().cloned())
76                .collect()
77        }
78    }
79
80    /// Use the provided URL as the Vector GraphQL API server, or default to the local port
81    /// provided by the API config.
82    pub fn url(&self) -> Url {
83        self.url.clone().unwrap_or_else(default_graphql_url)
84    }
85
86    /// URL with scheme set to WebSockets
87    pub fn web_socket_url(&self) -> Url {
88        let mut url = self.url();
89        url.set_scheme(match url.scheme() {
90            "https" => "wss",
91            _ => "ws",
92        })
93        .expect("Couldn't build WebSocket URL. Please report.");
94
95        url
96    }
97}