agent_data_plane_config/domains/dogstatsd.rs
1//! DogStatsD domain: source listeners, parsing, origin detection, aggregation, mapping, filters
2//! (some dynamic-capable), and debug logging.
3
4use std::collections::HashMap;
5use std::path::PathBuf;
6use std::time::Duration;
7
8use serde::Serialize;
9
10// TODO: better name than Domain? Pipeline? Topology? BlueprintConfig?
11/// Resolved DogStatsD configuration.
12#[derive(Clone, Debug, Default, PartialEq, Serialize)]
13pub struct Domain {
14 /// Source listeners and packet-decoding options.
15 pub listeners: Listeners,
16
17 /// Origin detection and tag cardinality.
18 pub origin: OriginDetection,
19
20 /// Context cache sizing and the sample-rate floor.
21 pub contexts: Contexts,
22
23 /// Metric aggregation window and flush behavior.
24 pub aggregation: Aggregation,
25
26 /// Metric-name mapper.
27 pub mapper: Mapper,
28
29 /// Which payload types are emitted.
30 pub enable_payloads: EnablePayloads,
31
32 /// Metric-name prefix filtering.
33 pub prefix_filter: PrefixFilter,
34
35 /// Per-metric tag include/exclude rules.
36 pub tag_filterlist: Vec<MetricTagFilterEntry>,
37
38 /// Extra tags added to every metric.
39 pub tags: Vec<String>,
40
41 /// Telemetry emitted by the DogStatsD source.
42 pub telemetry: Telemetry,
43
44 /// Debug logging for the DogStatsD source.
45 pub debug_log: DebugLog,
46}
47
48/// Source listeners and packet-decoding options.
49#[derive(Clone, Debug, Default, PartialEq, Serialize)]
50pub struct Listeners {
51 /// UDP port DogStatsD listens on.
52 pub port: u16,
53
54 /// TCP port DogStatsD listens on. (not in Datadog Agent config schema)
55 pub tcp_port: u16,
56
57 /// Path of the Unix datagram socket DogStatsD listens on.
58 pub socket: Option<String>,
59
60 /// Path of the Unix stream socket DogStatsD listens on.
61 pub stream_socket: Option<String>,
62
63 /// Windows named pipe name DogStatsD listens on. Unset when no named pipe is configured.
64 pub pipe_name: Option<String>,
65
66 /// SDDL security descriptor applied to the Windows named pipe listener.
67 pub windows_pipe_security_descriptor: String,
68
69 /// Whether the UDP listener accepts traffic from non-local addresses.
70 pub non_local_traffic: bool,
71
72 /// Host the UDP listener binds to.
73 pub bind_host: Option<String>,
74
75 /// Size, in bytes, requested for the socket receive buffer.
76 pub so_rcvbuf: usize,
77
78 /// Size, in bytes, of each packet receive buffer.
79 pub buffer_size: usize,
80
81 /// Number of receive buffers allocated. (not in Datadog Agent config schema)
82 pub buffer_count: usize,
83
84 /// Maximum number of receive buffers. (not in Datadog Agent config schema)
85 pub buffer_count_max: usize,
86
87 /// Whether to bind multiple UDP sockets via `SO_REUSEPORT`. (not in Datadog Agent config
88 /// schema)
89 pub autoscale_udp_listeners: bool,
90
91 /// Which listener implementation provides packets.
92 pub provider_kind: String,
93
94 /// Path a traffic capture is written to or replayed from.
95 pub capture_path: PathBuf,
96
97 /// Maximum recursion depth when replaying a traffic capture.
98 pub capture_depth: usize,
99
100 /// End-of-line markers required to terminate a stream-socket message.
101 pub eol_required: Vec<String>,
102
103 /// Whether to log stream messages that exceed the buffer size.
104 pub stream_log_too_big: bool,
105
106 /// Whether to relax decoder strictness on malformed packets. (not in Datadog Agent config
107 /// schema)
108 pub permissive_decoding: bool,
109
110 /// Host that received metrics are additionally forwarded to.
111 pub forward_host: Option<String>,
112
113 /// Port that received metrics are additionally forwarded to.
114 pub forward_port: u16,
115}
116
117/// Origin detection and tag cardinality.
118#[derive(Clone, Debug, Default, PartialEq, Serialize)]
119pub struct OriginDetection {
120 /// Whether origin detection tags metrics with their source workload.
121 pub detection: bool,
122
123 /// Whether client-supplied origin information is honored.
124 pub detection_client: bool,
125
126 /// Whether the unified origin-detection scheme is used.
127 pub unified: bool,
128
129 /// Whether a client may opt out of origin detection per metric.
130 pub optout_enabled: bool,
131
132 /// Whether a client-supplied entity ID takes precedence over the detected origin.
133 pub entity_id_precedence: bool,
134
135 /// Tag cardinality applied to origin-detected tags.
136 pub tag_cardinality: OriginTagCardinality,
137}
138
139/// Tag cardinality applied during origin detection.
140#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize)]
141pub enum OriginTagCardinality {
142 #[default]
143 Low,
144 Orchestrator,
145 High,
146 None,
147}
148
149/// Telemetry emitted by the DogStatsD source.
150#[derive(Clone, Debug, Default, PartialEq, Serialize)]
151pub struct Telemetry {
152 /// Whether processed-metric telemetry is broken down by detected origin.
153 pub origin_breakdown: bool,
154}
155
156/// Context cache sizing and sample-rate floor.
157#[derive(Clone, Debug, Default, PartialEq, Serialize)]
158pub struct Contexts {
159 /// Maximum number of metric contexts held in the cache. (not in Datadog Agent config schema)
160 pub cached_contexts_limit: usize,
161
162 /// Maximum number of tagsets held in the cache. (not in Datadog Agent config schema)
163 pub cached_tagsets_limit: usize,
164
165 /// Number of entries the context string interner holds.
166 pub string_interner_size: u64,
167
168 /// Byte budget for the context string interner, overriding the entry count when set. (not in
169 /// Datadog Agent config schema)
170 pub string_interner_size_bytes: Option<u64>,
171
172 /// Whether contexts may be heap-allocated when the interner is full. (not in Datadog Agent
173 /// config schema)
174 pub allow_context_heap_allocs: bool,
175
176 /// Lowest sample rate accepted before a metric is rejected. (not in Datadog Agent config
177 /// schema)
178 pub minimum_sample_rate: f64,
179}
180
181/// Metric aggregation window and flush behavior.
182#[derive(Clone, Debug, PartialEq, Serialize)]
183pub struct Aggregation {
184 /// Length, in seconds, of each aggregation window; must be non-zero. (not in Datadog Agent
185 /// config schema)
186 pub window_duration_seconds: u64,
187
188 /// Maximum number of contexts held per aggregation window. (not in Datadog Agent config schema)
189 pub context_limit: usize,
190
191 /// How often aggregated metrics are flushed. (not in Datadog Agent config schema)
192 pub flush_interval: Duration,
193
194 /// Whether windows that are still open are flushed on shutdown. (not in Datadog Agent config
195 /// schema)
196 pub flush_open_windows: bool,
197
198 /// How long the no-aggregation passthrough waits before flushing while idle. (not in Datadog
199 /// Agent config schema)
200 pub passthrough_idle_flush_timeout: Duration,
201
202 /// How long, in seconds, a counter value is retained after its last update before expiring.
203 pub counter_expiry_seconds: Option<u64>,
204
205 /// How long, in seconds, a context is retained after its last update before expiring.
206 pub context_expiry_seconds: u64,
207
208 /// Whether incomplete aggregation buckets are flushed rather than discarded.
209 pub flush_incomplete_buckets: bool,
210
211 /// Whether metrics bypass aggregation and are forwarded directly.
212 pub no_aggregation_pipeline: bool,
213
214 /// Capacity of the aggregator's tag-filter result cache.
215 pub aggregator_tag_filter_cache_capacity: usize,
216}
217
218impl Default for Aggregation {
219 fn default() -> Self {
220 Self {
221 // Saluki-schema-only knobs: the Datadog Agent schema does not publish these, so they are
222 // seeded only when set; absent that, these defaults stand and must match what the
223 // aggregate transform expects. A zero window, in particular, is invalid downstream.
224 window_duration_seconds: 10,
225 context_limit: 1_000_000,
226 flush_interval: Duration::from_secs(15),
227 passthrough_idle_flush_timeout: Duration::from_secs(1),
228 flush_open_windows: false,
229 // Datadog-schema knobs: always written by the witness driver, so these values are
230 // placeholders that never survive translation.
231 counter_expiry_seconds: None,
232 context_expiry_seconds: 0,
233 flush_incomplete_buckets: false,
234 no_aggregation_pipeline: false,
235 aggregator_tag_filter_cache_capacity: 0,
236 }
237 }
238}
239
240/// DogStatsD metric mapper.
241#[derive(Clone, Debug, Default, PartialEq, Serialize)]
242pub struct Mapper {
243 /// Mapper profiles that rewrite matching metric names and tags.
244 pub profiles: Vec<MapperProfile>,
245
246 /// Number of mapper match results cached.
247 pub cache_size: usize,
248
249 /// Number of entries the mapper's string interner holds. (not in Datadog Agent config schema)
250 pub string_interner_size: u64,
251}
252
253/// One mapper profile: a name, a metric prefix, and the mappings under it.
254#[derive(Clone, Debug, Default, PartialEq, Serialize)]
255pub struct MapperProfile {
256 /// Profile name, for diagnostics.
257 pub name: String,
258
259 /// Metric-name prefix the profile's mappings apply to.
260 pub prefix: String,
261
262 /// The name/tag mappings under this profile.
263 pub mappings: Vec<MetricMapping>,
264}
265
266/// A single metric-name mapping within a [`MapperProfile`].
267#[derive(Clone, Debug, Default, PartialEq, Serialize)]
268pub struct MetricMapping {
269 /// Pattern a metric name must match.
270 pub metric_match: String,
271
272 /// How `metric_match` is interpreted (for example, `wildcard` or `regex`).
273 pub match_type: String,
274
275 /// Replacement name emitted for a matching metric.
276 pub name: String,
277
278 /// Tags added to a matching metric, with values captured from the match.
279 pub tags: HashMap<String, String>,
280}
281
282/// Which payload types are emitted.
283#[derive(Clone, Debug, Default, PartialEq, Serialize)]
284pub struct EnablePayloads {
285 /// Whether event payloads are emitted.
286 pub events: bool,
287
288 /// Whether series (metric) payloads are emitted.
289 pub series: bool,
290
291 /// Whether service-check payloads are emitted.
292 pub service_checks: bool,
293
294 /// Whether sketch (distribution) payloads are emitted.
295 pub sketches: bool,
296}
297
298/// Metric-name prefix filtering (dynamic-capable).
299#[derive(Clone, Debug, Default, PartialEq, Serialize)]
300pub struct PrefixFilter {
301 /// Metric names (or prefixes) that are allowed through; others are dropped.
302 pub metric_filterlist: Vec<String>,
303
304 /// Whether filterlist entries match by prefix rather than exact name.
305 pub metric_filterlist_match_prefix: bool,
306
307 /// Metric names (or prefixes) that are blocked.
308 pub metric_blocklist: Vec<String>,
309
310 /// Whether blocklist entries match by prefix rather than exact name.
311 pub metric_blocklist_match_prefix: bool,
312
313 /// Namespace prepended to every metric name.
314 pub metric_namespace: String,
315
316 /// Namespaces excluded from the metric-namespace prefixing.
317 pub metric_namespace_blocklist: Vec<String>,
318}
319
320/// One tag-filterlist entry (dynamic-capable).
321#[derive(Clone, Debug, Default, PartialEq, Serialize)]
322pub struct MetricTagFilterEntry {
323 /// Metric name the entry applies to.
324 pub metric_name: String,
325
326 /// Whether the listed tags are included or excluded.
327 pub action: FilterAction,
328
329 /// Tags the action applies to.
330 pub tags: Vec<String>,
331}
332
333/// Whether a tag-filterlist entry includes or excludes the listed tags.
334#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize)]
335pub enum FilterAction {
336 Include,
337 #[default]
338 Exclude,
339}
340
341/// DogStatsD debug logging (dynamic-capable).
342#[derive(Clone, Debug, Default, PartialEq, Serialize)]
343pub struct DebugLog {
344 /// Whether DogStatsD debug logging is enabled.
345 pub logging_enabled: bool,
346
347 /// Path of the DogStatsD debug log file.
348 pub log_file: PathBuf,
349
350 /// Number of rotated debug log files retained.
351 pub log_file_max_rolls: usize,
352
353 /// Maximum size, in bytes, a debug log file reaches before it is rotated.
354 pub log_file_max_size: u64,
355
356 /// Whether per-metric processing statistics are collected.
357 pub metrics_stats_enable: bool,
358
359 /// Whether verbose per-packet log lines are suppressed.
360 pub disable_verbose_logs: bool,
361}