vector/sources/util/
mod.rs

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