1+ use agent_data_plane_config:: shared:: { Compression , MetricsEncoding } ;
12use async_trait:: async_trait;
23use datadog_protos:: events as proto;
34use facet:: Facet ;
45use http:: { uri:: PathAndQuery , HeaderValue , Method , Uri } ;
56use protobuf:: { rt:: WireType , CodedOutputStream } ;
67use resource_accounting:: { MemoryBounds , MemoryBoundsBuilder } ;
78use saluki_common:: iter:: ReusableDeduplicator ;
8- use saluki_config:: GenericConfiguration ;
99use saluki_context:: tags:: Tag ;
1010use saluki_core:: {
1111 components:: { encoders:: * , ComponentContext } ,
@@ -19,7 +19,6 @@ use saluki_core::{
1919use saluki_error:: { ErrorContext as _, GenericError } ;
2020use saluki_io:: compression:: CompressionScheme ;
2121use saluki_metrics:: MetricsBuilder ;
22- use serde:: Deserialize ;
2322use tracing:: { debug, error, warn} ;
2423
2524use crate :: common:: datadog:: {
@@ -28,95 +27,56 @@ use crate::common::datadog::{
2827 request_builder:: { EndpointEncoder , RequestBuilder } ,
2928 telemetry:: ComponentTelemetry ,
3029 DEFAULT_INTAKE_COMPRESSED_SIZE_LIMIT , DEFAULT_INTAKE_UNCOMPRESSED_SIZE_LIMIT ,
31- DEFAULT_SERIALIZER_COMPRESSED_SIZE_LIMIT , DEFAULT_SERIALIZER_UNCOMPRESSED_SIZE_LIMIT ,
3230} ;
3331
34- const DEFAULT_SERIALIZER_COMPRESSOR_KIND : & str = "zstd" ;
3532const MAX_EVENTS_PER_PAYLOAD : usize = 100 ;
3633const EVENTS_FIELD_NUMBER : u32 = 1 ;
3734
3835static CONTENT_TYPE_PROTOBUF : HeaderValue = HeaderValue :: from_static ( "application/x-protobuf" ) ;
3936
40- fn default_serializer_compressor_kind ( ) -> String {
41- DEFAULT_SERIALIZER_COMPRESSOR_KIND . to_owned ( )
42- }
43-
44- const fn default_zstd_compressor_level ( ) -> i32 {
45- 3
46- }
47-
48- const fn default_max_payload_size ( ) -> usize {
49- DEFAULT_SERIALIZER_COMPRESSED_SIZE_LIMIT
50- }
51-
52- const fn default_max_uncompressed_payload_size ( ) -> usize {
53- DEFAULT_SERIALIZER_UNCOMPRESSED_SIZE_LIMIT
54- }
55-
56- const fn default_log_payloads ( ) -> bool {
57- false
58- }
59-
6037/// Datadog Events incremental encoder.
6138///
6239/// Generates Datadog Events payloads for the Datadog platform.
63- #[ derive( Deserialize , Facet ) ]
64- #[ cfg_attr( test, derive( Debug , PartialEq , serde:: Serialize ) ) ]
40+ #[ derive( Facet ) ]
6541pub struct DatadogEventsConfiguration {
6642 /// Maximum compressed size, in bytes, of an events payload.
6743 ///
6844 /// This uses the same generic event payload setting as the Datadog Agent. ADP sends events to
6945 /// `/api/v1/events_batch`, so the effective value is clamped to that endpoint's global intake limit of 3,200,000
7046 /// bytes. If set to `0`, every non-empty compressed payload exceeds the limit and is dropped during flush.
71- ///
72- /// Defaults to 2,621,440 bytes.
73- #[ serde( rename = "serializer_max_payload_size" , default = "default_max_payload_size" ) ]
7447 max_payload_size : usize ,
7548
7649 /// Maximum uncompressed size, in bytes, of an events payload.
7750 ///
7851 /// This uses the same generic event payload setting as the Datadog Agent. ADP sends events to
7952 /// `/api/v1/events_batch`, so the effective value is clamped to that endpoint's global intake limit of 62,914,560
8053 /// bytes. Values smaller than the minimum endpoint framing size prevent the request builder from starting.
81- ///
82- /// Defaults to 4,194,304 bytes.
83- #[ serde(
84- rename = "serializer_max_uncompressed_payload_size" ,
85- default = "default_max_uncompressed_payload_size"
86- ) ]
8754 max_uncompressed_payload_size : usize ,
8855
8956 /// Compression kind to use for the request payloads.
90- ///
91- /// Defaults to `zstd`.
92- #[ serde(
93- rename = "serializer_compressor_kind" ,
94- default = "default_serializer_compressor_kind"
95- ) ]
9657 compressor_kind : String ,
9758
9859 /// Compressor level to use when the compressor kind is `zstd`.
99- ///
100- /// Defaults to 3.
101- #[ serde(
102- rename = "serializer_zstd_compressor_level" ,
103- default = "default_zstd_compressor_level"
104- ) ]
10560 zstd_compressor_level : i32 ,
10661
10762 /// Whether to log event payload contents before encoding.
10863 ///
10964 /// This logs decoded event objects, not the encoded HTTP body.
110- ///
111- /// Defaults to `false`.
112- #[ serde( default = "default_log_payloads" ) ]
11365 log_payloads : bool ,
11466}
11567
11668impl DatadogEventsConfiguration {
117- /// Creates a new `DatadogEventsConfiguration` from the given configuration.
118- pub fn from_configuration ( config : & GenericConfiguration ) -> Result < Self , GenericError > {
119- Ok ( config. as_typed ( ) ?)
69+ /// Creates a new `DatadogEventsConfiguration` from the shared typed configuration.
70+ pub fn from_configuration (
71+ metrics_encoding : & MetricsEncoding , compression : & Compression ,
72+ ) -> Result < Self , GenericError > {
73+ Ok ( Self {
74+ max_payload_size : metrics_encoding. max_payload_size ,
75+ max_uncompressed_payload_size : metrics_encoding. max_uncompressed_payload_size ,
76+ compressor_kind : compression. compressor_kind . clone ( ) ,
77+ zstd_compressor_level : compression. zstd_compressor_level ,
78+ log_payloads : metrics_encoding. log_payloads ,
79+ } )
12080 }
12181}
12282
@@ -328,27 +288,32 @@ fn encode_eventd(eventd: &EventD, tags_deduplicator: &mut ReusableDeduplicator<T
328288}
329289
330290#[ cfg( test) ]
331- mod config_smoke {
332- use datadog_agent_config_testing:: config_registry:: structs;
333- use datadog_agent_config_testing:: run_config_smoke_tests;
334- use serde_json:: json;
291+ mod tests {
292+ use agent_data_plane_config:: shared:: { Compression , MetricsEncoding } ;
335293
336294 use super :: DatadogEventsConfiguration ;
337- use crate :: config:: { DatadogRemapper , KEY_ALIASES } ;
338-
339- #[ tokio:: test]
340- async fn smoke_test ( ) {
341- run_config_smoke_tests (
342- structs:: DATADOG_EVENTS_CONFIGURATION ,
343- & [ ] ,
344- json ! ( { } ) ,
345- |cfg| {
346- cfg. as_typed :: < DatadogEventsConfiguration > ( )
347- . expect ( "DatadogEventsConfiguration should deserialize" )
348- } ,
349- KEY_ALIASES ,
350- DatadogRemapper :: new,
351- )
352- . await
295+
296+ #[ test]
297+ fn from_configuration_reads_typed_shared_values ( ) {
298+ let metrics_encoding = MetricsEncoding {
299+ max_payload_size : 123 ,
300+ max_uncompressed_payload_size : 456 ,
301+ log_payloads : true ,
302+ ..Default :: default ( )
303+ } ;
304+
305+ let compression = Compression {
306+ compressor_kind : "gzip" . to_owned ( ) ,
307+ zstd_compressor_level : 7 ,
308+ } ;
309+
310+ let config = DatadogEventsConfiguration :: from_configuration ( & metrics_encoding, & compression)
311+ . expect ( "typed configuration should be accepted" ) ;
312+
313+ assert_eq ! ( config. max_payload_size, 123 ) ;
314+ assert_eq ! ( config. max_uncompressed_payload_size, 456 ) ;
315+ assert_eq ! ( config. compressor_kind, "gzip" ) ;
316+ assert_eq ! ( config. zstd_compressor_level, 7 ) ;
317+ assert ! ( config. log_payloads) ;
353318 }
354319}
0 commit comments