Skip to content

fix(util): second-aligned millisecond timestamps for all Datadog APIs#61

Merged
platinummonkey merged 2 commits into
mainfrom
fix/second-aligned-millisecond-timestamps
Feb 13, 2026
Merged

fix(util): second-aligned millisecond timestamps for all Datadog APIs#61
platinummonkey merged 2 commits into
mainfrom
fix/second-aligned-millisecond-timestamps

Conversation

@platinummonkey
Copy link
Copy Markdown
Collaborator

Summary

Changes

  • pkg/util/time.go: Change ParseTimeToUnixMilli to use Unix()*1000 instead of UnixMilli() — the central fix
  • cmd/metrics.go: Simplify V2 timeseries query to use ParseTimeToUnixMilli directly instead of ParseTimeParam + manual conversion
  • cmd/metrics_test.go: Fix broken parseTimeParam references → util.ParseTimeToUnixMilli; tighten test to validate the actual function used in production

Context

ParseTimeParam returns time.Time values with nanosecond precision (from time.Now() and time.Duration arithmetic). UnixMilli() preserves the sub-second millisecond component, producing timestamps not on clean second boundaries. Some Datadog APIs reject or misinterpret these. Unix()*1000 truncates sub-second precision at the source so every callsite benefits.

Test plan

  • TestV2TimeseriesTimestampConversion — validates second-aligned output for all input formats
  • TestV2TimestampUnixMilliVsUnixTimes1000 — demonstrates the difference between the two approaches
  • TestParseTimeToUnixMilli — existing unit tests pass unchanged
  • Full go test ./... passes (only pre-existing keychain test failure on macOS)

Related Issues

Supersedes #58


🤖 Generated with Claude Code

cballou and others added 2 commits February 13, 2026 17:21
…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.
…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 platinummonkey requested a review from a team as a code owner February 13, 2026 23:25
@datadog-datadog-prod-us1
Copy link
Copy Markdown
Contributor

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 79.44% (+0.00%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 710c533 | Docs | Datadog PR Page | Was this helpful? Give us feedback!

@platinummonkey platinummonkey merged commit 677f3c0 into main Feb 13, 2026
5 checks passed
@platinummonkey platinummonkey deleted the fix/second-aligned-millisecond-timestamps branch February 13, 2026 23:32
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