vector/sinks/blackhole/
config.rs

1use std::time::Duration;
2
3use futures::{future, FutureExt};
4use serde_with::serde_as;
5use vector_lib::configurable::configurable_component;
6
7use crate::{
8    config::{AcknowledgementsConfig, GenerateConfig, Input, SinkConfig, SinkContext},
9    sinks::{blackhole::sink::BlackholeSink, Healthcheck, VectorSink},
10};
11
12const fn default_print_interval_secs() -> Duration {
13    Duration::from_secs(0)
14}
15
16/// Configuration for the `blackhole` sink.
17#[serde_as]
18#[configurable_component(sink(
19    "blackhole",
20    "Send observability events nowhere, which can be useful for debugging purposes."
21))]
22#[derive(Clone, Debug, Derivative)]
23#[serde(deny_unknown_fields, default)]
24#[derivative(Default)]
25pub struct BlackholeConfig {
26    /// The interval between reporting a summary of activity.
27    ///
28    /// Set to `0` (default) to disable reporting.
29    #[derivative(Default(value = "default_print_interval_secs()"))]
30    #[serde(default = "default_print_interval_secs")]
31    #[serde_as(as = "serde_with::DurationSeconds<u64>")]
32    #[configurable(metadata(docs::human_name = "Print Interval"))]
33    #[configurable(metadata(docs::examples = 10))]
34    pub print_interval_secs: Duration,
35
36    /// The number of events, per second, that the sink is allowed to consume.
37    ///
38    /// By default, there is no limit.
39    #[configurable(metadata(docs::examples = 1000))]
40    pub rate: Option<usize>,
41
42    #[configurable(derived)]
43    #[serde(
44        default,
45        deserialize_with = "crate::serde::bool_or_struct",
46        skip_serializing_if = "crate::serde::is_default"
47    )]
48    pub acknowledgements: AcknowledgementsConfig,
49}
50
51#[async_trait::async_trait]
52#[typetag::serde(name = "blackhole")]
53impl SinkConfig for BlackholeConfig {
54    async fn build(&self, _cx: SinkContext) -> crate::Result<(VectorSink, Healthcheck)> {
55        let sink = BlackholeSink::new(self.clone());
56        let healthcheck = future::ok(()).boxed();
57
58        Ok((VectorSink::Stream(Box::new(sink)), healthcheck))
59    }
60
61    fn input(&self) -> Input {
62        Input::all()
63    }
64
65    fn acknowledgements(&self) -> &AcknowledgementsConfig {
66        &self.acknowledgements
67    }
68}
69
70impl GenerateConfig for BlackholeConfig {
71    fn generate_config() -> toml::Value {
72        toml::Value::try_from(Self::default()).unwrap()
73    }
74}
75
76#[cfg(test)]
77mod tests {
78    use crate::sinks::blackhole::config::BlackholeConfig;
79
80    #[test]
81    fn generate_config() {
82        crate::test_util::test_generate_config::<BlackholeConfig>();
83    }
84}