diff --git a/assets/components/LogEventSource.spec.js b/assets/components/LogEventSource.spec.js index 06eb83ba..ac56d911 100644 --- a/assets/components/LogEventSource.spec.js +++ b/assets/components/LogEventSource.spec.js @@ -105,6 +105,23 @@ describe("", () => { `); }); + test("should parse messages with loki's timestamp format", async () => { + const wrapper = createLogEventSource(); + sources["/api/logs/stream?id=abc"].emitOpen(); + sources["/api/logs/stream?id=abc"].emitMessage({ data: `2020-04-27T12:35:43.272974324+02:00 xxxxx` }); + + const [message, _] = wrapper.vm.messages; + const { key, ...messageWithoutKey } = message; + + expect(key).toBe("2020-04-27T10:35:43.272Z"); + expect(messageWithoutKey).toMatchInlineSnapshot(` + Object { + "date": 2020-04-27T10:35:43.272Z, + "message": "xxxxx", + } + `); + }); + test("should pass messages to slot", async () => { const wrapper = createLogEventSource(); sources["/api/logs/stream?id=abc"].emitOpen(); diff --git a/assets/components/LogEventSource.vue b/assets/components/LogEventSource.vue index bff10d2f..4737f78b 100644 --- a/assets/components/LogEventSource.vue +++ b/assets/components/LogEventSource.vue @@ -10,9 +10,10 @@ import debounce from "lodash.debounce"; import InfiniteLoader from "./InfiniteLoader"; function parseMessage(data) { - const date = new Date(data.substring(0, 30)); - const key = data.substring(0, 30); - const message = data.substring(30).trim(); + const i = data.indexOf(' '); + const key = data.substring(0, i); + const date = new Date(key); + const message = data.substring(i).trim(); return { key, date,