Skip to content

line: parse DogStatsD container ID field on lines without tags - #748

Open
Vasu-Madaan wants to merge 1 commit into
prometheus:masterfrom
Vasu-Madaan:fix-dogstatsd-container-id-without-tags
Open

line: parse DogStatsD container ID field on lines without tags#748
Vasu-Madaan wants to merge 1 commit into
prometheus:masterfrom
Vasu-Madaan:fix-dogstatsd-container-id-without-tags

Conversation

@Vasu-Madaan

Copy link
Copy Markdown

Problem

The DogStatsD v1.2 container ID field (|c:<id>) can appear on a line that has no |# tags (for example a DogStatsD client with origin/container detection enabled but no constant tags configured). A counter then looks like:

my_counter:1|c|c:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef

LineToEvents only treats a line as DogStatsD (and skips the legacy multi-metric : split) when it contains |#. Without tags, the line falls through to strings.Split(elements[1], ":"), which splits on every colon and shreds the container ID field:

"1|c|c:0123...ef"  ->  ["1|c|c", "0123...ef"]

The first fragment 1|c|c parses value=1, type=c, and a trailing bare c that fails the container-ID check (malformed_container_id); the second fragment has too few parts (malformed_component). The sample is dropped and the metric is never exported, even though the same line with tags parses correctly:

my_counter:1|c|#env:prod|c:0123...ef   ->  ok, container_id label set

Fix

Detect the container ID field (always the final |-delimited field) and, like |# tags, skip the legacy : split for such lines. A valid legacy multi-metric line always ends in a bare stat type (c, g, ms, ...), never c:<id>, so legacy parsing is unaffected.

Tests

Adds LineToEvents cases for counter/gauge/timer/complex-value container-ID lines without tags. gofmt, go vet, and go test ./... pass.


Note: Claude was used to help investigate and prepare this change.

The DogStatsD v1.2 container ID field (|c:<id>) can appear on a line that
has no |# tags. In that case LineToEvents fell through to the legacy
multi-metric ':' split, which shredded the |c:<id> field: the sample was
dropped and counted as malformed_container_id + malformed_component, so
the metric was never exported.

Detect the container ID field (always the final '|'-delimited field) and,
like |# tags, skip the legacy ':' split for such lines. A valid legacy
line always ends in a bare stat type (c, g, ms, ...), never "c:<id>", so
this does not affect legacy multi-metric parsing.

Add tests for counter/gauge/timer/complex-value container ID lines
without tags.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant