From b70c2da290c31f3a8c298ab6e020d9175254998d Mon Sep 17 00:00:00 2001 From: Amir Raminfar Date: Wed, 21 May 2025 19:59:00 -0700 Subject: [PATCH] fix: fixes search and urls in detail panel (#3907) --- assets/components/LogViewer/EventSource.spec.ts | 6 +++--- assets/components/LogViewer/LogDetails.vue | 15 ++++++++------- assets/components/LogViewer/SimpleLogItem.vue | 3 +-- .../__snapshots__/EventSource.spec.ts.snap | 1 + assets/models/LogEntry.ts | 11 +++++++++-- assets/pages/settings.vue | 11 +++++++---- internal/container/event_generator.go | 1 + internal/container/types.go | 1 + internal/web/__snapshots__/web.snapshot | 15 +++++++++------ 9 files changed, 40 insertions(+), 24 deletions(-) diff --git a/assets/components/LogViewer/EventSource.spec.ts b/assets/components/LogViewer/EventSource.spec.ts index 55240280..49bbbfac 100644 --- a/assets/components/LogViewer/EventSource.spec.ts +++ b/assets/components/LogViewer/EventSource.spec.ts @@ -138,7 +138,7 @@ describe("", () => { const wrapper = createLogEventSource(); sources[sourceUrl].emitOpen(); sources[sourceUrl].emitMessage({ - data: `{"ts":1560336942459, "m":"This is a message.", "id":1}`, + data: `{"ts":1560336942459, "m":"This is a message.", "id":1, "rm": "This is a message."}`, }); vi.runAllTimers(); @@ -154,7 +154,7 @@ describe("", () => { const wrapper = createLogEventSource(); sources[sourceUrl].emitOpen(); sources[sourceUrl].emitMessage({ - data: `{"ts":1560336942459, "m":"This is a message.", "id":1}`, + data: `{"ts":1560336942459, "m":"This is a message.", "id":1, "rm": "This is a message."}`, }); vi.runAllTimers(); @@ -167,7 +167,7 @@ describe("", () => { const wrapper = createLogEventSource({ hourStyle: "12" }); sources[sourceUrl].emitOpen(); sources[sourceUrl].emitMessage({ - data: `{"ts":1560336942459, "m":"foo bar", "id":1}`, + data: `{"ts":1560336942459, "m":"foo bar", "id":1, "rm": "foo bar"}`, }); vi.runAllTimers(); diff --git a/assets/components/LogViewer/LogDetails.vue b/assets/components/LogViewer/LogDetails.vue index e3455569..69011721 100644 --- a/assets/components/LogViewer/LogDetails.vue +++ b/assets/components/LogViewer/LogDetails.vue @@ -29,7 +29,7 @@
Raw JSON - +
-

+        

       
@@ -59,7 +59,7 @@ {{ key.join(".") }}
- + {{ JSON.stringify(value) }} @@ -96,14 +96,15 @@ function toggleField(key: string[]) { const fields = computed({ get() { const fieldsWithValue: { key: string[]; value: any; enabled: boolean }[] = []; - const allFields = flattenJSONToMap(entry.unfilteredMessage); + const rawFields = JSON.parse(entry.rawMessage); + const allFields = flattenJSONToMap(rawFields); if (visibleKeys.value.size === 0) { for (const [key, value] of allFields) { fieldsWithValue.push({ key, value, enabled: true }); } } else { for (const [key, enabled] of visibleKeys.value) { - const value = getDeep(entry.unfilteredMessage, key); + const value = getDeep(rawFields, key); fieldsWithValue.push({ key, value, enabled }); } @@ -141,8 +142,8 @@ const toggleAllFields = computed({ }, }); -function syntaxHighlight(json: any) { - json = JSON.stringify(json, null, 2); +function syntaxHighlight(json: string) { + json = JSON.stringify(JSON.parse(json.replace(/&/g, "&").replace(//g, ">")), null, 2); return json.replace( /("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|\b\d+\b)/g, function (match: string) { diff --git a/assets/components/LogViewer/SimpleLogItem.vue b/assets/components/LogViewer/SimpleLogItem.vue index 78c48a4a..47aec7dd 100644 --- a/assets/components/LogViewer/SimpleLogItem.vue +++ b/assets/components/LogViewer/SimpleLogItem.vue @@ -6,14 +6,13 @@ > diff --git a/internal/container/event_generator.go b/internal/container/event_generator.go index 85b0c54f..6553b5c8 100644 --- a/internal/container/event_generator.go +++ b/internal/container/event_generator.go @@ -124,6 +124,7 @@ func createEvent(message string, streamType StdType) *LogEvent { logEvent.Timestamp = timestamp.UnixMilli() message = strings.TrimSuffix(message[index+1:], "\n") logEvent.Message = message + logEvent.RawMessage = message if message == "" { logEvent.Message = "" // empty message so do nothing } else if json.Valid([]byte(message)) { diff --git a/internal/container/types.go b/internal/container/types.go index 17ac3a06..d1592ed4 100644 --- a/internal/container/types.go +++ b/internal/container/types.go @@ -167,6 +167,7 @@ func ParseContainerAction(input string) (ContainerAction, error) { type LogEvent struct { Message any `json:"m,omitempty"` + RawMessage string `json:"rm,omitempty"` Timestamp int64 `json:"ts"` Id uint32 `json:"id,omitempty"` Level string `json:"l,omitempty"` diff --git a/internal/web/__snapshots__/web.snapshot b/internal/web/__snapshots__/web.snapshot index d406dc89..7e3f13dd 100644 --- a/internal/web/__snapshots__/web.snapshot +++ b/internal/web/__snapshots__/web.snapshot @@ -81,15 +81,18 @@ Content-Type: text/html
dev
/* snapshot: Test_handler_between_dates */ -{"m":"INFO Testing stdout logs...","ts":1589396137772,"id":466600245,"l":"info","s":"stdout","c":"123456"} -{"m":"INFO Testing stderr logs...","ts":1589396197772,"id":1101501603,"l":"info","s":"stderr","c":"123456"} +{"m":"INFO Testing stdout logs...","rm":"INFO Testing stdout logs...","ts":1589396137772,"id":466600245,"l":"info","s":"stdout","c":"123456"} +{"m":"INFO Testing stderr logs...","rm":"INFO Testing stderr logs...","ts":1589396197772,"id":1101501603,"l":"info","s":"stderr","c":"123456"} + /* snapshot: Test_handler_between_dates_with_everything_complex */ -{"m":{"msg":"a complex log message"},"ts":1589396197772,"id":62280847,"l":"unknown","s":"stdout","c":"123456"} +{"m":{"msg":"a complex log message"},"rm":"{\"msg\":\"a complex log message\"}","ts":1589396197772,"id":62280847,"l":"unknown","s":"stdout","c":"123456"} + /* snapshot: Test_handler_between_dates_with_fill */ -{"m":"INFO Testing stdout logs...","ts":1589396137772,"id":466600245,"l":"info","s":"stdout","c":"123456"} -{"m":"INFO Testing stderr logs...","ts":1589396197772,"id":1101501603,"l":"info","s":"stderr","c":"123456"} +{"m":"INFO Testing stdout logs...","rm":"INFO Testing stdout logs...","ts":1589396137772,"id":466600245,"l":"info","s":"stdout","c":"123456"} +{"m":"INFO Testing stderr logs...","rm":"INFO Testing stderr logs...","ts":1589396197772,"id":1101501603,"l":"info","s":"stderr","c":"123456"} + /* snapshot: Test_handler_download_logs */ INFO Testing logs... @@ -179,7 +182,7 @@ data: {"name":"container-stopped","host":"localhost","actorId":"123456","time":" /* snapshot: Test_handler_streamLogs_happy_with_id */ :ping -data: {"m":"INFO Testing logs...","ts":1589396137772,"id":1469707724,"l":"info","s":"stdout","c":"123456"} +data: {"m":"INFO Testing logs...","rm":"INFO Testing logs...","ts":1589396137772,"id":1469707724,"l":"info","s":"stdout","c":"123456"} id: 1589396137772