1#![recursion_limit = "256"] #![deny(unreachable_pub)]
3#![deny(unused_extern_crates)]
4#![deny(unused_allocation)]
5#![deny(unused_assignments)]
6#![deny(unused_comparisons)]
7#![deny(warnings)]
8#![deny(missing_docs)]
9#![cfg_attr(docsrs, feature(doc_cfg), deny(rustdoc::broken_intra_doc_links))]
10#![allow(async_fn_in_trait)]
11#![allow(clippy::approx_constant)]
12#![allow(clippy::float_cmp)]
13#![allow(clippy::match_wild_err_arm)]
14#![allow(clippy::new_ret_no_self)]
15#![allow(clippy::type_complexity)]
16#![allow(clippy::unit_arg)]
17#![deny(clippy::clone_on_ref_ptr)]
18#![deny(clippy::trivially_copy_pass_by_ref)]
19#![deny(clippy::disallowed_methods)] #![deny(clippy::missing_const_for_fn)] #[cfg(all(unix, feature = "sinks-socket"))]
25#[macro_use]
26extern crate cfg_if;
27#[macro_use]
28extern crate derivative;
29#[macro_use]
30extern crate tracing;
31#[macro_use]
32extern crate vector_lib;
33
34pub use indoc::indoc;
35
36#[cfg(all(feature = "tikv-jemallocator", not(feature = "allocation-tracing")))]
37#[global_allocator]
38static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
39
40#[cfg(all(feature = "tikv-jemallocator", feature = "allocation-tracing"))]
41#[global_allocator]
42static ALLOC: self::internal_telemetry::allocations::Allocator<tikv_jemallocator::Jemalloc> =
43 self::internal_telemetry::allocations::get_grouped_tracing_allocator(
44 tikv_jemallocator::Jemalloc,
45 );
46
47#[allow(unreachable_pub)]
48pub mod internal_telemetry;
49
50#[macro_use]
51#[allow(unreachable_pub)]
52pub mod config;
53pub mod cli;
54#[allow(unreachable_pub)]
55pub mod components;
56pub mod conditions;
57pub mod dns;
58#[cfg(feature = "docker")]
59pub mod docker;
60pub mod expiring_hash_map;
61pub mod generate;
62pub mod generate_schema;
63#[macro_use]
64#[allow(unreachable_pub)]
65pub mod internal_events;
66#[cfg(feature = "lapin")]
67pub mod amqp;
68#[cfg(feature = "api")]
69#[allow(unreachable_pub)]
70pub mod api;
71pub mod app;
72pub mod async_read;
73#[cfg(feature = "aws-config")]
74pub mod aws;
75#[allow(unreachable_pub)]
76pub mod codecs;
77pub mod common;
78mod convert_config;
79pub mod encoding_transcode;
80pub mod enrichment_tables;
81pub mod extra_context;
82#[cfg(feature = "gcp")]
83pub mod gcp;
84pub(crate) mod graph;
85pub mod heartbeat;
86pub mod http;
87#[allow(unreachable_pub)]
88#[cfg(any(feature = "sources-kafka", feature = "sinks-kafka"))]
89pub mod kafka;
90#[allow(unreachable_pub)]
91pub mod kubernetes;
92pub mod line_agg;
93pub mod list;
94#[cfg(any(feature = "sources-nats", feature = "sinks-nats"))]
95pub mod nats;
96pub mod net;
97#[allow(unreachable_pub)]
98pub(crate) mod proto;
99pub mod providers;
100pub mod secrets;
101pub mod serde;
102#[cfg(windows)]
103pub mod service;
104pub mod signal;
105pub(crate) mod sink_ext;
106#[allow(unreachable_pub)]
107pub mod sinks;
108pub mod source_sender;
109#[allow(unreachable_pub)]
110pub mod sources;
111pub mod stats;
112#[cfg(feature = "api-client")]
113#[allow(unreachable_pub)]
114pub mod tap;
115pub mod template;
116pub mod test_util;
117#[cfg(feature = "api-client")]
118#[allow(unreachable_pub)]
119pub mod top;
120#[allow(unreachable_pub)]
121pub mod topology;
122pub mod trace;
123#[allow(unreachable_pub)]
124pub mod transforms;
125pub mod types;
126pub mod unit_test;
127pub(crate) mod utilization;
128pub mod validate;
129#[cfg(windows)]
130pub mod vector_windows;
131
132pub use source_sender::SourceSender;
133pub use vector_lib::{Error, Result, event, metrics, schema, shutdown, tcp, tls};
134
135static APP_NAME_SLUG: std::sync::OnceLock<String> = std::sync::OnceLock::new();
136
137pub fn get_app_name() -> &'static str {
142 option_env!("VECTOR_APP_NAME").unwrap_or("Vector")
143}
144
145pub fn get_slugified_app_name() -> String {
149 APP_NAME_SLUG
150 .get_or_init(|| get_app_name().to_lowercase().replace(' ', "-"))
151 .clone()
152}
153
154pub fn vector_version() -> impl std::fmt::Display {
157 #[cfg(feature = "nightly")]
158 let pkg_version = format!("{}-nightly", built_info::PKG_VERSION);
159
160 #[cfg(not(feature = "nightly"))]
161 let pkg_version = match built_info::DEBUG {
162 "1" | "2" | "true" => {
164 format!(
165 "{}-custom-{}",
166 built_info::PKG_VERSION,
167 built_info::GIT_SHORT_HASH
168 )
169 }
170 _ => built_info::PKG_VERSION.to_string(),
171 };
172
173 pkg_version
174}
175
176pub fn get_version() -> String {
178 let pkg_version = vector_version();
179 let build_desc = built_info::VECTOR_BUILD_DESC;
180 let build_string = match build_desc {
181 Some(desc) => format!("{} {}", built_info::TARGET, desc),
182 None => built_info::TARGET.into(),
183 };
184
185 let build_string = match built_info::DEBUG {
189 "1" => format!("{build_string} debug=line"),
190 "2" | "true" => format!("{build_string} debug=full"),
191 _ => build_string,
192 };
193
194 format!("{pkg_version} ({build_string})")
195}
196
197#[allow(warnings)]
199pub mod built_info {
200 include!(concat!(env!("OUT_DIR"), "/built.rs"));
201}
202
203pub fn get_hostname() -> std::io::Result<String> {
206 Ok(if let Ok(hostname) = std::env::var("VECTOR_HOSTNAME") {
207 hostname.to_string()
208 } else {
209 hostname::get()?.to_string_lossy().into_owned()
210 })
211}
212
213#[track_caller]
218pub(crate) fn spawn_named<T>(
219 task: impl std::future::Future<Output = T> + Send + 'static,
220 _name: &str,
221) -> tokio::task::JoinHandle<T>
222where
223 T: Send + 'static,
224{
225 #[cfg(tokio_unstable)]
226 return tokio::task::Builder::new()
227 .name(_name)
228 .spawn(task)
229 .expect("tokio task should spawn");
230
231 #[cfg(not(tokio_unstable))]
232 tokio::spawn(task)
233}
234
235pub fn num_threads() -> usize {
237 let count = match std::thread::available_parallelism() {
238 Ok(count) => count,
239 Err(error) => {
240 warn!(message = "Failed to determine available parallelism for thread count, defaulting to 1.", %error);
241 std::num::NonZeroUsize::new(1).unwrap()
242 }
243 };
244 usize::from(count)
245}