Skip to content

fix(logs): correct timestamp conversion causing 400 Bad Request#16

Merged
platinummonkey merged 2 commits into
mainfrom
fix/logs-search-bad-request
Feb 10, 2026
Merged

fix(logs): correct timestamp conversion causing 400 Bad Request#16
platinummonkey merged 2 commits into
mainfrom
fix/logs-search-bad-request

Conversation

@platinummonkey
Copy link
Copy Markdown
Collaborator

Summary

Fixes a critical bug in the pup logs search command that was causing 400 Bad Request errors. The issue was incorrect timestamp conversion from milliseconds to seconds, resulting in dates in the year 57063 instead of 2026.

Also removes an obsolete unstable operation warning for v2.QueryTimeseriesData.

Changes

Timestamp Conversion Fix (cmd/logs_simple.go:658-659)

  • Changed time.Unix(fromTime, 0) to time.UnixMilli(fromTime)
  • Changed time.Unix(toTime, 0) to time.UnixMilli(toTime)
  • The parseTimeString() function returns milliseconds, but time.Unix() expects seconds

Warning Fix (pkg/client/client.go:82)

  • Removed v2.QueryTimeseriesData from unstable operations list
  • This operation is no longer unstable in the API client library

Testing (cmd/logs_simple_test.go)

  • Added TestParseTimeString to validate timestamp parsing
  • Ensures timestamps are returned in milliseconds (13 digits)
  • Tests relative times (1h, 7d) and "now"

Root Cause

When users ran:

pup logs search --query="service:storage-manager" --from="7d" --limit=20

The function would:

  1. Parse "7d" to 1738971894000 milliseconds
  2. Pass to time.Unix(1738971894000, 0) treating it as seconds
  3. Create timestamp for year 57063
  4. API rejects with 400 Bad Request

Testing

  • ✅ All unit tests pass
  • ✅ Race detector clean
  • ✅ Build successful
  • ✅ New test validates timestamp format

Related Issues

Fixes user-reported bug: Error: failed to search logs: 400 Bad Request (status: 400)


🤖 Generated with Claude Code

platinummonkey and others added 2 commits February 10, 2026 08:11
The `runLogsSearch` function was incorrectly using `time.Unix()` to convert
millisecond timestamps returned by `parseTimeString()`. The `time.Unix()`
function expects seconds as the first parameter, but was receiving
milliseconds, causing it to create timestamps in the year 57063 instead of
2026. This resulted in 400 Bad Request errors from the API.

Changes:
- Use `time.UnixMilli()` instead of `time.Unix()` in logs_simple.go:658-659
- Add `TestParseTimeString` to validate timestamp parsing returns milliseconds
- Verify all other log commands (list, query, aggregate) correctly use string formatting

Fixes the error: "failed to search logs: 400 Bad Request (status: 400)"

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
The `v2.QueryTimeseriesData` operation is no longer unstable in the Datadog
API client library, causing a warning when trying to enable it:
"WARNING: 'v2.QueryTimeseriesData' is not an unstable operation"

Removed `v2.QueryTimeseriesData` from the unstable operations list in
pkg/client/client.go to eliminate the spurious warning.

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 14:12
@github-actions
Copy link
Copy Markdown

📊 Test Coverage Report

Overall Coverage: 75.5% 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:33: 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/util/time.go:20: 95.8%

## Summary

total:								(statements)		75.5%

📈 Coverage Status: ❌ FAILED - Coverage below minimum threshold

Updated for commit 64446c1

@platinummonkey platinummonkey merged commit 766a191 into main Feb 10, 2026
4 checks passed
@platinummonkey platinummonkey deleted the fix/logs-search-bad-request branch February 10, 2026 14:17
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