18975: Adds 'Main logs' filter selection. Fixes filter dynamic population.
authorLucas Di Pentima <lucas.dipentima@curii.com>
Thu, 7 Jul 2022 20:16:47 +0000 (17:16 -0300)
committerLucas Di Pentima <lucas.dipentima@curii.com>
Thu, 7 Jul 2022 20:59:22 +0000 (17:59 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas.dipentima@curii.com>

cypress/integration/process.spec.js
src/models/log.ts
src/store/process-logs-panel/process-logs-panel-actions.ts
src/store/process-logs-panel/process-logs-panel-reducer.ts

index faf70c49ec2fe93ec813b0cf821985e33ec81d9c..55290fa36bb4d8a97ecd47b3056f185a4ed83396 100644 (file)
@@ -168,8 +168,15 @@ describe('Process tests', function() {
             cy.getAll('@stdoutLogs', '@nodeInfoLogs', '@crunchRunLogs').then(function() {
                 cy.loginAs(activeUser);
                 cy.goToPath(`/processes/${containerRequest.uuid}`);
-                // Should should all logs
-                cy.get('[data-cy=process-logs-filter]').should('contain', 'All logs');
+                // Should show main logs by default
+                cy.get('[data-cy=process-logs-filter]').should('contain', 'Main logs');
+                cy.get('[data-cy=process-logs]')
+                    .should('contain', stdoutLogs[Math.floor(Math.random() * stdoutLogs.length)])
+                    .and('not.contain', nodeInfoLogs[Math.floor(Math.random() * nodeInfoLogs.length)])
+                    .and('contain', crunchRunLogs[Math.floor(Math.random() * crunchRunLogs.length)]);
+                // Select 'All logs'
+                cy.get('[data-cy=process-logs-filter]').click();
+                cy.get('body').contains('li', 'All logs').click();
                 cy.get('[data-cy=process-logs]')
                     .should('contain', stdoutLogs[Math.floor(Math.random() * stdoutLogs.length)])
                     .and('contain', nodeInfoLogs[Math.floor(Math.random() * nodeInfoLogs.length)])
index 20060f88b640f4b2f1d720b0babcee290e65a5af..63e953bb74d76d2e6706920d07e214117231a641 100644 (file)
@@ -23,6 +23,6 @@ export interface LogResource extends Resource, ResourceWithProperties {
     kind: ResourceKind.LOG;
     objectUuid: string;
     eventAt: string;
-    eventType: string;
+    eventType: LogEventType;
     summary: string;
 }
index b0ddd7ee11f70dea0c122bb5afb2b4681976ee28..ca950ffe3e5280d42caea8591f08ef7f33dd73fc 100644 (file)
@@ -45,21 +45,25 @@ export const addProcessLogsPanelItem = (message: ResourceEventMessage<{ text: st
     async (dispatch: Dispatch, getState: () => RootState, { logService }: ServiceRepository) => {
         if (PROCESS_PANEL_LOG_EVENT_TYPES.indexOf(message.eventType) > -1) {
             const uuid = getProcessLogsPanelCurrentUuid(getState().router);
-            if (uuid) {
-                const process = getProcess(uuid)(getState().resources);
-                if (process) {
-                    const { containerRequest, container } = process;
-                    if (message.objectUuid === containerRequest.uuid
-                        || (container && message.objectUuid === container.uuid)) {
-                        dispatch(processLogsPanelActions.ADD_PROCESS_LOGS_PANEL_ITEM({
-                            logType: COMBINED_FILTER_TYPE,
-                            log: message.properties.text
-                        }));
-                        dispatch(processLogsPanelActions.ADD_PROCESS_LOGS_PANEL_ITEM({
-                            logType: message.eventType,
-                            log: message.properties.text
-                        }));
-                    }
+            if (!uuid) { return }
+            const process = getProcess(uuid)(getState().resources);
+            if (!process) { return }
+            const { containerRequest, container } = process;
+            if (message.objectUuid === containerRequest.uuid
+                || (container && message.objectUuid === container.uuid)) {
+                dispatch(processLogsPanelActions.ADD_PROCESS_LOGS_PANEL_ITEM({
+                    logType: ALL_FILTER_TYPE,
+                    log: message.properties.text
+                }));
+                dispatch(processLogsPanelActions.ADD_PROCESS_LOGS_PANEL_ITEM({
+                    logType: message.eventType,
+                    log: message.properties.text
+                }));
+                if (MAIN_EVENT_TYPES.indexOf(message.eventType) > -1) {
+                    dispatch(processLogsPanelActions.ADD_PROCESS_LOGS_PANEL_ITEM({
+                        logType: MAIN_FILTER_TYPE,
+                        log: message.properties.text
+                    }));
                 }
             }
         }
@@ -84,6 +88,9 @@ const loadContainerLogs = async (containerUuid: string, logService: LogService)
 
 const createInitialLogPanelState = (logResources: LogResource[]) => {
     const allLogs = logsToLines(logResources);
+    const mainLogs = logsToLines(logResources.filter(
+        e => MAIN_EVENT_TYPES.indexOf(e.eventType) > -1
+    ));
     const groupedLogResources = groupBy(logResources, log => log.eventType);
     const groupedLogs = Object
         .keys(groupedLogResources)
@@ -91,8 +98,12 @@ const createInitialLogPanelState = (logResources: LogResource[]) => {
             ...grouped,
             [key]: logsToLines(groupedLogResources[key])
         }), {});
-    const filters = [COMBINED_FILTER_TYPE, ...Object.keys(groupedLogs)];
-    const logs = { [COMBINED_FILTER_TYPE]: allLogs, ...groupedLogs };
+    const filters = [MAIN_FILTER_TYPE, ALL_FILTER_TYPE, ...Object.keys(groupedLogs)];
+    const logs = {
+        [MAIN_FILTER_TYPE]: mainLogs,
+        [ALL_FILTER_TYPE]: allLogs,
+        ...groupedLogs
+    };
     return { filters, logs };
 };
 
@@ -111,7 +122,14 @@ export const navigateToLogCollection = (uuid: string) =>
 
 const MAX_AMOUNT_OF_LOGS = 10000;
 
-const COMBINED_FILTER_TYPE = 'All logs';
+const ALL_FILTER_TYPE = 'All logs';
+
+const MAIN_FILTER_TYPE = 'Main logs';
+const MAIN_EVENT_TYPES = [
+    LogEventType.CRUNCH_RUN,
+    LogEventType.STDERR,
+    LogEventType.STDOUT,
+];
 
 const PROCESS_PANEL_LOG_EVENT_TYPES = [
     LogEventType.ARV_MOUNT,
index c7d694c0eeb5f9f080937ce3ec9f6ee73893432a..c502f1b1ff47f18ee97873917e513f3c3daabc6e 100644 (file)
@@ -24,10 +24,13 @@ export const processLogsPanelReducer = (state = initialState, action: ProcessLog
             selectedFilter
         }),
         ADD_PROCESS_LOGS_PANEL_ITEM: ({ logType, log }) => {
+            const filters = state.filters.indexOf(logType) > -1
+                ? state.filters
+                : [...state.filters, logType];
             const currentLogs = state.logs[logType] || [];
             const logsOfType = [...currentLogs, log];
             const logs = { ...state.logs, [logType]: logsOfType };
-            return { ...state, logs };
+            return { ...state, logs, filters };
         },
         default: () => state,
     });