fix(metrics): send timestamps as Unix seconds instead of milliseconds to API#7
Merged
Conversation
… to API The metrics query command was incorrectly converting timestamps to milliseconds before sending to the Datadog v2 timeseries API, which expects Unix timestamps in seconds. This caused queries to fail or return incorrect time ranges. The parseTimeParam function correctly parses input timestamps as seconds (e.g., "1h" ago, "1704067200", or "now"), but the code was then multiplying by 1000 (via UnixMilli()) before sending to the API. Changes: - Changed from.UnixMilli() to from.Unix() in runMetricsQuery - Changed to.UnixMilli() to to.Unix() in runMetricsQuery - Updated documentation to clarify timestamps are in seconds Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
📊 Test Coverage ReportThreshold: 80% ❌ Coverage by Package📈 Coverage Status: ❌ FAILED - Coverage below minimum threshold Updated for commit 5022dcc |
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
Fixed a bug where the metrics query command was sending timestamps in milliseconds instead of seconds to the Datadog v2 timeseries API, causing queries to fail or return incorrect time ranges.
Problem
The
parseTimeParamfunction correctly parses user input (e.g.,--from="1h",--from="1704067200") as Unix seconds, but the code was then converting these to milliseconds via.UnixMilli()before sending to the API. The Datadog v2 timeseries API expects timestamps in seconds, not milliseconds.Changes
from.UnixMilli()tofrom.Unix()inrunMetricsQuery(cmd/metrics.go:510)to.UnixMilli()toto.Unix()inrunMetricsQuery(cmd/metrics.go:511)Testing
.UnixMilli()pattern for API callsImpact
Users can now correctly query metrics with time ranges like:
🤖 Generated with Claude Code