From ca20f7c0a3e7d6d5169e2a1fbd068efa112c9660 Mon Sep 17 00:00:00 2001 From: Amir Raminfar Date: Mon, 11 May 2020 17:05:21 -0700 Subject: [PATCH] Makes changes to show all containers and event streams (#448) --- __snapshots__/dozzle.snapshot | 2 +- assets/components/LogEventSource.spec.js | 8 ++++---- assets/components/LogEventSource.vue | 22 +++++++++++++--------- assets/components/LogViewer.vue | 6 +++++- assets/components/MobileMenu.vue | 9 ++------- assets/components/SideMenu.vue | 10 +++++++--- assets/pages/Settings.vue | 8 +++++++- assets/store/index.js | 12 ++++++++---- assets/store/settings.js | 1 + docker/client.go | 8 ++++---- docker/client_test.go | 6 +++--- main.go | 18 +++++++----------- main_test.go | 12 ++++++------ routes.go | 15 +++++++++++---- 14 files changed, 79 insertions(+), 58 deletions(-) diff --git a/__snapshots__/dozzle.snapshot b/__snapshots__/dozzle.snapshot index 52701f79..777f2630 100644 --- a/__snapshots__/dozzle.snapshot +++ b/__snapshots__/dozzle.snapshot @@ -66,7 +66,7 @@ event: containers-changed data: start /* snapshot: Test_handler_streamLogs_error_finding_container */ -HTTP/1.1 500 Internal Server Error +HTTP/1.1 404 Not Found Connection: close Content-Type: text/plain; charset=utf-8 X-Content-Type-Options: nosniff diff --git a/assets/components/LogEventSource.spec.js b/assets/components/LogEventSource.spec.js index c0ee97f6..701e07fd 100644 --- a/assets/components/LogEventSource.spec.js +++ b/assets/components/LogEventSource.spec.js @@ -134,7 +134,7 @@ describe("", () => { await wrapper.vm.$nextTick(); expect(wrapper.find("ul.events")).toMatchInlineSnapshot(` `); }); @@ -149,7 +149,7 @@ describe("", () => { await wrapper.vm.$nextTick(); expect(wrapper.find("ul.events")).toMatchInlineSnapshot(`
    -
  • today at 10:55 AM blackwhite
  • +
  • today at 10:55 AM blackwhite
`); }); @@ -164,7 +164,7 @@ describe("", () => { await wrapper.vm.$nextTick(); expect(wrapper.find("ul.events")).toMatchInlineSnapshot(`
    -
  • today at 10:55 AM <test>foo bar</test>
  • +
  • today at 10:55 AM <test>foo bar</test>
`); }); @@ -182,7 +182,7 @@ describe("", () => { await wrapper.vm.$nextTick(); expect(wrapper.find("ul.events")).toMatchInlineSnapshot(`
    -
  • today at 10:55 AM This is a test <hi></hi>
  • +
  • today at 10:55 AM This is a test <hi></hi>
`); }); diff --git a/assets/components/LogEventSource.vue b/assets/components/LogEventSource.vue index cb13bc89..b9d2be4d 100644 --- a/assets/components/LogEventSource.vue +++ b/assets/components/LogEventSource.vue @@ -35,19 +35,23 @@ export default { this.es = null; } this.es = new EventSource(`${config.base}/api/logs/stream?id=${this.id}`); - const flushBuffer = debounce( - () => { - this.messages.push(...this.buffer); - this.buffer = []; - }, - 250, - { maxWait: 1000 } - ); + + this.es.addEventListener("container-stopped", (e) => { + this.es.close(); + this.buffer.push({ event: "container-stopped", message: "Container stopped", date: new Date() }); + flushNow(); + }); + this.es.addEventListener("error", (e) => console.log("EventSource failed: " + JSON.stringify(e))); + + const flushBuffer = debounce(() => flushNow(), 250, { maxWait: 1000 }); + const flushNow = () => { + this.messages.push(...this.buffer); + this.buffer = []; + }; this.es.onmessage = (e) => { this.buffer.push(this.parseMessage(e.data)); flushBuffer(); }; - this.es.onerror = (e) => console.log("EventSource failed." + e); this.$once("hook:beforeDestroy", () => this.es.close()); }, async loadOlderLogs() { diff --git a/assets/components/LogViewer.vue b/assets/components/LogViewer.vue index 5d4e0ded..d4e4ca5a 100644 --- a/assets/components/LogViewer.vue +++ b/assets/components/LogViewer.vue @@ -1,6 +1,6 @@