From a04cc98c4d12c442a4125633723a238fe3827ec2 Mon Sep 17 00:00:00 2001 From: Cody Lee Date: Tue, 10 Feb 2026 08:11:07 -0600 Subject: [PATCH 1/2] fix(logs): correct timestamp conversion in logs search command 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 --- cmd/logs_simple.go | 4 +-- cmd/logs_simple_test.go | 55 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/cmd/logs_simple.go b/cmd/logs_simple.go index df03dc24..de96ca94 100644 --- a/cmd/logs_simple.go +++ b/cmd/logs_simple.go @@ -655,8 +655,8 @@ func runLogsSearch(cmd *cobra.Command, args []string) error { api := datadogV1.NewLogsApi(client.V1()) limit := int32(logsLimit) - fromTimeObj := time.Unix(fromTime, 0) - toTimeObj := time.Unix(toTime, 0) + fromTimeObj := time.UnixMilli(fromTime) + toTimeObj := time.UnixMilli(toTime) body := datadogV1.LogsListRequest{ Query: &logsQuery, diff --git a/cmd/logs_simple_test.go b/cmd/logs_simple_test.go index d214cf25..6e7737a7 100644 --- a/cmd/logs_simple_test.go +++ b/cmd/logs_simple_test.go @@ -25,6 +25,61 @@ func TestLogsCmd(t *testing.T) { } } +func TestParseTimeString(t *testing.T) { + tests := []struct { + name string + input string + wantErr bool + check func(int64) bool + }{ + { + name: "relative time - 1 hour", + input: "1h", + check: func(ts int64) bool { + // Should be roughly 1 hour ago in milliseconds + // Timestamps should be 13 digits for milliseconds since epoch + return ts > 1000000000000 && ts < 9999999999999 + }, + }, + { + name: "relative time - 7 days", + input: "7d", + check: func(ts int64) bool { + // Should be roughly 7 days ago in milliseconds + return ts > 1000000000000 && ts < 9999999999999 + }, + }, + { + name: "now", + input: "now", + check: func(ts int64) bool { + // Should be current time in milliseconds (13 digits) + return ts > 1000000000000 && ts < 9999999999999 + }, + }, + { + name: "invalid format", + input: "invalid", + wantErr: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := parseTimeString(tt.input) + + if (err != nil) != tt.wantErr { + t.Errorf("parseTimeString() error = %v, wantErr %v", err, tt.wantErr) + return + } + + if !tt.wantErr && tt.check != nil && !tt.check(got) { + t.Errorf("parseTimeString() = %d, validation failed", got) + } + }) + } +} + // Helper function to setup logs test client func setupLogsTestClient(t *testing.T) func() { t.Helper() From 64446c154ac62c675c2674225615506dadb4c391 Mon Sep 17 00:00:00 2001 From: Cody Lee Date: Tue, 10 Feb 2026 08:11:21 -0600 Subject: [PATCH 2/2] fix(client): remove QueryTimeseriesData from unstable operations 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 --- pkg/client/client.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/client/client.go b/pkg/client/client.go index 4179415d..dea94208 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -79,7 +79,6 @@ func New(cfg *config.Config) (*Client, error) { // Enable all unstable operations to suppress warnings // These are beta/preview features that we want to use unstableOps := []string{ - "v2.QueryTimeseriesData", "v2.ListIncidents", "v2.GetIncident", "v2.CreateIncident",