Skip to main content

vector/sources/util/
mod.rs

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