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 = "top")]
118pub mod top;
119#[allow(unreachable_pub)]
120pub mod topology;
121pub mod trace;
122#[allow(unreachable_pub)]
123pub mod transforms;
124pub mod types;
125pub mod unit_test;
126pub(crate) mod utilization;
127pub mod validate;
128#[cfg(windows)]
129pub mod vector_windows;
130
131pub use source_sender::SourceSender;
132pub use vector_lib::{Error, Result, event, metrics, schema, shutdown, tcp, tls};
133
134static APP_NAME_SLUG: std::sync::OnceLock<String> = std::sync::OnceLock::new();
135static USE_COLOR: std::sync::OnceLock<bool> = 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 set_global_color(enabled: bool) {
157 if let Err(e) = USE_COLOR.set(enabled) {
158 error!(message = "Failed to set global color.", %e);
159 }
160}
161
162pub fn use_color() -> bool {
165 *USE_COLOR.get_or_init(|| false)
166}
167
168pub fn format_vrl_diagnostics(
170 source: &str,
171 diagnostics: impl Into<vrl::diagnostic::DiagnosticList>,
172) -> String {
173 let formatter = vrl::diagnostic::Formatter::new(source, diagnostics);
174 if use_color() {
175 formatter.colored().to_string()
176 } else {
177 formatter.to_string()
178 }
179}
180
181pub fn vector_version() -> impl std::fmt::Display {
184 #[cfg(feature = "nightly")]
185 let pkg_version = format!("{}-nightly", built_info::PKG_VERSION);
186
187 #[cfg(not(feature = "nightly"))]
188 let pkg_version = match built_info::DEBUG {
189 "1" | "2" | "true" => {
191 format!(
192 "{}-custom-{}",
193 built_info::PKG_VERSION,
194 built_info::GIT_SHORT_HASH
195 )
196 }
197 _ => built_info::PKG_VERSION.to_string(),
198 };
199
200 pkg_version
201}
202
203pub fn get_version() -> String {
205 let pkg_version = vector_version();
206 let build_desc = built_info::VECTOR_BUILD_DESC;
207 let build_string = match build_desc {
208 Some(desc) => format!("{} {}", built_info::TARGET, desc),
209 None => built_info::TARGET.into(),
210 };
211
212 let build_string = match built_info::DEBUG {
216 "1" => format!("{build_string} debug=line"),
217 "2" | "true" => format!("{build_string} debug=full"),
218 _ => build_string,
219 };
220
221 format!("{pkg_version} ({build_string})")
222}
223
224#[allow(warnings)]
226pub mod built_info {
227 include!(concat!(env!("OUT_DIR"), "/built.rs"));
228}
229
230pub fn get_hostname() -> std::io::Result<String> {
233 Ok(if let Ok(hostname) = std::env::var("VECTOR_HOSTNAME") {
234 hostname.to_string()
235 } else {
236 hostname::get()?.to_string_lossy().into_owned()
237 })
238}
239
240#[track_caller]
245pub(crate) fn spawn_named<T>(
246 task: impl std::future::Future<Output = T> + Send + 'static,
247 _name: &str,
248) -> tokio::task::JoinHandle<T>
249where
250 T: Send + 'static,
251{
252 #[cfg(tokio_unstable)]
253 return tokio::task::Builder::new()
254 .name(_name)
255 .spawn(task)
256 .expect("tokio task should spawn");
257
258 #[cfg(not(tokio_unstable))]
259 tokio::spawn(task)
260}
261
262pub fn num_threads() -> usize {
264 let count = match std::thread::available_parallelism() {
265 Ok(count) => count,
266 Err(error) => {
267 warn!(message = "Failed to determine available parallelism for thread count, defaulting to 1.", %error);
268 std::num::NonZeroUsize::new(1).unwrap()
269 }
270 };
271 usize::from(count)
272}