fix(util): second-aligned millisecond timestamps for all Datadog APIs#61
Merged
Merged
Conversation
…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>
Contributor
|
✅ Tests 🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: 710c533 | Docs | Datadog PR Page | Was this helpful? Give us feedback! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ParseTimeToUnixMilliundefined: parseTimeParam)ParseTimeToUnixMilli(logs, RUM, error tracking, metrics) now produce second-aligned timestamps by defaultChanges
pkg/util/time.go: ChangeParseTimeToUnixMillito useUnix()*1000instead ofUnixMilli()— the central fixcmd/metrics.go: Simplify V2 timeseries query to useParseTimeToUnixMillidirectly instead ofParseTimeParam+ manual conversioncmd/metrics_test.go: Fix brokenparseTimeParamreferences →util.ParseTimeToUnixMilli; tighten test to validate the actual function used in productionContext
ParseTimeParamreturnstime.Timevalues with nanosecond precision (fromtime.Now()andtime.Durationarithmetic).UnixMilli()preserves the sub-second millisecond component, producing timestamps not on clean second boundaries. Some Datadog APIs reject or misinterpret these.Unix()*1000truncates sub-second precision at the source so every callsite benefits.Test plan
TestV2TimeseriesTimestampConversion— validates second-aligned output for all input formatsTestV2TimestampUnixMilliVsUnixTimes1000— demonstrates the difference between the two approachesTestParseTimeToUnixMilli— existing unit tests pass unchangedgo test ./...passes (only pre-existing keychain test failure on macOS)Related Issues
Supersedes #58
🤖 Generated with Claude Code