Skip to content

Commit 3deb317

Browse files
dsmith3197AndrooTheChen
authored andcommitted
fix(datadog_agent source): return 200 on empty object payload (vectordotdev#19093)
* fix(datadog_agent source): return 200 on empty object payload * add test
1 parent 228cc1f commit 3deb317

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/sources/datadog_agent/logs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ pub(crate) fn decode_log_body(
6767
api_key: Option<Arc<str>>,
6868
source: &DatadogAgentSource,
6969
) -> Result<Vec<Event>, ErrorMessage> {
70-
if body.is_empty() {
70+
if body.is_empty() || body.as_ref() == b"{}" {
7171
// The datadog agent may send an empty payload as a keep alive
72+
// https://github.com/DataDog/datadog-agent/blob/5a6c5dd75a2233fbf954e38ddcc1484df4c21a35/pkg/logs/client/http/destination.go#L52
7273
debug!(
7374
message = "Empty payload ignored.",
7475
internal_log_rate_limit = true

src/sources/datadog_agent/tests.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,27 @@ fn test_decode_log_body() {
120120
QuickCheck::new().quickcheck(inner as fn(Vec<LogMsg>) -> TestResult);
121121
}
122122

123+
#[test]
124+
fn test_decode_log_body_empty_object() {
125+
let body = Bytes::from("{}");
126+
let api_key = None;
127+
let decoder = crate::codecs::Decoder::new(
128+
Framer::Bytes(BytesDecoder::new()),
129+
Deserializer::Bytes(BytesDeserializer),
130+
);
131+
132+
let source = DatadogAgentSource::new(
133+
true,
134+
decoder,
135+
"http",
136+
test_logs_schema_definition(),
137+
LogNamespace::Legacy,
138+
);
139+
140+
let events = decode_log_body(body, api_key, &source).unwrap();
141+
assert_eq!(events.len(), 0);
142+
}
143+
123144
#[test]
124145
fn generate_config() {
125146
crate::test_util::test_generate_config::<DatadogAgentConfig>();

0 commit comments

Comments
 (0)