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