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(crate) 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::{event, metrics, schema, tcp, tls};
134pub use vector_lib::{shutdown, Error, Result};
135
136static APP_NAME_SLUG: std::sync::OnceLock<String> = std::sync::OnceLock::new();
137
138pub fn get_app_name() -> &'static str {
143 option_env!("VECTOR_APP_NAME").unwrap_or("Vector")
144}
145
146pub fn get_slugified_app_name() -> String {
150 APP_NAME_SLUG
151 .get_or_init(|| get_app_name().to_lowercase().replace(' ', "-"))
152 .clone()
153}
154
155pub fn vector_version() -> impl std::fmt::Display {
158 #[cfg(feature = "nightly")]
159 let pkg_version = format!("{}-nightly", built_info::PKG_VERSION);
160
161 #[cfg(not(feature = "nightly"))]
162 let pkg_version = match built_info::DEBUG {
163 "1" | "2" | "true" => {
165 format!(
166 "{}-custom-{}",
167 built_info::PKG_VERSION,
168 built_info::GIT_SHORT_HASH
169 )
170 }
171 _ => built_info::PKG_VERSION.to_string(),
172 };
173
174 pkg_version
175}
176
177pub fn get_version() -> String {
179 let pkg_version = vector_version();
180 let build_desc = built_info::VECTOR_BUILD_DESC;
181 let build_string = match build_desc {
182 Some(desc) => format!("{} {}", built_info::TARGET, desc),
183 None => built_info::TARGET.into(),
184 };
185
186 let build_string = match built_info::DEBUG {
190 "1" => format!("{build_string} debug=line"),
191 "2" | "true" => format!("{build_string} debug=full"),
192 _ => build_string,
193 };
194
195 format!("{pkg_version} ({build_string})")
196}
197
198#[allow(warnings)]
200pub mod built_info {
201 include!(concat!(env!("OUT_DIR"), "/built.rs"));
202}
203
204pub fn get_hostname() -> std::io::Result<String> {
207 Ok(if let Ok(hostname) = std::env::var("VECTOR_HOSTNAME") {
208 hostname.to_string()
209 } else {
210 hostname::get()?.to_string_lossy().into_owned()
211 })
212}
213
214#[track_caller]
219pub(crate) fn spawn_named<T>(
220 task: impl std::future::Future<Output = T> + Send + 'static,
221 _name: &str,
222) -> tokio::task::JoinHandle<T>
223where
224 T: Send + 'static,
225{
226 #[cfg(tokio_unstable)]
227 return tokio::task::Builder::new()
228 .name(_name)
229 .spawn(task)
230 .expect("tokio task should spawn");
231
232 #[cfg(not(tokio_unstable))]
233 tokio::spawn(task)
234}
235
236pub fn num_threads() -> usize {
238 let count = match std::thread::available_parallelism() {
239 Ok(count) => count,
240 Err(error) => {
241 warn!(message = "Failed to determine available parallelism for thread count, defaulting to 1.", %error);
242 std::num::NonZeroUsize::new(1).unwrap()
243 }
244 };
245 usize::from(count)
246}