vector/sources/util/
mod.rs

1#![allow(missing_docs)]
2#[cfg(feature = "sources-http_server")]
3mod body_decoding;
4#[cfg(feature = "sources-file")]
5mod encoding_config;
6#[cfg(all(unix, feature = "sources-dnstap"))]
7pub mod framestream;
8#[cfg(any(feature = "sources-vector", feature = "sources-opentelemetry"))]
9pub mod grpc;
10#[cfg(any(
11    feature = "sources-utils-http-auth",
12    feature = "sources-utils-http-encoding",
13    feature = "sources-utils-http-headers",
14    feature = "sources-utils-http-prelude",
15    feature = "sources-utils-http-query"
16))]
17pub mod http;
18#[cfg(any(
19    feature = "sources-http_client",
20    feature = "sources-prometheus-scrape",
21    feature = "sources-okta"
22))]
23pub mod http_client;
24#[cfg(any(
25    feature = "sources-aws_sqs",
26    feature = "sources-gcp_pubsub",
27    feature = "sources-mqtt"
28))]
29mod message_decoding;
30pub mod multiline_config;
31#[cfg(any(feature = "sources-utils-net-tcp", feature = "sources-utils-net-udp"))]
32pub mod net;
33#[cfg(all(
34    unix,
35    any(feature = "sources-socket", feature = "sources-utils-net-unix",)
36))]
37pub mod unix;
38#[cfg(all(unix, feature = "sources-socket"))]
39mod unix_datagram;
40#[cfg(all(unix, feature = "sources-utils-net-unix"))]
41mod unix_stream;
42mod wrappers;
43
44#[cfg(feature = "sources-file")]
45pub use encoding_config::EncodingConfig;
46pub use multiline_config::MultilineConfig;
47#[cfg(all(
48    unix,
49    any(feature = "sources-socket", feature = "sources-utils-net-unix",)
50))]
51pub use unix::change_socket_permissions;
52#[cfg(all(unix, feature = "sources-socket",))]
53pub use unix_datagram::build_unix_datagram_source;
54#[cfg(all(unix, feature = "sources-utils-net-unix",))]
55pub use unix_stream::build_unix_stream_source;
56pub use wrappers::{AfterRead, AfterReadExt};
57
58#[cfg(feature = "sources-http_server")]
59pub use self::body_decoding::Encoding;
60#[cfg(feature = "sources-utils-http-prelude")]
61pub use self::http::HttpSource;
62#[cfg(feature = "sources-utils-http-headers")]
63pub use self::http::add_headers;
64#[cfg(feature = "sources-utils-http-query")]
65pub use self::http::add_query_parameters;
66#[cfg(any(
67    feature = "sources-prometheus-scrape",
68    feature = "sources-prometheus-remote-write",
69    feature = "sources-utils-http-encoding"
70))]
71pub use self::http::decompress_body;
72#[cfg(any(
73    feature = "sources-aws_sqs",
74    feature = "sources-gcp_pubsub",
75    feature = "sources-mqtt"
76))]
77pub use self::message_decoding::decode_message;
78
79/// Extract a tag and it's value from input string delimited by a colon character.
80///
81/// Note: the behavior of StatsD if more than one colon is found (which would presumably
82/// be part of the tag value), is to remove any additional colons from the tag value.
83/// Thus Vector expects only one colon character to be present per chunk, so the find()
84/// operation locating the first position is sufficient.
85#[cfg(any(feature = "sources-statsd", feature = "sources-datadog_agent"))]
86pub fn extract_tag_key_and_value<S: AsRef<str>>(
87    tag_chunk: S,
88) -> (String, vector_lib::event::metric::TagValue) {
89    use vector_lib::event::metric::TagValue;
90
91    let tag_chunk = tag_chunk.as_ref();
92
93    // tag_chunk is expected to be formatted as "tag_name:tag_value"
94    // If no colon is found, then it is classified as a Bare tag.
95    match tag_chunk.split_once(':') {
96        // the notation `tag:` is valid for StatsD. The effect is an empty string value.
97        Some((prefix, suffix)) => (prefix.to_string(), TagValue::Value(suffix.to_string())),
98        None => (tag_chunk.to_string(), TagValue::Bare),
99    }
100}