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() 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",