1
0
mirror of https://github.com/amir20/dozzle.git synced 2025-12-21 21:33:18 +01:00

support more timestamp formats (#405)

This commit is contained in:
Raphael Piccolo
2020-04-27 21:03:51 +02:00
committed by GitHub
parent 00c143a8c8
commit d794ca1c7f
2 changed files with 21 additions and 3 deletions

View File

@@ -105,6 +105,23 @@ describe("<LogEventSource />", () => {
`); `);
}); });
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 () => { test("should pass messages to slot", async () => {
const wrapper = createLogEventSource(); const wrapper = createLogEventSource();
sources["/api/logs/stream?id=abc"].emitOpen(); sources["/api/logs/stream?id=abc"].emitOpen();

View File

@@ -10,9 +10,10 @@ import debounce from "lodash.debounce";
import InfiniteLoader from "./InfiniteLoader"; import InfiniteLoader from "./InfiniteLoader";
function parseMessage(data) { function parseMessage(data) {
const date = new Date(data.substring(0, 30)); const i = data.indexOf(' ');
const key = data.substring(0, 30); const key = data.substring(0, i);
const message = data.substring(30).trim(); const date = new Date(key);
const message = data.substring(i).trim();
return { return {
key, key,
date, date,