diff --git a/backend/server.js b/backend/server.js index 20d9312..bbf60f3 100644 --- a/backend/server.js +++ b/backend/server.js @@ -32,6 +32,12 @@ async function run() { changeStream = collection.watch(pipeline, options); console.log("Started watching changes in database"); + const filterOptions = { + 'kubernetes.namespace': await collection.distinct('kubernetes.namespace'), + 'kubernetes.pod.name': await collection.distinct('kubernetes.pod.name'), + 'kubernetes.container.name': await collection.distinct('kubernetes.container.name') + } + const writeMessage = (response, blob) => { const id = blob._id || null const message = `id: ${id}\nevent: message\ndata: ${JSON.stringify(blob)}\n\n` @@ -45,6 +51,9 @@ async function run() { const header = { 'Content-Type': 'text/event-stream', 'Connection': 'keep-alive' }; response.writeHead(200, "OK", header); + const message = `id: 1\nevent: filters\ndata: ${JSON.stringify(filterOptions)}\n\n` + response.write(message) + const historyCursor = collection.find() .sort({$natural:-1}) .limit(historyNumber).toArray().then((res) => { diff --git a/frontend/src/components/LogViewer.vue b/frontend/src/components/LogViewer.vue index 4ee57dc..3e4a015 100644 --- a/frontend/src/components/LogViewer.vue +++ b/frontend/src/components/LogViewer.vue @@ -44,6 +44,7 @@ export default { enableCellChangeFlash: true }, currentRowCount: 0, + comboBoxOptions: {}, viewRowCount: 20, comboBoxOptions: [], columnDefs: [ @@ -88,6 +89,7 @@ export default { setupStream() { let es = new EventSource('/events'); es.onmessage = (e) => this.handleReceiveMessage(e) + es.addEventListener("filters", (e) => this.handleReceiveFilters(e)) }, onGridReady(params) { this.gridApi = params.api; @@ -102,6 +104,9 @@ export default { this.gridApi.flashCells({ rowNodes: [rowNode]}); this.gridApi.sizeColumnsToFit() }, + handleReceiveFilters (event) { + this.comboBoxOptions = this.parseEventData(event.data); + }, parseEventData (eventData) { try { let json = JSON.parse(eventData)