From 2af0033f62b1f81c8e9593a77de8f7921d53f8d0 Mon Sep 17 00:00:00 2001 From: Adrinlol Date: Thu, 18 Aug 2022 13:53:58 +0400 Subject: [PATCH 01/10] Add fira code font-family and use it for logs container (#396) --- ui/packages/ce/public/index.html | 3 +++ ui/packages/platform/public/index.html | 3 +++ ui/packages/shared/pages/Instance/styles.scss | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ui/packages/ce/public/index.html b/ui/packages/ce/public/index.html index 2ddd0a316..19370dad8 100644 --- a/ui/packages/ce/public/index.html +++ b/ui/packages/ce/public/index.html @@ -14,6 +14,9 @@ + + + diff --git a/ui/packages/platform/public/index.html b/ui/packages/platform/public/index.html index a6f51b12e..ccbe6cb61 100644 --- a/ui/packages/platform/public/index.html +++ b/ui/packages/platform/public/index.html @@ -22,6 +22,9 @@ + + + diff --git a/ui/packages/shared/pages/Instance/styles.scss b/ui/packages/shared/pages/Instance/styles.scss index 3bc100169..4dacc716d 100644 --- a/ui/packages/shared/pages/Instance/styles.scss +++ b/ui/packages/shared/pages/Instance/styles.scss @@ -14,6 +14,6 @@ padding: 0.5rem 1rem; & > p { font-size: medium; - font-family: 'Source Code Pro, monospace'; + font-family: 'Fira Code', monospace; } } -- GitLab From e4a546d0a5dd6509d85633e9f79810fc46b33103 Mon Sep 17 00:00:00 2001 From: Lasha Kakabadze Date: Wed, 24 Aug 2022 23:31:49 +0200 Subject: [PATCH 02/10] If response includes error, assign red color (#396) --- ui/packages/platform/src/components/DbLabSession.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ui/packages/platform/src/components/DbLabSession.js b/ui/packages/platform/src/components/DbLabSession.js index 1ebaf8fe2..f3df6ca88 100644 --- a/ui/packages/platform/src/components/DbLabSession.js +++ b/ui/packages/platform/src/components/DbLabSession.js @@ -23,6 +23,7 @@ import ExpansionPanelDetails from '@material-ui/core/ExpansionPanelDetails'; import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; import TextField from '@material-ui/core/TextField'; import { formatDistanceToNowStrict } from 'date-fns'; +import cn from 'classnames'; import { HorizontalScrollContainer @@ -71,6 +72,11 @@ const getStyles = (theme) => ({ marginBottom: 10, borderBottom: '1px solid ' + colors.consoleStroke }, + errorMessageColor: { + '& > p': { + color: 'red' + } + }, logContainer: { 'backgroundColor': 'black', 'color': 'white', @@ -501,6 +507,9 @@ class DbLabSession extends Component { const logs = data && data.logs ? data.logs : null; const artifacts = data && data.artifacts ? data.artifacts : null; const artifactData = data && data.artifactData ? data.artifactData : null; + const filterErrorLogs = () => logs && logs.filter((r) => + (r.sql_state_code.includes('ERROR') || + r.message.includes('ERROR'))) && classes.errorMessageColor; return (
@@ -765,7 +774,6 @@ class DbLabSession extends Component { value={i.warning} className={classes.code} margin='normal' - variant='outlined' InputProps={{ readOnly: true }} @@ -942,7 +950,8 @@ class DbLabSession extends Component { className={classes.artifactsExpansionPanelDetails}> { a.artifact_type === 'log' ?
{Array.isArray(logs) && logs.length ? ( -
+
{logs.map(r => { return (
-- GitLab From 34a06a95c8f261959e45e8cdbbfe9cebffe9415b Mon Sep 17 00:00:00 2001 From: Lasha Kakabadze Date: Tue, 30 Aug 2022 15:17:14 +0400 Subject: [PATCH 03/10] Revert changes to dblabsession and implement error log for logs (#396) --- ui/packages/platform/src/components/DbLabSession.js | 13 ++----------- ui/packages/shared/pages/Instance/styles.scss | 4 ++++ ui/packages/shared/pages/Instance/wsLogs.ts | 4 ++++ 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/ui/packages/platform/src/components/DbLabSession.js b/ui/packages/platform/src/components/DbLabSession.js index f3df6ca88..1ebaf8fe2 100644 --- a/ui/packages/platform/src/components/DbLabSession.js +++ b/ui/packages/platform/src/components/DbLabSession.js @@ -23,7 +23,6 @@ import ExpansionPanelDetails from '@material-ui/core/ExpansionPanelDetails'; import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; import TextField from '@material-ui/core/TextField'; import { formatDistanceToNowStrict } from 'date-fns'; -import cn from 'classnames'; import { HorizontalScrollContainer @@ -72,11 +71,6 @@ const getStyles = (theme) => ({ marginBottom: 10, borderBottom: '1px solid ' + colors.consoleStroke }, - errorMessageColor: { - '& > p': { - color: 'red' - } - }, logContainer: { 'backgroundColor': 'black', 'color': 'white', @@ -507,9 +501,6 @@ class DbLabSession extends Component { const logs = data && data.logs ? data.logs : null; const artifacts = data && data.artifacts ? data.artifacts : null; const artifactData = data && data.artifactData ? data.artifactData : null; - const filterErrorLogs = () => logs && logs.filter((r) => - (r.sql_state_code.includes('ERROR') || - r.message.includes('ERROR'))) && classes.errorMessageColor; return (
@@ -774,6 +765,7 @@ class DbLabSession extends Component { value={i.warning} className={classes.code} margin='normal' + variant='outlined' InputProps={{ readOnly: true }} @@ -950,8 +942,7 @@ class DbLabSession extends Component { className={classes.artifactsExpansionPanelDetails}> { a.artifact_type === 'log' ?
{Array.isArray(logs) && logs.length ? ( -
+
{logs.map(r => { return (
diff --git a/ui/packages/shared/pages/Instance/styles.scss b/ui/packages/shared/pages/Instance/styles.scss index 4dacc716d..55e0c08ee 100644 --- a/ui/packages/shared/pages/Instance/styles.scss +++ b/ui/packages/shared/pages/Instance/styles.scss @@ -17,3 +17,7 @@ font-family: 'Fira Code', monospace; } } + +.error-log { + color: red; +} \ No newline at end of file diff --git a/ui/packages/shared/pages/Instance/wsLogs.ts b/ui/packages/shared/pages/Instance/wsLogs.ts index 6cd299f54..572507f80 100644 --- a/ui/packages/shared/pages/Instance/wsLogs.ts +++ b/ui/packages/shared/pages/Instance/wsLogs.ts @@ -16,6 +16,10 @@ export const establishConnection = async (api: Api) => { tag.appendChild(document.createTextNode(logEntry)); logElement.appendChild(tag); logElement.scrollIntoView(false); + + if (logEntry.split(" ")[3] === "[ERROR]") { + tag.classList.add("error-log"); + } }; const { response, error } = await api.getWSToken({ -- GitLab From 61a2944287d3296bebb9ec6ec232d30c250eb8be Mon Sep 17 00:00:00 2001 From: Lasha Kakabadze Date: Wed, 31 Aug 2022 15:43:45 +0400 Subject: [PATCH 04/10] Display logs messages for n minutes (#396) --- ui/packages/shared/pages/Instance/wsLogs.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/ui/packages/shared/pages/Instance/wsLogs.ts b/ui/packages/shared/pages/Instance/wsLogs.ts index 572507f80..1e0709807 100644 --- a/ui/packages/shared/pages/Instance/wsLogs.ts +++ b/ui/packages/shared/pages/Instance/wsLogs.ts @@ -1,6 +1,8 @@ +import moment from 'moment'; import { Api } from "./stores/Main"; const logsEndpoint = '/instance/logs'; +const LOGS_TIME_LIMIT = 20 export const establishConnection = async (api: Api) => { const logElement = document.getElementById("logs-container"); @@ -57,8 +59,17 @@ export const establishConnection = async (api: Api) => { }; socket.onmessage = function (event) { - const logEntry = decodeURIComponent(atob(event.data)); - - appendLogElement(logEntry) - }; + const logEntry = decodeURIComponent(atob(event.data)) + const logEntryTime = moment.utc( + logEntry.split(' ').slice(0, 2).join(',').replace(',', ' '), + ) + + const timeDifference = + moment(logEntryTime).isValid() && + moment.duration(moment.utc(Date.now()).diff(logEntryTime)).asMinutes() + + if (timeDifference <= LOGS_TIME_LIMIT) { + appendLogElement(logEntry) + } + } }; -- GitLab From 198a46e510f5990f504fb576255b811a39e5c694 Mon Sep 17 00:00:00 2001 From: Lasha Kakabadze Date: Wed, 31 Aug 2022 16:03:52 +0400 Subject: [PATCH 05/10] Limit the number of logs - defaults to 1000 (#396) --- ui/packages/shared/pages/Instance/wsLogs.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ui/packages/shared/pages/Instance/wsLogs.ts b/ui/packages/shared/pages/Instance/wsLogs.ts index 1e0709807..b32130596 100644 --- a/ui/packages/shared/pages/Instance/wsLogs.ts +++ b/ui/packages/shared/pages/Instance/wsLogs.ts @@ -2,7 +2,9 @@ import moment from 'moment'; import { Api } from "./stores/Main"; const logsEndpoint = '/instance/logs'; + const LOGS_TIME_LIMIT = 20 +const LOGS_LINE_LIMIT = 1000 export const establishConnection = async (api: Api) => { const logElement = document.getElementById("logs-container"); @@ -68,7 +70,10 @@ export const establishConnection = async (api: Api) => { moment(logEntryTime).isValid() && moment.duration(moment.utc(Date.now()).diff(logEntryTime)).asMinutes() - if (timeDifference <= LOGS_TIME_LIMIT) { + if ( + timeDifference <= LOGS_TIME_LIMIT && + logElement.childElementCount <= LOGS_LINE_LIMIT + ) { appendLogElement(logEntry) } } -- GitLab From 8c63a0ff6ab15d86060ac04b743c32015151e197 Mon Sep 17 00:00:00 2001 From: Lasha Kakabadze Date: Wed, 31 Aug 2022 16:17:00 +0400 Subject: [PATCH 06/10] Add padding between log messages (#396) --- ui/packages/shared/pages/Instance/styles.scss | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ui/packages/shared/pages/Instance/styles.scss b/ui/packages/shared/pages/Instance/styles.scss index 55e0c08ee..1dafe7291 100644 --- a/ui/packages/shared/pages/Instance/styles.scss +++ b/ui/packages/shared/pages/Instance/styles.scss @@ -14,7 +14,8 @@ padding: 0.5rem 1rem; & > p { font-size: medium; - font-family: 'Fira Code', monospace; + font-family: 'Fira Code', monospace; + padding: 4px 0; } } -- GitLab From c66d091d1849d8cd67c76efb2fec0caf2559d2d2 Mon Sep 17 00:00:00 2001 From: Lasha Kakabadze Date: Thu, 1 Sep 2022 17:57:23 +0400 Subject: [PATCH 07/10] Delete log entry if the limit has been reached (#396) --- ui/packages/shared/pages/Instance/wsLogs.ts | 53 +++++++++++---------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/ui/packages/shared/pages/Instance/wsLogs.ts b/ui/packages/shared/pages/Instance/wsLogs.ts index b32130596..762e3701f 100644 --- a/ui/packages/shared/pages/Instance/wsLogs.ts +++ b/ui/packages/shared/pages/Instance/wsLogs.ts @@ -14,17 +14,33 @@ export const establishConnection = async (api: Api) => { return; } - const appendLogElement = (logEntry: string) => { - const tag = document.createElement("p"); - - tag.appendChild(document.createTextNode(logEntry)); - logElement.appendChild(tag); - logElement.scrollIntoView(false); - - if (logEntry.split(" ")[3] === "[ERROR]") { - tag.classList.add("error-log"); + const appendLogElement = (logEntry: string, logType?: string) => { + const tag = document.createElement('p') + tag.appendChild(document.createTextNode(logEntry)) + logElement.appendChild(tag) + logElement.scrollIntoView(false) + + if (logType === 'message') { + const logEntryTime = moment.utc( + logEntry.split(' ').slice(0, 2).join(',').replace(',', ' '), + ) + + const timeDifference = + moment(logEntryTime).isValid() && + moment.duration(moment.utc(Date.now()).diff(logEntryTime)).asMinutes() + + if ( + logElement.childElementCount > LOGS_LINE_LIMIT && + timeDifference > LOGS_TIME_LIMIT + ) { + logElement.removeChild(tag) + } + + if (logEntry.split(' ')[3] === '[ERROR]') { + tag.classList.add('error-log') + } } - }; + } const { response, error } = await api.getWSToken({ instanceId: "", @@ -62,19 +78,6 @@ export const establishConnection = async (api: Api) => { socket.onmessage = function (event) { const logEntry = decodeURIComponent(atob(event.data)) - const logEntryTime = moment.utc( - logEntry.split(' ').slice(0, 2).join(',').replace(',', ' '), - ) - - const timeDifference = - moment(logEntryTime).isValid() && - moment.duration(moment.utc(Date.now()).diff(logEntryTime)).asMinutes() - - if ( - timeDifference <= LOGS_TIME_LIMIT && - logElement.childElementCount <= LOGS_LINE_LIMIT - ) { - appendLogElement(logEntry) - } - } + appendLogElement(logEntry, "message") + } }; -- GitLab From b6390b5c653a6126604c117f435ed08b0c9f79e0 Mon Sep 17 00:00:00 2001 From: Lasha Kakabadze Date: Fri, 2 Sep 2022 11:43:30 +0400 Subject: [PATCH 08/10] Improve solution for log removal (#396) --- ui/packages/shared/pages/Instance/wsLogs.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ui/packages/shared/pages/Instance/wsLogs.ts b/ui/packages/shared/pages/Instance/wsLogs.ts index 762e3701f..eb4f24433 100644 --- a/ui/packages/shared/pages/Instance/wsLogs.ts +++ b/ui/packages/shared/pages/Instance/wsLogs.ts @@ -28,12 +28,14 @@ export const establishConnection = async (api: Api) => { const timeDifference = moment(logEntryTime).isValid() && moment.duration(moment.utc(Date.now()).diff(logEntryTime)).asMinutes() - - if ( - logElement.childElementCount > LOGS_LINE_LIMIT && - timeDifference > LOGS_TIME_LIMIT - ) { - logElement.removeChild(tag) + + for (let i = 0; i < logElement.childElementCount; i++) { + if ( + logElement.childElementCount > LOGS_LINE_LIMIT && + timeDifference > LOGS_TIME_LIMIT + ) { + logElement.removeChild(logElement.children[i]) + } } if (logEntry.split(' ')[3] === '[ERROR]') { -- GitLab From 08ce0d536c77441d9c9297c6b4c29e877df6dd1e Mon Sep 17 00:00:00 2001 From: Lasha Kakabadze Date: Fri, 2 Sep 2022 13:51:48 +0400 Subject: [PATCH 09/10] Remove log element iteration (#396) --- ui/packages/shared/pages/Instance/wsLogs.ts | 54 +++++++++++---------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/ui/packages/shared/pages/Instance/wsLogs.ts b/ui/packages/shared/pages/Instance/wsLogs.ts index eb4f24433..5541ff7ba 100644 --- a/ui/packages/shared/pages/Instance/wsLogs.ts +++ b/ui/packages/shared/pages/Instance/wsLogs.ts @@ -15,34 +15,36 @@ export const establishConnection = async (api: Api) => { } const appendLogElement = (logEntry: string, logType?: string) => { - const tag = document.createElement('p') - tag.appendChild(document.createTextNode(logEntry)) - logElement.appendChild(tag) - logElement.scrollIntoView(false) - - if (logType === 'message') { - const logEntryTime = moment.utc( - logEntry.split(' ').slice(0, 2).join(',').replace(',', ' '), - ) - - const timeDifference = - moment(logEntryTime).isValid() && - moment.duration(moment.utc(Date.now()).diff(logEntryTime)).asMinutes() - - for (let i = 0; i < logElement.childElementCount; i++) { - if ( - logElement.childElementCount > LOGS_LINE_LIMIT && - timeDifference > LOGS_TIME_LIMIT - ) { - logElement.removeChild(logElement.children[i]) - } - } - - if (logEntry.split(' ')[3] === '[ERROR]') { - tag.classList.add('error-log') - } + const tag = document.createElement('p') + tag.appendChild(document.createTextNode(logEntry)) + logElement.appendChild(tag) + logElement.scrollIntoView(false) + + if (logType === 'message') { + const logEntryTime = moment.utc( + logElement.children[0].innerHTML + .split(' ') + .slice(0, 2) + .join(',') + .replace(',', ' '), + ) + + const timeDifference = + moment(logEntryTime).isValid() && + moment.duration(moment.utc(Date.now()).diff(logEntryTime)).asMinutes() + + if ( + logElement.childElementCount > LOGS_LINE_LIMIT && + timeDifference > LOGS_TIME_LIMIT + ) { + logElement.removeChild(logElement.children[0]) } } + + if (logEntry.split(' ')[3] === '[ERROR]') { + tag.classList.add('error-log') + } + } const { response, error } = await api.getWSToken({ instanceId: "", -- GitLab From 768e3af3e7ada12352fd6b2dd3d4d913796811fa Mon Sep 17 00:00:00 2001 From: Lasha Kakabadze Date: Fri, 2 Sep 2022 15:25:00 +0400 Subject: [PATCH 10/10] Cleanup entry time calculation (#396) --- ui/packages/shared/pages/Instance/wsLogs.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/ui/packages/shared/pages/Instance/wsLogs.ts b/ui/packages/shared/pages/Instance/wsLogs.ts index 5541ff7ba..3ac48ad06 100644 --- a/ui/packages/shared/pages/Instance/wsLogs.ts +++ b/ui/packages/shared/pages/Instance/wsLogs.ts @@ -22,11 +22,7 @@ export const establishConnection = async (api: Api) => { if (logType === 'message') { const logEntryTime = moment.utc( - logElement.children[0].innerHTML - .split(' ') - .slice(0, 2) - .join(',') - .replace(',', ' '), + logElement.children[0].innerHTML.split(' ').slice(0, 2).join(' '), ) const timeDifference = -- GitLab