Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/api/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ func logsResponse(message string) map[string]any {
"data": []any{
map[string]any{
"message": message,
"timestamp": int64(1760000000000),
"timestamp": "2025-10-09T08:53:20Z",
},
},
"has_more": false,
Expand Down
4 changes: 3 additions & 1 deletion internal/api/log_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"net/http/httptest"
"testing"
"time"

"github.com/google/uuid"
"github.com/stretchr/testify/assert"
Expand All @@ -31,7 +32,7 @@ func TestStreamProjectLogsRequestAndEvents(t *testing.T) {
_, _ = w.Write([]byte(": connected\n\n"))
_, _ = w.Write([]byte("id: next-id\n"))
_, _ = w.Write([]byte("event: log\n"))
_, _ = w.Write([]byte(`data: {"id":"log-1","message":"build finished","timestamp":1760000000000,"resource":{"type":"function","id":"` + functionID.String() + `"},"deployment":{"id":"` + deploymentID.String() + `"}}` + "\n\n"))
_, _ = w.Write([]byte(`data: {"id":"log-1","message":"build finished","timestamp":"2025-10-09T08:53:20Z","resource":{"type":"function","id":"` + functionID.String() + `"},"deployment":{"id":"` + deploymentID.String() + `"}}` + "\n\n"))
_, _ = w.Write([]byte("event: warning\n"))
_, _ = w.Write([]byte(`data: {"error":"temporary read failure"}` + "\n\n"))
}))
Expand Down Expand Up @@ -61,6 +62,7 @@ func TestStreamProjectLogsRequestAndEvents(t *testing.T) {
assert.Equal(t, "next-id", event.ID)
assert.Equal(t, "log-1", event.Log.Id)
assert.Equal(t, "build finished", event.Log.Message)
assert.Equal(t, time.Date(2025, 10, 9, 8, 53, 20, 0, time.UTC), event.Log.Timestamp)

event, err = stream.Next()
require.NoError(t, err)
Expand Down
8 changes: 4 additions & 4 deletions internal/apiclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ func TestGetProjectLogActivityUsesPostBody(t *testing.T) {
resourceIDs := []string{"22222222-2222-4222-8222-222222222222"}
levels := []string{"warn"}
regions := []string{"us-east-1"}
startTime := int64(1_700_000_000_000)
endTime := int64(1_700_000_300_000)
startTime := "2023-11-14T22:13:20Z"
endTime := "2023-11-14T23:03:20Z"
bucketCount := 24
requestBody, err := json.Marshal(map[string]any{
"resource": map[string]any{
Expand Down Expand Up @@ -47,7 +47,7 @@ func TestGetProjectLogActivityUsesPostBody(t *testing.T) {
assert.Equal(t, []any{resourceIDs[0]}, resource["ids"])
assert.Equal(t, []any{levels[0]}, decodedBody["levels"])
assert.Equal(t, []any{regions[0]}, decodedBody["regions"])
assert.InEpsilon(t, startTime, decodedBody["start_time"], 0)
assert.InEpsilon(t, endTime, decodedBody["end_time"], 0)
assert.Equal(t, startTime, decodedBody["start_time"])
assert.Equal(t, endTime, decodedBody["end_time"])
assert.InEpsilon(t, bucketCount, decodedBody["bucket_count"], 0)
}
36 changes: 18 additions & 18 deletions internal/apiclient/common/common.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions internal/cmd/frontends/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func frontendLogCommandResponse(message string, hasMore bool, next string) map[s
map[string]any{
"message": message,
"region": "aws-us-east-1",
"timestamp": int64(1760000000000),
"timestamp": "2025-10-09T08:53:20Z",
},
},
"has_more": hasMore,
Expand All @@ -284,13 +284,13 @@ func catchUpLogResponse() map[string]any {
"id": "stream-log",
"message": "build follow",
"region": "aws-us-east-1",
"timestamp": int64(1760000000000),
"timestamp": "2025-10-09T08:53:20Z",
},
map[string]any{
"id": "catch-up-log",
"message": "catch up log",
"region": "aws-us-east-1",
"timestamp": int64(1760000000001),
"timestamp": "2025-10-09T08:53:20.001Z",
},
},
"has_more": false,
Expand All @@ -306,7 +306,7 @@ func writeFrontendLogStream(t *testing.T, w http.ResponseWriter, message string)
_, _ = w.Write([]byte(": connected\n\n"))
_, _ = w.Write([]byte("id: stream-cursor\n"))
_, _ = w.Write([]byte("event: log\n"))
_, _ = w.Write([]byte(`data: {"id":"stream-log","message":"` + message + `","timestamp":1760000000000,"resource":{"type":"frontend","id":"` + frontendID + `"}}` + "\n\n"))
_, _ = w.Write([]byte(`data: {"id":"stream-log","message":"` + message + `","timestamp":"2025-10-09T08:53:20Z","resource":{"type":"frontend","id":"` + frontendID + `"}}` + "\n\n"))
if flusher, ok := w.(http.Flusher); ok {
flusher.Flush()
}
Expand Down
8 changes: 4 additions & 4 deletions internal/cmd/functions/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func logCommandResponse(message string, hasMore bool, next string) map[string]an
map[string]any{
"message": message,
"region": "aws-us-east-1",
"timestamp": int64(1760000000000),
"timestamp": "2025-10-09T08:53:20Z",
},
},
"has_more": hasMore,
Expand All @@ -295,13 +295,13 @@ func catchUpLogResponse() map[string]any {
"id": "stream-log",
"message": "build follow",
"region": "aws-us-east-1",
"timestamp": int64(1760000000000),
"timestamp": "2025-10-09T08:53:20Z",
},
map[string]any{
"id": "catch-up-log",
"message": "catch up log",
"region": "aws-us-east-1",
"timestamp": int64(1760000000001),
"timestamp": "2025-10-09T08:53:20.001Z",
},
},
"has_more": false,
Expand All @@ -317,7 +317,7 @@ func writeFunctionLogStream(t *testing.T, w http.ResponseWriter, message string)
_, _ = w.Write([]byte(": connected\n\n"))
_, _ = w.Write([]byte("id: stream-cursor\n"))
_, _ = w.Write([]byte("event: log\n"))
_, _ = w.Write([]byte(`data: {"id":"stream-log","message":"` + message + `","timestamp":1760000000000,"resource":{"type":"function","id":"` + functionID + `"}}` + "\n\n"))
_, _ = w.Write([]byte(`data: {"id":"stream-log","message":"` + message + `","timestamp":"2025-10-09T08:53:20Z","resource":{"type":"function","id":"` + functionID + `"}}` + "\n\n"))
if flusher, ok := w.(http.Flusher); ok {
flusher.Flush()
}
Expand Down
6 changes: 3 additions & 3 deletions internal/logfollow/follow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestDeploymentStopsAtTerminalStatusAndRunsCatchUp(t *testing.T) {
w.Header().Set("Content-Type", "text/event-stream")
_, _ = w.Write([]byte("id: stream-cursor\n"))
_, _ = w.Write([]byte("event: log\n"))
_, _ = w.Write([]byte(`data: {"id":"streamed-id","message":"streamed log","timestamp":1760000000000,"resource":{"type":"function","id":"` + functionID.String() + `"}}` + "\n\n"))
_, _ = w.Write([]byte(`data: {"id":"streamed-id","message":"streamed log","timestamp":"2025-10-09T08:53:20Z","resource":{"type":"function","id":"` + functionID.String() + `"}}` + "\n\n"))
flusher.Flush()
<-r.Context().Done()
}))
Expand Down Expand Up @@ -77,7 +77,7 @@ func TestDeploymentRunsCatchUpWhenStreamEndsBeforeTerminal(t *testing.T) {
w.Header().Set("Content-Type", "text/event-stream")
_, _ = w.Write([]byte("id: stream-cursor\n"))
_, _ = w.Write([]byte("event: log\n"))
_, _ = w.Write([]byte(`data: {"id":"streamed-id","message":"streamed log","timestamp":1760000000000,"resource":{"type":"function","id":"` + functionID.String() + `"}}` + "\n\n"))
_, _ = w.Write([]byte(`data: {"id":"streamed-id","message":"streamed log","timestamp":"2025-10-09T08:53:20Z","resource":{"type":"function","id":"` + functionID.String() + `"}}` + "\n\n"))
}))
defer server.Close()

