Skip to content

fix(datadog): cap coalesced DogStatsD datagram size, fall back to per-metric sends#13665

Open
shreemaan-abhishek wants to merge 1 commit into
apache:masterfrom
shreemaan-abhishek:perf/datadog-datagram-size-guard
Open

fix(datadog): cap coalesced DogStatsD datagram size, fall back to per-metric sends#13665
shreemaan-abhishek wants to merge 1 commit into
apache:masterfrom
shreemaan-abhishek:perf/datadog-datagram-size-guard

Conversation

@shreemaan-abhishek

Copy link
Copy Markdown
Contributor

Description

Follow-up to #13653 (already merged), addressing the review note there about the coalesced datagram having no size guard.

#13653 coalesces an entry's metrics into a single newline-delimited DogStatsD datagram. Because each line repeats the full tag suffix, the coalesced packet is ~6x a single metric line. With long tag sources (constant_tags has no maxItems, route/service/consumer names can be long, include_path adds the route path), the packet can exceed the DogStatsD agent's default receive buffer (dogstatsd_buffer_size, 8192 bytes) and be silently truncatedsock:send() only returns an error above the OS max UDP size (~64KB on Linux), so nothing catches it. This is a regression versus the previous one-datagram-per-metric behaviour, where each datagram was ~6x smaller.

This PR sends the coalesced datagram only when it fits within 8192 bytes; otherwise it falls back to one datagram per metric (the original size profile). A single socket is still reused across the batch, so the syscall win from #13653 is preserved for the common case.

Tests

Adds a test with oversized constant_tags (coalesced payload > 8192) asserting every metric still arrives via the fallback path.

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation accordingly (no user-facing config/behaviour change)
  • I have verified linting passes

Coalescing an entry's metrics into one datagram repeats the tag suffix on
every line, so with long constant_tags / names / paths the packet can exceed
the DogStatsD agent's default receive buffer (dogstatsd_buffer_size = 8192)
and be silently truncated. Send the coalesced datagram only when it fits
within 8192 bytes; otherwise fall back to one datagram per metric (the
original size profile). Adds a test with oversized tags asserting all
metrics still arrive.

Signed-off-by: Abhishek Choudhary <shreemaan.abhishek@gmail.com>
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant