Skip to content

fix(metrics): improve error messages and fix timestamp format#31

Merged
platinummonkey merged 1 commit into
mainfrom
fix/improve-metrics-error-handling
Feb 11, 2026
Merged

fix(metrics): improve error messages and fix timestamp format#31
platinummonkey merged 1 commit into
mainfrom
fix/improve-metrics-error-handling

Conversation

@platinummonkey
Copy link
Copy Markdown
Collaborator

Summary

Fixes #29 - Improves error handling in metrics commands to provide detailed API error messages and fixes timestamp format bug causing "Queries before 2010 are invalid" errors.

Changes

Error Message Improvements

  • Extract and display full API response body in error messages
  • Add request context (query, timestamps, filters, tags) to errors
  • Include troubleshooting tips for common issues
  • Applied to all metrics commands: query, list, metadata get/update, and submit

Timestamp Format Fix

  • Root Cause: API v2 timeseries endpoint expects timestamps in milliseconds, not seconds
  • Before: Using from.Unix() (seconds) → e.g., 1770772813
  • After: Using from.UTC().UnixMilli() (milliseconds) → e.g., 1770772813000
  • Ensures timestamps are converted to UTC before sending to API

Example

Before (generic error):

Error: failed to query metrics: 400 Bad Request (status: 400)

After (detailed error):

Error: failed to query metrics: 400 Bad Request
Status: 400
API Response: {"errors":["Queries before 2010 are invalid"]}

Request Details:
- Query: avg:system.cpu.user{*}
- From: 2026-02-10T19:20:13Z (Unix: 1770772813)
- To: 2026-02-10T20:20:13Z (Unix: 1770776413)

Troubleshooting:
- Verify your query syntax is correct (e.g., avg:metric.name{filter})
- Check that the time range is valid
- Ensure the metric exists and has data in the specified time range
- Confirm you have proper permissions to access the metric

Testing

  • All existing tests pass
  • Verified build completes successfully
  • Manually tested error output format

Related Issues

Closes #29


🤖 Generated with Claude Code

Fixes #29 - Improves error handling in metrics commands to provide
detailed API error messages and request context for debugging.

Changes:
- Extract and display API response body in error messages
- Add request details (query, timestamps, filters) to errors
- Include troubleshooting tips for common issues
- Fix timestamp format: use UnixMilli() instead of Unix() for API v2
- Convert timestamps to UTC before sending to API

The API v2 timeseries endpoint expects timestamps in milliseconds,
not seconds. This was causing "Queries before 2010 are invalid" errors
because second-based timestamps were being interpreted as 1970s dates.

Error messages now show:
- HTTP status code
- Full API response (e.g., {"errors":["..."]})
- Request parameters used
- Troubleshooting guidance

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@platinummonkey platinummonkey requested a review from a team as a code owner February 11, 2026 02:22
@github-actions
Copy link
Copy Markdown

📊 Test Coverage Report

Overall Coverage: 80.4% 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:32: 94.4%
- 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/useragent/useragent.go:32: 100.0%
- github.com/DataDog/pup/pkg/util/time.go:20: 95.8%

## Summary

total:								(statements)		80.4%

📈 Coverage Status: ✅ PASSED - Coverage meets minimum threshold

Updated for commit 0a3adb2

@platinummonkey platinummonkey merged commit 99219a7 into main Feb 11, 2026
4 checks passed
@platinummonkey platinummonkey deleted the fix/improve-metrics-error-handling branch February 11, 2026 02:26
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.

[BUG] metrics query not working

1 participant