19851: Uses API.MaxItemsPerResponse setting for log requests.
authorLucas Di Pentima <lucas.dipentima@curii.com>
Tue, 13 Dec 2022 17:55:16 +0000 (18:55 +0100)
committerLucas Di Pentima <lucas.dipentima@curii.com>
Tue, 13 Dec 2022 17:55:16 +0000 (18:55 +0100)
Also, count=none on the 2nd request for better performance.

Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas.dipentima@curii.com>

src/common/config.ts
src/store/process-logs-panel/process-logs-panel-actions.ts

index 574445df09b05f5f47a8b0b57fc190352a8e1237..65ee687c0d64b73109f2de477db6dc09945b80e5 100644 (file)
@@ -15,6 +15,7 @@ interface WorkbenchConfig {
 export interface ClusterConfigJSON {
     API: {
         UnfreezeProjectRequiresAdmin: boolean
+        MaxItemsPerResponse: number
     },
     ClusterID: string;
     RemoteClusters: {
@@ -227,6 +228,7 @@ export const mapRemoteHosts = (clusterConfigJSON: ClusterConfigJSON, config: Con
 export const mockClusterConfigJSON = (config: Partial<ClusterConfigJSON>): ClusterConfigJSON => ({
     API: {
         UnfreezeProjectRequiresAdmin: false,
+        MaxItemsPerResponse: 1000,
     },
     ClusterID: "",
     RemoteClusters: {},
index e0db51f8bdfc01edfe1ae3ff06205fc90af947d7..e0f5a14e2e716361f30e8855f3c99265dff8eed2 100644 (file)
@@ -34,8 +34,9 @@ export const initProcessLogsPanel = (processUuid: string) =>
     async (dispatch: Dispatch, getState: () => RootState, { logService }: ServiceRepository) => {
         dispatch(processLogsPanelActions.RESET_PROCESS_LOGS_PANEL());
         const process = getProcess(processUuid)(getState().resources);
+        const maxPageSize = getState().auth.config.clusterConfig.API.MaxItemsPerResponse;
         if (process && process.container) {
-            const logResources = await loadContainerLogs(process.container.uuid, logService);
+            const logResources = await loadContainerLogs(process.container.uuid, logService, maxPageSize);
             const initialState = createInitialLogPanelState(logResources);
             dispatch(processLogsPanelActions.INIT_PROCESS_LOGS_PANEL(initialState));
         }
@@ -69,7 +70,7 @@ export const addProcessLogsPanelItem = (message: ResourceEventMessage<{ text: st
         }
     };
 
-const loadContainerLogs = async (containerUuid: string, logService: LogService) => {
+const loadContainerLogs = async (containerUuid: string, logService: LogService, maxPageSize: number) => {
     const requestFilters = new FilterBuilder()
         .addEqual('object_uuid', containerUuid)
         .addIn('event_type', PROCESS_PANEL_LOG_EVENT_TYPES)
@@ -81,20 +82,21 @@ const loadContainerLogs = async (containerUuid: string, logService: LogService)
         .addDesc('eventAt')
         .getOrder();
     const { items, itemsAvailable } = await logService.list({
-        limit: MAX_PAGE_SIZE,
+        limit: maxPageSize,
         filters: requestFilters,
         order: requestOrderAsc,
     });
 
-    // Request the remaining, or the last 1000 logs if necessary
-    const remainingLogs = itemsAvailable - MAX_PAGE_SIZE;
+    // Request the remaining, or the last 'maxPageSize' logs if necessary
+    const remainingLogs = itemsAvailable - maxPageSize;
     if (remainingLogs > 0) {
         const { items: itemsLast } = await logService.list({
-            limit: min([MAX_PAGE_SIZE, remainingLogs]),
+            limit: min([maxPageSize, remainingLogs]),
             filters: requestFilters,
             order: requestOrderDesc,
+            count: 'none',
         })
-        if (remainingLogs > MAX_PAGE_SIZE) {
+        if (remainingLogs > maxPageSize) {
             const snipLine = {
                 ...items[items.length - 1],
                 eventType: LogEventType.SNIP,
@@ -147,8 +149,6 @@ export const navigateToLogCollection = (uuid: string) =>
         }
     };
 
-const MAX_PAGE_SIZE = 1000;
-
 const ALL_FILTER_TYPE = 'All logs';
 
 const MAIN_FILTER_TYPE = 'Main logs';