From 9d239f918ab0779ff5a020253f87ce010d5f9c25 Mon Sep 17 00:00:00 2001 From: Imre Toth <imre.toth@ess.eu> Date: Fri, 24 Feb 2023 16:29:30 +0000 Subject: [PATCH] ICSHWI-11079: Modifying log configuration" --- src/api/SwaggerApi.js | 8 ++--- src/components/common/Loki/LokiPanel.js | 34 +++++++++++++--------- src/components/common/snackbar/Snackbar.js | 4 +-- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/api/SwaggerApi.js b/src/api/SwaggerApi.js index dc90c28b..39e5b38a 100644 --- a/src/api/SwaggerApi.js +++ b/src/api/SwaggerApi.js @@ -761,7 +761,7 @@ export function unpackLokilog(logData) { return { ...logData }; } -export function useLokiSysLog() { +export function useLokiSysLog(onError) { const api = useContext(apiContext); const method = useCallAndUnpack( (hostName, timeRange) => @@ -771,10 +771,10 @@ export function useLokiSysLog() { }), unpackLokilog ); - return useAsync({ fcn: method, call: false }); + return useAsync({ fcn: method, call: false, onError: onError }); } -export function useLokiProcServLog() { +export function useLokiProcServLog(onError) { const api = useContext(apiContext); const method = useCallAndUnpack( (hostName, iocName, timeRange) => @@ -786,7 +786,7 @@ export function useLokiProcServLog() { unpackLokilog ); - return useAsync({ fcn: method, call: false }); + return useAsync({ fcn: method, call: false, onError: onError }); } export function unpackIocStatus(status) { diff --git a/src/components/common/Loki/LokiPanel.js b/src/components/common/Loki/LokiPanel.js index 0ca2c144..f553d3d8 100644 --- a/src/components/common/Loki/LokiPanel.js +++ b/src/components/common/Loki/LokiPanel.js @@ -46,19 +46,26 @@ const useStyles = makeStyles((theme) => ({ const LOG_POLL_INTERVAL = 5000; export function LokiPanel({ host, iocName, isSyslog, isDeployed }) { + const showWarning = useCustomSnackbar(); + + function onError(message) { + showWarning(message, "warning"); + } + const classes = useStyles(); const hostName = host.csEntryHost.name; - const [logData, getLogData /* reset*/, , logDataLoading] = useLokiSysLog(); + const [logData, getLogData /* reset*/, , logDataLoading] = + useLokiSysLog(onError); const [procServLog, getProcServLog /* reset*/, , procServLoading] = - useLokiProcServLog(); - const [timeRange, setTimeRange] = React.useState(60); + useLokiProcServLog(onError); + const [timeRange, setTimeRange] = React.useState(720); + const [timeRangeText, setTimeRangeText] = React.useState("12 hours"); const [periodChange, setPeriodChange] = useState(false); - const showWarning = useCustomSnackbar("warning"); - const handleChange = (event) => { setPeriodChange(true); setTimeRange(event.target.value); + setTimeRangeText(event.currentTarget.innerText); }; // remove progressBar if intervall has been changed, and data received @@ -110,7 +117,6 @@ export function LokiPanel({ host, iocName, isSyslog, isDeployed }) { value={timeRange} onChange={handleChange} > - <MenuItem value={60}>1 hour</MenuItem> <MenuItem value={720}>12 hours</MenuItem> <MenuItem value={10080}>7 days</MenuItem> </Select> @@ -136,7 +142,8 @@ export function LokiPanel({ host, iocName, isSyslog, isDeployed }) { logData, procServLog, isDeployed, - showWarning + showWarning, + timeRangeText )} dataReady={dataReady} extraClass={isDeployed ? classes.deployed : classes.undeployed} @@ -160,13 +167,14 @@ function logsToPreprocess( logData, procServLog, isDeployed, - showWarning + showWarning, + timeRangeText ) { if (isSysLog === true) { - return preprocessLog(logData, true, showWarning); + return preprocessLog(logData, true, showWarning, timeRangeText); } - return preprocessLog(procServLog, isDeployed, showWarning); + return preprocessLog(procServLog, isDeployed, showWarning, timeRangeText); } function formatLogLine(logLine) { @@ -182,9 +190,9 @@ function formatLogLine(logLine) { ); } -function preprocessLog(logData, isDeployed, showWarning) { +function preprocessLog(logData, isDeployed, showWarning, timeRangeText) { if (logData.warning) { - showWarning(logData.warning); + showWarning(logData.warning, "warning"); } if (logData && logData.lines?.length > 0) { @@ -204,5 +212,5 @@ function preprocessLog(logData, isDeployed, showWarning) { } } - return "<html><body> - No messages found for period - </body></html>"; + return `<html><body> - No messages found for ${timeRangeText} period - </body></html>`; } diff --git a/src/components/common/snackbar/Snackbar.js b/src/components/common/snackbar/Snackbar.js index f11a364b..83f2ba81 100644 --- a/src/components/common/snackbar/Snackbar.js +++ b/src/components/common/snackbar/Snackbar.js @@ -14,11 +14,11 @@ const useStyles = makeStyles((theme) => ({ } })); -export function useCustomSnackbar(severity = "error") { +export function useCustomSnackbar() { const { enqueueSnackbar, closeSnackbar } = useSnackbar(); const classes = useStyles(); - function showError(errorMessage) { + function showError(errorMessage, severity = "error") { console.log("Snackbar: " + errorMessage); const action = (key) => ( <Button -- GitLab