Expand Down Expand Up @@ -210,7 +210,7 @@ func TestRuntimeSurfacesOpenError(t *testing.T) {
func writeStreamLog(w http.ResponseWriter, cursor, logID, message string) {
_, _ = w.Write([]byte("id: " + cursor + "\n"))
_, _ = w.Write([]byte("event: log\n"))
_, _ = w.Write([]byte(`data: {"id":"` + logID + `","message":"` + message + `","timestamp":1760000000000,"resource":{"type":"function","id":"22222222-2222-4222-8222-222222222222"}}` + "\n\n"))
_, _ = w.Write([]byte(`data: {"id":"` + logID + `","message":"` + message + `","timestamp":"2025-10-09T08:53:20Z","resource":{"type":"function","id":"22222222-2222-4222-8222-222222222222"}}` + "\n\n"))
if flusher, ok := w.(http.Flusher); ok {
flusher.Flush()
}
Expand Down
7 changes: 4 additions & 3 deletions internal/output/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,14 @@ func LogSearchEvents(w io.Writer, events []apiclient.LogSearchEvent) {
}
}

func printLogEvent(w io.Writer, timestamp int64, region *string, message string) {
func printLogEvent(w io.Writer, timestamp time.Time, region *string, message string) {
message = strings.TrimSpace(message)
formattedTimestamp := FormatTimestamp(timestamp)
if region := stringPtrValue(region); region != "" {
fmt.Fprintf(w, "%s [%s] %s\n", time.UnixMilli(timestamp).Format(time.RFC3339), region, message)
fmt.Fprintf(w, "%s [%s] %s\n", formattedTimestamp, region, message)
return
}
fmt.Fprintf(w, "%s %s\n", time.UnixMilli(timestamp).Format(time.RFC3339), message)
fmt.Fprintf(w, "%s %s\n", formattedTimestamp, message)
}

func functionStatus(fn apiclient.Function) string {
Expand Down
Loading