Skip to content

pkg/line: support DogStatsD v1.3 metric timestamp field (|T<unix_ts>)#684

Open
alliasgher wants to merge 1 commit into
prometheus:masterfrom
alliasgher:fix/dogstatsd-v1.3-timestamp
Open

pkg/line: support DogStatsD v1.3 metric timestamp field (|T<unix_ts>)#684
alliasgher wants to merge 1 commit into
prometheus:masterfrom
alliasgher:fix/dogstatsd-v1.3-timestamp

Conversation

@alliasgher
Copy link
Copy Markdown

Summary

DogStatsD protocol v1.3 adds an optional timestamp suffix to the metric datagram:

<name>:<value>|<type>|#<tags>|T<unix_timestamp>

Previously any datagram containing this field was silently dropped because T was not a recognised component prefix (hit the default branch → continue samples) and the 5-component guard rejected fully-formed v1.3 datagrams.

Changes

  • pkg/line/line.go: add a 'T' case in the component switch that validates the Unix timestamp integer and ignores it (statsd_exporter does not propagate source timestamps to Prometheus — same approach as the v1.2 |c:<container_id> field)
  • Raise the max-components guard from 58 to accommodate all six possible v1.3 fields (value, type, @sample, #tags, |c:, |T:) without hitting a false malformed_component error
  • pkg/line/line_test.go: five new test cases — counter, gauge, combined sampling+container+timestamp, and two malformed-timestamp cases

Tests

go test ./pkg/line/...   # all pass

Fixes #680

DogStatsD protocol v1.3 adds an optional metric timestamp suffix:

  <name>:<value>|<type>|#<tags>|T<unix_timestamp>

The timestamp is a UTC Unix epoch integer, e.g. T1656581400.
statsd_exporter does not propagate source timestamps to Prometheus,
so the field is parsed for validity and then discarded — this matches
the behaviour of the container-ID (|c:) field introduced in v1.2.

Changes:
- Add a 'T' case in the component switch to accept and validate the
  timestamp field; invalid or missing values increment the
  malformed_timestamp error counter.
- Raise the max-components guard from 5 to 8 to accommodate all v1.3
  fields (value, type, @sample, #tags, |c:container, |T<ts>) without
  triggering a false malformed_component error.
- Add five test cases: counter with timestamp, gauge with timestamp,
  combined sampling+container+timestamp, and two malformed cases.

Fixes prometheus#680

Signed-off-by: Ali <alliasgher123@gmail.com>
Copy link
Copy Markdown
Contributor

@pedro-stanaka pedro-stanaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Been busy times for me, finally had the chance to review this. Need some clarification and I think we can drop the expensive parse of the timestamp.

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.

DogStatsD v1.3 support an optional Unix timestamp field.

2 participants