agent_data_plane_config/domains/otlp.rs
1//! OTLP domain: the OTLP receiver (gRPC/HTTP transports, logs/metrics activation), the OTLP proxy
2//! gating, and OTLP context sizing. OTLP trace handling lives in the `traces` domain.
3
4use std::collections::HashMap;
5use std::time::Duration;
6use std::{num::NonZeroUsize, str::FromStr};
7
8use serde::{Deserialize, Serialize};
9
10use crate::defaults::DEFAULT_STRING_INTERNER_SIZE_BYTES;
11use crate::{domains::dogstatsd::OriginTagCardinality, Error};
12
13/// Resolved OTLP configuration.
14#[derive(Clone, Debug, Default, PartialEq, Serialize)]
15pub struct Domain {
16 /// OTLP receiver transports and per-signal activation.
17 pub receiver: Receiver,
18
19 /// OTLP metrics translation settings.
20 pub metrics: Metrics,
21
22 /// OTLP trace ingestion settings.
23 pub traces: Traces,
24
25 /// OTLP proxy gating and endpoint.
26 pub proxy: Proxy,
27
28 /// OTLP context cache sizing.
29 pub contexts: Contexts,
30
31 /// Debug logging of the OTLP data ADP receives.
32 pub debug: DebugOutput,
33}
34
35/// Debug logging of received OTLP data.
36#[derive(Clone, Debug, Default, PartialEq, Serialize)]
37pub struct DebugOutput {
38 /// How much detail is logged for each received export request.
39 ///
40 /// Stays [`DebugVerbosity::None`] unless `otlp_config.debug.verbosity` is configured explicitly. A schema default
41 /// of `basic` doesn't turn the output on.
42 pub verbosity: DebugVerbosity,
43}
44
45/// How much detail is logged for each received OTLP export request.
46#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize)]
47pub enum DebugVerbosity {
48 /// Log nothing.
49 #[default]
50 None,
51
52 /// Log one summary line per request, with the number of items received.
53 Basic,
54
55 /// Log the summary line, then about one line for each item received.
56 Normal,
57
58 /// Log the summary line, then every field of every item received.
59 Detailed,
60}
61
62impl FromStr for DebugVerbosity {
63 type Err = Error;
64
65 /// Parses a verbosity, ignoring case, so `Basic` and `DETAILED` are accepted as well as `basic` and `detailed`.
66 fn from_str(value: &str) -> Result<Self, Self::Err> {
67 match value.to_ascii_lowercase().as_str() {
68 "none" => Ok(Self::None),
69 "basic" => Ok(Self::Basic),
70 "normal" => Ok(Self::Normal),
71 "detailed" => Ok(Self::Detailed),
72 _ => Err(Error::new_without_source(format!(
73 "unknown debug verbosity `{value}`; expected `none`, `basic`, `normal`, or `detailed`"
74 ))),
75 }
76 }
77}
78
79/// Default TTL for cached prior points used when converting cumulative sums to deltas.
80pub const DEFAULT_DELTA_TTL: Duration = Duration::from_secs(3600);
81
82/// OTLP metrics translation settings.
83#[derive(Clone, Debug, PartialEq, Serialize)]
84pub struct Metrics {
85 /// Tag cardinality applied to entity and global tags enriched onto OTLP metrics.
86 ///
87 /// Defaults to `low`. Set this to `orchestrator` or `high` when the additional series cardinality is acceptable.
88 /// `none` disables entity and global tag enrichment.
89 pub tag_cardinality: OriginTagCardinality,
90
91 /// How explicit histogram buckets are reported.
92 pub histogram_mode: HistogramMode,
93
94 /// Whether histogram count, sum, minimum, and maximum metrics are emitted when available.
95 ///
96 /// The `nobuckets` mode requires this setting. Defaults to `false`.
97 pub send_histogram_aggregations: bool,
98
99 /// Whether every resource attribute is added as a raw metric tag, in addition to the
100 /// semantic-convention mappings that are always applied.
101 pub resource_attributes_as_tags: bool,
102
103 /// Whether instrumentation scope name, version, and attributes are added as metric tags.
104 ///
105 /// Defaults to `true`. When `false`, no scope tags are emitted (no `n/a` placeholders).
106 /// Disable this in high-cardinality scope environments where per-scope tag overhead outweighs queryability.
107 pub instrumentation_scope_metadata_as_tags: bool,
108
109 /// OTLP sum translation settings.
110 pub sums: Sums,
111
112 /// Comma-separated list of tags to add to every emitted metric.
113 ///
114 /// Defaults to empty. When the static-tag resolver produces no tags, this value is preserved.
115 /// When it produces one or more tags, those tags replace this value; the two sets are not merged.
116 pub tags: String,
117
118 /// OTLP summary translation settings.
119 pub summaries: Summaries,
120
121 /// Time-to-live for cached prior data points used when converting cumulative monotonic sums
122 /// to deltas. Defaults to `3600` seconds. Must be greater than zero.
123 pub delta_ttl: Duration,
124}
125
126impl Default for Metrics {
127 fn default() -> Self {
128 Self {
129 tag_cardinality: OriginTagCardinality::default(),
130 histogram_mode: HistogramMode::default(),
131 send_histogram_aggregations: false,
132 resource_attributes_as_tags: false,
133 instrumentation_scope_metadata_as_tags: true,
134 sums: Sums::default(),
135 tags: String::new(),
136 summaries: Summaries::default(),
137 delta_ttl: DEFAULT_DELTA_TTL,
138 }
139 }
140}
141
142/// How explicit OTLP histogram buckets are reported.
143#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize)]
144pub enum HistogramMode {
145 /// Omit bucket metrics.
146 NoBuckets,
147
148 /// Report each bucket as a counter.
149 Counters,
150
151 /// Report buckets as distributions.
152 #[default]
153 Distributions,
154}
155
156impl FromStr for HistogramMode {
157 type Err = Error;
158
159 fn from_str(value: &str) -> Result<Self, Self::Err> {
160 match value {
161 "nobuckets" => Ok(Self::NoBuckets),
162 "counters" => Ok(Self::Counters),
163 "distributions" => Ok(Self::Distributions),
164 other => Err(Error::new_without_source(format!(
165 "unknown histogram mode `{other}`; expected `nobuckets`, `counters`, or `distributions`"
166 ))),
167 }
168 }
169}
170
171/// How cumulative monotonic sums are reported.
172#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize)]
173pub enum CumulativeMonotonicMode {
174 /// Converts cumulative values to deltas and reports them as counts.
175 #[default]
176 ToDelta,
177
178 /// Reports cumulative values as gauges without converting them to deltas.
179 RawValue,
180}
181
182impl FromStr for CumulativeMonotonicMode {
183 type Err = Error;
184
185 fn from_str(value: &str) -> Result<Self, Self::Err> {
186 match value {
187 "to_delta" => Ok(Self::ToDelta),
188 "raw_value" => Ok(Self::RawValue),
189 other => Err(Error::new_without_source(format!(
190 "unknown cumulative monotonic sum mode `{other}`; expected `to_delta` or `raw_value`"
191 ))),
192 }
193 }
194}
195
196/// Controls how the first value of a cumulative monotonic sum is reported.
197#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize)]
198pub enum InitialCumulativeMonotonicValue {
199 /// Reports the first value when its series started after the translator process.
200 #[default]
201 Auto,
202
203 /// Always drops the first value.
204 Drop,
205
206 /// Always reports the first value.
207 Keep,
208}
209
210impl FromStr for InitialCumulativeMonotonicValue {
211 type Err = Error;
212
213 fn from_str(value: &str) -> Result<Self, Self::Err> {
214 match value {
215 "auto" => Ok(Self::Auto),
216 "drop" => Ok(Self::Drop),
217 "keep" => Ok(Self::Keep),
218 other => Err(Error::new_without_source(format!(
219 "unknown initial cumulative monotonic value `{other}`; expected `auto`, `drop`, or `keep`"
220 ))),
221 }
222 }
223}
224
225/// OTLP sum translation settings.
226#[derive(Clone, Debug, Default, PartialEq, Serialize)]
227pub struct Sums {
228 /// Cumulative monotonic sum reporting mode.
229 ///
230 /// Defaults to `to_delta`, which converts cumulative values to delta counts. Set to `raw_value` to emit
231 /// cumulative values as gauges.
232 pub cumulative_monotonic_mode: CumulativeMonotonicMode,
233
234 /// Initial cumulative monotonic sum reporting behavior.
235 ///
236 /// Defaults to `auto`, which reports the value only when its series started after the translator process.
237 /// Set this to `drop` to always discard the first value or `keep` to always report it.
238 pub initial_cumulative_monotonic_value: InitialCumulativeMonotonicValue,
239}
240
241/// OTLP summary translation settings.
242#[derive(Clone, Debug, Default, PartialEq, Serialize)]
243pub struct Summaries {
244 /// How summary quantiles are reported.
245 ///
246 /// Defaults to `gauges`, which emits one gauge metric per quantile. Set to `noquantiles` to omit quantile
247 /// metrics.
248 pub mode: SummaryMode,
249}
250
251/// How OTLP summary quantiles are reported.
252#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize)]
253pub enum SummaryMode {
254 /// Report one gauge metric per quantile.
255 #[default]
256 Gauges,
257
258 /// Omit quantile metrics.
259 NoQuantiles,
260}
261
262impl FromStr for SummaryMode {
263 type Err = Error;
264
265 fn from_str(value: &str) -> Result<Self, Self::Err> {
266 match value {
267 "gauges" => Ok(Self::Gauges),
268 "noquantiles" => Ok(Self::NoQuantiles),
269 other => Err(Error::new_without_source(format!(
270 "unknown summary mode `{other}`; expected `gauges` or `noquantiles`"
271 ))),
272 }
273 }
274}
275
276/// Transport accepted by the OTLP gRPC receiver.
277#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize)]
278#[serde(rename_all = "lowercase")]
279pub enum GrpcTransport {
280 /// TCP transport.
281 #[default]
282 Tcp,
283 /// Unix stream socket transport.
284 Unix,
285}
286
287impl GrpcTransport {
288 /// Returns the configuration spelling of this transport.
289 pub const fn as_str(self) -> &'static str {
290 match self {
291 Self::Tcp => "tcp",
292 Self::Unix => "unix",
293 }
294 }
295}
296
297impl FromStr for GrpcTransport {
298 type Err = Error;
299
300 fn from_str(value: &str) -> Result<Self, Self::Err> {
301 match value {
302 "tcp" => Ok(Self::Tcp),
303 "unix" => Ok(Self::Unix),
304 other => Err(Error::new_without_source(format!(
305 "unknown gRPC transport `{other}`; expected `tcp` or `unix`"
306 ))),
307 }
308 }
309}
310
311/// OTLP receiver transports and per-signal activation.
312#[derive(Clone, Debug, Default, PartialEq, Serialize)]
313pub struct Receiver {
314 /// Whether the receiver accepts OTLP logs.
315 pub logs_enabled: bool,
316
317 /// Whether the receiver accepts OTLP metrics.
318 pub metrics_enabled: bool,
319
320 /// gRPC receiver settings.
321 pub grpc: GrpcReceiver,
322
323 /// HTTP receiver settings.
324 pub http: HttpReceiver,
325}
326
327/// Default gRPC maximum inbound message size, in MiB.
328///
329/// The Datadog schema default for `max_recv_msg_size_mib` is `0`, which grpc-go treats as "apply the
330/// built-in 4 MiB limit." Translation substitutes this constant for a configured `0` so the model
331/// always carries an effective limit.
332pub const DEFAULT_GRPC_MAX_RECV_MSG_SIZE_MIB: u64 = 4;
333
334/// Default gRPC keepalive ping interval: idle time before the server sends a PING to check the
335/// connection is still alive.
336pub const DEFAULT_GRPC_KEEPALIVE_TIME: Duration = Duration::from_secs(2 * 60 * 60);
337
338/// Default gRPC keepalive ping timeout: time to wait for a PONG before closing the connection.
339pub const DEFAULT_GRPC_KEEPALIVE_TIMEOUT: Duration = Duration::from_secs(20);
340
341/// Server-side keepalive parameters for the OTLP gRPC receiver.
342///
343/// All fields are `Duration`. A zero duration is the sentinel for "unset": the translator
344/// resolves `time` and `timeout` to their effective defaults, and treats `max_connection_age` and
345/// `max_connection_age_grace` as "no limit."
346#[derive(Clone, Debug, Default, PartialEq, Serialize)]
347pub struct KeepaliveServerParameters {
348 /// Maximum time a connection may exist before the server sends GOAWAY. A zero duration means no
349 /// limit. Lower this to force periodic connection rotation in long-lived deployments.
350 pub max_connection_age: Duration,
351
352 /// Grace period after `max_connection_age` before the connection is forcibly closed. A zero
353 /// duration means no limit. Increase this to give in-flight RPCs more time to finish during
354 /// age-based shutdown.
355 pub max_connection_age_grace: Duration,
356
357 /// Idle time before the server sends a keepalive PING. A zero duration is resolved by the
358 /// translator to the default of 2 hours. Lower this to detect dead connections faster at the
359 /// cost of more frequent PING traffic.
360 pub time: Duration,
361
362 /// Time to wait for a PONG after a keepalive PING before closing the connection. A zero duration
363 /// is resolved by the translator to the default of 20 seconds. Increase this on networks with
364 /// high latency or intermittent delays.
365 pub timeout: Duration,
366}
367
368/// TLS settings for an OTLP receiver (gRPC or HTTP).
369///
370/// These configure server-side TLS for the receiver. When `cert_file` and `key_file` are both set, the receiver
371/// accepts encrypted connections. When `ca_file` is also set, the server requests client certificates and verifies
372/// them if presented, but does not require them (optional verification).
373#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
374pub struct Tls {
375 /// Path to the PEM-encoded certificate chain file.
376 ///
377 /// When set together with `key_file`, enables TLS on the receiver. Defaults to empty (TLS disabled).
378 pub cert_file: String,
379
380 /// Path to the PEM-encoded private key file.
381 ///
382 /// The private key must correspond to the leaf certificate in `cert_file`. Defaults to empty (TLS disabled).
383 pub key_file: String,
384
385 /// Path to the PEM-encoded CA certificate file for verifying client certificates.
386 ///
387 /// When set, the server requests client certificates and verifies them against the CA certificates in this file.
388 /// Clients that present a certificate must provide a valid one; clients that present no certificate are still
389 /// accepted. Defaults to empty (no client certificate verification).
390 pub ca_file: String,
391}
392
393/// OTLP gRPC receiver.
394#[derive(Clone, Debug, Default, PartialEq, Serialize)]
395pub struct GrpcReceiver {
396 /// Address the gRPC receiver listens on.
397 pub endpoint: String,
398
399 /// Maximum inbound message size, in MiB.
400 pub max_recv_msg_size_mib: u64,
401
402 /// Transport the gRPC receiver binds. Defaults to `tcp`.
403 pub transport: GrpcTransport,
404
405 /// HTTP/2 maximum concurrent streams per connection.
406 ///
407 /// Defaults to `0`, which means no limit (the server applies no cap). A positive value sets
408 /// the `SETTINGS_MAX_CONCURRENT_STREAMS` HTTP/2 setting.
409 pub max_concurrent_streams: u32,
410
411 /// Server-side keepalive parameters. Always present; zero durations are resolved to the
412 /// grpc-go defaults (2 h interval, 20 s timeout) by the translator.
413 pub keepalive: KeepaliveServerParameters,
414
415 /// TLS settings for the gRPC receiver.
416 pub tls: Tls,
417
418 /// Whether an input explicitly set any `tls` value of the gRPC receiver. (not in Datadog Agent config
419 /// schema)
420 ///
421 /// The translator derives this from the merged sources, not from the typed TLS fields. Those fields omit
422 /// some `tls` keys, and they can't tell an explicit empty value from the default.
423 pub tls_configured: bool,
424}
425
426/// OTLP HTTP receiver.
427#[derive(Clone, Debug, PartialEq, Serialize)]
428pub struct HttpReceiver {
429 /// Address the HTTP receiver listens on.
430 pub endpoint: String,
431
432 /// Transport the HTTP receiver binds (for example, `tcp` or `unix`). (not in Datadog Agent
433 /// config schema)
434 pub transport: String,
435
436 /// CORS configuration for the HTTP receiver.
437 pub cors: Cors,
438
439 /// TLS settings for the HTTP receiver.
440 pub tls: Tls,
441
442 /// Whether an input explicitly set any `tls` value of the HTTP receiver. (not in Datadog Agent config
443 /// schema)
444 ///
445 /// The translator derives this from the merged sources, not from the typed TLS fields. Those fields omit
446 /// some `tls` keys, and they can't tell an explicit empty value from the default.
447 pub tls_configured: bool,
448
449 /// Maximum HTTP request body size, in bytes.
450 ///
451 /// Defaults to `0`, which applies the 20 MiB limit used by the Datadog Agent. A positive value
452 /// sets the limit in bytes.
453 pub max_request_body_size: u64,
454}
455
456impl Default for HttpReceiver {
457 fn default() -> Self {
458 Self {
459 // Witnessed; overwritten during drive.
460 endpoint: String::new(),
461 transport: "tcp".to_string(),
462 cors: Cors::default(),
463 tls: Tls::default(),
464 tls_configured: false,
465 max_request_body_size: 0,
466 }
467 }
468}
469
470/// CORS configuration for the OTLP HTTP receiver.
471#[derive(Clone, Debug, Default, PartialEq, Serialize)]
472pub struct Cors {
473 /// Allowed origins for cross-origin requests. A bare `*` allows every origin; a partial
474 /// wildcard like `http://*.example.com` matches that prefix and suffix. Empty disables CORS.
475 /// Defaults to empty; configure this for browser-based exporters.
476 pub allowed_origins: Vec<String>,
477
478 /// Request headers allowed in preflight, beyond the implicit `Accept`, `Accept-Language`,
479 /// `Content-Type`, and `Content-Language`. Use `*` to allow any header. Empty also implicitly
480 /// allows `X-Requested-With`. Defaults to empty; add headers for browser exporters that send them.
481 pub allowed_headers: Vec<String>,
482
483 /// Response headers exposed to the browser via `Access-Control-Expose-Headers`.
484 /// Defaults to empty; add headers browser clients need to read.
485 pub exposed_headers: Vec<String>,
486
487 /// Seconds browsers may cache a preflight response. Defaults to `0` (no caching); increase
488 /// to avoid repeated preflight round-trips for frequent browser requests.
489 pub max_age: u64,
490}
491
492/// How custom infrastructure tags are promoted into container tags on OTLP traces.
493#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize)]
494#[serde(rename_all = "lowercase")]
495pub enum ContainerTagPromotion {
496 /// Writes tags as-is. Only convention keys reach container tags; custom keys remain plain resource
497 /// attributes.
498 #[default]
499 Off,
500
501 /// Writes both the original key and a `datadog.container.tag.` prefixed copy, so custom keys reach
502 /// container tags while the unprefixed form survives for consumers that read it.
503 Duplicate,
504
505 /// Writes only the `datadog.container.tag.` form. Smaller payloads, but consumers reading the
506 /// unprefixed form lose access to the tag.
507 Rename,
508}
509
510impl FromStr for ContainerTagPromotion {
511 type Err = Error;
512
513 fn from_str(value: &str) -> Result<Self, Self::Err> {
514 match value {
515 "off" => Ok(Self::Off),
516 "duplicate" => Ok(Self::Duplicate),
517 "rename" => Ok(Self::Rename),
518 other => Err(Error::new_without_source(format!(
519 "unknown container tag promotion mode `{other}`; expected `off`, `duplicate`, or `rename`"
520 ))),
521 }
522 }
523}
524
525/// OTLP trace ingestion settings.
526#[derive(Clone, Debug, PartialEq, Serialize)]
527pub struct Traces {
528 /// Whether OTLP trace ingestion is enabled.
529 pub enabled: bool,
530
531 /// Internal port the OTLP trace receiver forwards to.
532 pub internal_port: u16,
533
534 /// Percentage of OTLP traces the OTLP receiver keeps when the APM probabilistic sampler is disabled.
535 ///
536 /// The receiver turns this into a sampling rate and reports that rate on every OTLP trace as `_dd.otlp_sr`, even
537 /// when the APM probabilistic sampler makes the sampling decision. Values outside `(0, 100)`, and NaN, normalize to a
538 /// receiver rate of `1.0`. Explicit sampling priorities and other samplers still apply.
539 ///
540 /// Defaults to `100`. Lower it to reduce OTLP trace volume when the APM probabilistic sampler is disabled.
541 pub probabilistic_sampler_sampling_percentage: f64,
542
543 /// Non-zero byte budget for the OTLP trace context interner. (not in Datadog Agent config schema)
544 ///
545 /// Defaults to 512 KiB and cannot exceed 1 GiB.
546 pub string_interner_size: NonZeroUsize,
547
548 /// Whether top-level spans are computed from span kind on OTLP traces. (not in Datadog Agent
549 /// config schema)
550 pub enable_compute_top_level_by_span_kind: bool,
551
552 /// Whether spans missing intake-required fields are ingested rather than rejected. (not in
553 /// Datadog Agent config schema)
554 pub ignore_missing_datadog_fields: bool,
555
556 /// Whether entity and global tags from the workload metadata store are enriched onto OTLP traces.
557 ///
558 /// Defaults to `true`. When `false`, traces carry only the resource attributes the sender provided.
559 pub infra_attributes_enabled: bool,
560
561 /// How custom infrastructure tags are promoted into container tags on OTLP traces.
562 ///
563 /// Defaults to `off`, which leaves custom tags as plain resource attributes. Convention keys and
564 /// already-prefixed keys are exempt in every mode.
565 pub container_tag_promotion: ContainerTagPromotion,
566
567 /// Whether the OTLP span name becomes the operation name of OTLP spans that have no `operation.name`.
568 ///
569 /// `true` selects V1 operation and resource naming. Defaults to `false`.
570 pub span_name_as_resource_name: bool,
571
572 /// Preferred operation names, keyed by the operation name V1 naming derives.
573 ///
574 /// A non-empty map selects V1 operation and resource naming. Defaults to empty.
575 pub span_name_remappings: HashMap<String, String>,
576}
577
578impl Default for Traces {
579 fn default() -> Self {
580 Self {
581 enabled: false,
582 internal_port: 0,
583 // Witnessed; overwritten during drive.
584 probabilistic_sampler_sampling_percentage: 0.0,
585 string_interner_size: DEFAULT_STRING_INTERNER_SIZE_BYTES,
586 enable_compute_top_level_by_span_kind: true,
587 ignore_missing_datadog_fields: false,
588 infra_attributes_enabled: true,
589 container_tag_promotion: ContainerTagPromotion::default(),
590 // Witnessed; overwritten during drive.
591 span_name_as_resource_name: false,
592 span_name_remappings: HashMap::new(),
593 }
594 }
595}
596
597/// OTLP proxy gating: which signals ADP proxies to the Agent, and the Agent endpoints it proxies them to.
598#[derive(Clone, Debug, Default, PartialEq, Serialize)]
599pub struct Proxy {
600 /// Whether ADP proxies logs.
601 pub logs_enabled: bool,
602
603 /// Whether ADP proxies metrics.
604 pub metrics_enabled: bool,
605
606 /// Whether ADP proxies traces.
607 pub traces_enabled: bool,
608
609 /// Address of the Agent's relocated OTLP/gRPC listener, which ADP proxies OTLP/gRPC requests to.
610 pub grpc_endpoint: String,
611
612 /// Address of the Agent's relocated OTLP/HTTP listener, which ADP proxies OTLP/HTTP requests to.
613 pub http_endpoint: String,
614}
615
616impl Proxy {
617 /// Returns `true` if any proxy flag is set, whether or not its signal is enabled.
618 pub const fn enabled(&self) -> bool {
619 self.logs_enabled || self.metrics_enabled || self.traces_enabled
620 }
621}
622
623/// OTLP context cache sizing.
624#[derive(Clone, Debug, PartialEq, Serialize)]
625pub struct Contexts {
626 /// Whether contexts may be heap-allocated when the interner is full. (not in Datadog Agent
627 /// config schema)
628 pub allow_context_heap_allocs: bool,
629
630 /// Maximum number of metric contexts held in the cache. (not in Datadog Agent config schema)
631 pub cached_contexts_limit: usize,
632
633 /// Maximum number of tagsets held in the cache. (not in Datadog Agent config schema)
634 pub cached_tagsets_limit: usize,
635
636 /// Size, in bytes, of the context string interner. (not in Datadog Agent config schema)
637 pub string_interner_size: u64,
638}
639
640impl Default for Contexts {
641 fn default() -> Self {
642 Self {
643 allow_context_heap_allocs: true,
644 cached_contexts_limit: 500_000,
645 cached_tagsets_limit: 500_000,
646 string_interner_size: 2 * 1024 * 1024,
647 }
648 }
649}
650
651#[cfg(test)]
652mod tests {
653 use super::{
654 ContainerTagPromotion, CumulativeMonotonicMode, DebugVerbosity, GrpcReceiver, GrpcTransport, HttpReceiver,
655 InitialCumulativeMonotonicValue,
656 };
657
658 #[test]
659 fn container_tag_promotion_parses_known_values() {
660 for (value, expected) in [
661 ("off", ContainerTagPromotion::Off),
662 ("duplicate", ContainerTagPromotion::Duplicate),
663 ("rename", ContainerTagPromotion::Rename),
664 ] {
665 assert_eq!(
666 value
667 .parse::<ContainerTagPromotion>()
668 .expect("known value should parse"),
669 expected
670 );
671 }
672 }
673
674 #[test]
675 fn container_tag_promotion_rejects_unknown_values() {
676 let error = "unsupported"
677 .parse::<ContainerTagPromotion>()
678 .expect_err("unsupported mode should be rejected");
679
680 assert_eq!(
681 error.to_string(),
682 "unknown container tag promotion mode `unsupported`; expected `off`, `duplicate`, or `rename`"
683 );
684 }
685
686 #[test]
687 fn grpc_transport_parses_known_values() {
688 assert_eq!("tcp".parse::<GrpcTransport>().unwrap(), GrpcTransport::Tcp);
689 assert_eq!("unix".parse::<GrpcTransport>().unwrap(), GrpcTransport::Unix);
690 }
691
692 #[test]
693 fn grpc_transport_rejects_unknown_values() {
694 assert!("tcp4".parse::<GrpcTransport>().is_err());
695 assert!("udp".parse::<GrpcTransport>().is_err());
696 }
697
698 #[test]
699 fn cumulative_monotonic_mode_parses_known_values() {
700 assert_eq!(
701 "to_delta"
702 .parse::<CumulativeMonotonicMode>()
703 .expect("to_delta should parse"),
704 CumulativeMonotonicMode::ToDelta
705 );
706 assert_eq!(
707 "raw_value"
708 .parse::<CumulativeMonotonicMode>()
709 .expect("raw_value should parse"),
710 CumulativeMonotonicMode::RawValue
711 );
712 }
713
714 #[test]
715 fn cumulative_monotonic_mode_rejects_unknown_values() {
716 let error = "unsupported"
717 .parse::<CumulativeMonotonicMode>()
718 .expect_err("unsupported mode should be rejected");
719
720 assert_eq!(
721 error.to_string(),
722 "unknown cumulative monotonic sum mode `unsupported`; expected `to_delta` or `raw_value`"
723 );
724 }
725
726 #[test]
727 fn initial_cumulative_monotonic_value_parses_known_values() {
728 for (value, expected) in [
729 ("auto", InitialCumulativeMonotonicValue::Auto),
730 ("drop", InitialCumulativeMonotonicValue::Drop),
731 ("keep", InitialCumulativeMonotonicValue::Keep),
732 ] {
733 assert_eq!(
734 value
735 .parse::<InitialCumulativeMonotonicValue>()
736 .expect("known value should parse"),
737 expected
738 );
739 }
740 }
741
742 #[test]
743 fn initial_cumulative_monotonic_value_rejects_unknown_values() {
744 let error = "unsupported"
745 .parse::<InitialCumulativeMonotonicValue>()
746 .expect_err("unsupported value should be rejected");
747
748 assert_eq!(
749 error.to_string(),
750 "unknown initial cumulative monotonic value `unsupported`; expected `auto`, `drop`, or `keep`"
751 );
752 }
753
754 #[test]
755 fn grpc_receiver_defaults_to_agent_compatible_values() {
756 let grpc = GrpcReceiver::default();
757 assert_eq!(grpc.max_concurrent_streams, 0, "0 means no limit (Agent default)");
758 }
759
760 #[test]
761 fn http_receiver_defaults_to_agent_compatible_values() {
762 let http = HttpReceiver::default();
763 assert_eq!(http.max_request_body_size, 0, "0 means 20 MiB default (Agent default)");
764 }
765
766 #[test]
767 fn debug_verbosity_parses_in_any_case() {
768 for (configured, expected) in [
769 ("none", DebugVerbosity::None),
770 ("Basic", DebugVerbosity::Basic),
771 ("NORMAL", DebugVerbosity::Normal),
772 ("DeTaIlEd", DebugVerbosity::Detailed),
773 ] {
774 assert_eq!(configured.parse::<DebugVerbosity>().unwrap(), expected, "{configured}");
775 }
776 }
777
778 #[test]
779 fn debug_verbosity_rejects_an_unknown_value_and_names_it() {
780 let error = "Loud".parse::<DebugVerbosity>().unwrap_err();
781
782 assert!(error.to_string().contains("unknown debug verbosity `Loud`"));
783 }
784}