Skip to content

Commit

Permalink
fix(datadog_agent source): return 200 on empty object payload (#19093)
Browse files Browse the repository at this point in the history
* fix(datadog_agent source): return 200 on empty object payload

* add test
  • Loading branch information
dsmith3197 authored and jszwedko committed Nov 16, 2023
1 parent 86f1c22 commit 3650313
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/sources/datadog_agent/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ pub(crate) fn decode_log_body(
api_key: Option<Arc<str>>,
source: &DatadogAgentSource,
) -> Result<Vec<Event>, ErrorMessage> {
if body.is_empty() {
if body.is_empty() || body.as_ref() == b"{}" {
// The datadog agent may send an empty payload as a keep alive
// https://github.com/DataDog/datadog-agent/blob/5a6c5dd75a2233fbf954e38ddcc1484df4c21a35/pkg/logs/client/http/destination.go#L52
debug!(
message = "Empty payload ignored.",
internal_log_rate_limit = true
Expand Down
21 changes: 21 additions & 0 deletions src/sources/datadog_agent/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,27 @@ fn test_decode_log_body() {
QuickCheck::new().quickcheck(inner as fn(Vec<LogMsg>) -> TestResult);
}

#[test]
fn test_decode_log_body_empty_object() {
let body = Bytes::from("{}");
let api_key = None;
let decoder = crate::codecs::Decoder::new(
Framer::Bytes(BytesDecoder::new()),
Deserializer::Bytes(BytesDeserializer),
);

let source = DatadogAgentSource::new(
true,
decoder,
"http",
test_logs_schema_definition(),
LogNamespace::Legacy,
);

let events = decode_log_body(body, api_key, &source).unwrap();
assert_eq!(events.len(), 0);
}

#[test]
fn generate_config() {
crate::test_util::test_generate_config::<DatadogAgentConfig>();
Expand Down

0 comments on commit 3650313

Please sign in to comment.