Skip to content

fix(metrics): send timestamps as Unix seconds instead of milliseconds to API#7

Merged
platinummonkey merged 2 commits into
mainfrom
metrics-bug
Feb 10, 2026
Merged

fix(metrics): send timestamps as Unix seconds instead of milliseconds to API#7
platinummonkey merged 2 commits into
mainfrom
metrics-bug

Conversation

@platinummonkey
Copy link
Copy Markdown
Collaborator

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 parseTimeParam function 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

  • Changed from.UnixMilli() to from.Unix() in runMetricsQuery (cmd/metrics.go:510)
  • Changed to.UnixMilli() to to.Unix() in runMetricsQuery (cmd/metrics.go:511)
  • Updated documentation to clarify timestamps are in seconds (cmd/metrics.go:126-127)

Testing

  • All existing tests pass
  • Verified no other code uses the incorrect .UnixMilli() pattern for API calls

Impact

Users can now correctly query metrics with time ranges like:

pup metrics query --query="avg:system.cpu.user{*}" --from="1h" --to="now"
pup metrics query --query="avg:system.cpu.user{*}" --from="1704067200" --to="1704153600"

🤖 Generated with Claude Code

… 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>
@platinummonkey platinummonkey requested a review from a team as a code owner February 10, 2026 02:44
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 10, 2026

📊 Test Coverage Report

Overall Coverage: 75.1% Coverage

Threshold: 80% ❌

Coverage by Package
## Coverage by Package

- github.com/DataDog/pup/pkg/auth/callback/server.go:40: 81.2%
- github.com/DataDog/pup/pkg/auth/dcr/client.go:28: 100.0%
- github.com/DataDog/pup/pkg/auth/dcr/types.go:24: 100.0%
- github.com/DataDog/pup/pkg/auth/oauth/client.go:22: 100.0%
- github.com/DataDog/pup/pkg/auth/oauth/pkce.go:24: 85.7%
- github.com/DataDog/pup/pkg/auth/storage/factory.go:53: 94.7%
- github.com/DataDog/pup/pkg/auth/storage/keychain.go:44: 42.9%
- github.com/DataDog/pup/pkg/auth/storage/storage.go:58: 71.4%
- github.com/DataDog/pup/pkg/auth/types/types.go:23: 100.0%
- github.com/DataDog/pup/pkg/client/client.go:28: 94.1%
- github.com/DataDog/pup/pkg/config/config.go:22: 100.0%
- github.com/DataDog/pup/pkg/formatter/formatter.go:31: 100.0%
- github.com/DataDog/pup/pkg/util/time.go:20: 95.8%

## Summary

total:								(statements)		75.1%

📈 Coverage Status: ❌ FAILED - Coverage below minimum threshold

Updated for commit 5022dcc

@platinummonkey platinummonkey merged commit c969308 into main Feb 10, 2026
4 checks passed
@platinummonkey platinummonkey deleted the metrics-bug branch February 10, 2026 02:46
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.

1 participant