Skip to content

fix(metrics): use Unix()*1000 for V2 timeseries API timestamps#58

Closed
cballou wants to merge 1 commit into
DataDog:mainfrom
cballou:fix/v2-timeseries-timestamp-conversion
Closed

fix(metrics): use Unix()*1000 for V2 timeseries API timestamps#58
cballou wants to merge 1 commit into
DataDog:mainfrom
cballou:fix/v2-timeseries-timestamp-conversion

Conversation

@cballou
Copy link
Copy Markdown
Contributor

@cballou cballou commented Feb 12, 2026

Summary

  • Fixes V2 timeseries metric query failures caused by sub-second precision in millisecond timestamps
  • Replaces time.Time.UnixMilli() with Unix() * 1000 to produce second-aligned millisecond timestamps that the Datadog V2 API accepts reliably
  • Adds unit tests validating the timestamp conversion behavior

Details

parseTimeParam returns time.Time values with nanosecond precision (from time.Now() and time.Duration arithmetic). UnixMilli() faithfully includes the sub-second millisecond component, producing timestamps that are not on clean second boundaries. The API rejects or misinterprets these.

Unix() * 1000 truncates sub-second precision and produces second-aligned millisecond timestamps.

Test plan

  • Added unit tests for timestamp conversion
  • Manual verification: run pup metrics query with V2 timeseries endpoint and confirm queries succeed

…s API timestamps

The Datadog V2 timeseries query API expects millisecond timestamps, but
using time.Time.UnixMilli() directly caused query failures. The root
cause is that parseTimeParam returns time values with nanosecond
precision (from time.Now() and time.Duration arithmetic), and
UnixMilli() faithfully includes the sub-second millisecond component.
This produces timestamps that are not on clean second boundaries, which
the API rejects or misinterprets.

Switching to Unix() * 1000 truncates sub-second precision and produces
second-aligned millisecond timestamps that the API accepts reliably.
@cballou cballou requested a review from a team as a code owner February 12, 2026 17:36
@platinummonkey
Copy link
Copy Markdown
Collaborator

@cballou mind fixing the failure? If not I'm happy to pick this up, I suspect this might exist on other APIs as well so that's a good catch.

platinummonkey added a commit that referenced this pull request Feb 13, 2026
…rseTimeToUnixMilli

Moves the Unix()*1000 fix from the metrics V2 callsite into
ParseTimeToUnixMilli so all callers (logs, RUM, error tracking, metrics)
produce second-aligned timestamps by default. Fixes the CI build failure
from #58 where tests referenced an undefined parseTimeParam symbol.

- Change ParseTimeToUnixMilli to use Unix()*1000 instead of UnixMilli()
- Simplify metrics V2 query to use ParseTimeToUnixMilli directly
- Fix test references from parseTimeParam to util.ParseTimeToUnixMilli

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@platinummonkey
Copy link
Copy Markdown
Collaborator

merged into #61

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.

2 participants