This is an automated email from the ASF dual-hosted git repository. ephraimanierobi pushed a commit to branch v2-4-test in repository https://gitbox.apache.org/repos/asf/airflow.git
commit 9c3ee045accbbef9f1b1bbee523d86afbf57e6c1 Author: Brent Bovenzi <[email protected]> AuthorDate: Tue Oct 25 10:26:23 2022 -0400 reduce extraneous task log requests (#27233) (cherry picked from commit e73e90e388f7916ae5eea48ba39687d99f7a94b1) --- airflow/www/static/js/api/useTaskLog.ts | 23 +++++++++++++++++----- .../js/dag/details/taskInstance/Logs/index.tsx | 4 +++- .../static/js/dag/details/taskInstance/index.tsx | 3 ++- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/airflow/www/static/js/api/useTaskLog.ts b/airflow/www/static/js/api/useTaskLog.ts index 1c8b999de8..580c5e0ab4 100644 --- a/airflow/www/static/js/api/useTaskLog.ts +++ b/airflow/www/static/js/api/useTaskLog.ts @@ -20,15 +20,19 @@ import axios, { AxiosResponse } from 'axios'; import { useQuery } from 'react-query'; import { useAutoRefresh } from 'src/context/autorefresh'; -import type { API } from 'src/types'; +import type { API, TaskInstance } from 'src/types'; import { getMetaValue } from 'src/utils'; const taskLogApi = getMetaValue('task_log_api'); +interface Props extends API.GetLogVariables { + state?: TaskInstance['state']; +} + const useTaskLog = ({ - dagId, dagRunId, taskId, taskTryNumber, mapIndex, fullContent, -}: API.GetLogVariables) => { + dagId, dagRunId, taskId, taskTryNumber, mapIndex, fullContent, state, +}: Props) => { let url: string = ''; if (taskLogApi) { url = taskLogApi.replace('_DAG_RUN_ID_', dagRunId).replace('_TASK_ID_', taskId).replace(/-1$/, taskTryNumber.toString()); @@ -36,12 +40,21 @@ const useTaskLog = ({ const { isRefreshOn } = useAutoRefresh(); + // Only refresh is the state is pending + const isStatePending = state === 'deferred' + || state === 'scheduled' + || state === 'running' + || state === 'up_for_reschedule' + || state === 'up_for_retry' + || state === 'queued' + || state === 'restarting'; + return useQuery( - ['taskLogs', dagId, dagRunId, taskId, mapIndex, taskTryNumber, fullContent], + ['taskLogs', dagId, dagRunId, taskId, mapIndex, taskTryNumber, fullContent, state], () => axios.get<AxiosResponse, string>(url, { headers: { Accept: 'text/plain' }, params: { map_index: mapIndex, full_content: fullContent } }), { placeholderData: '', - refetchInterval: isRefreshOn && (autoRefreshInterval || 1) * 1000, + refetchInterval: isStatePending && isRefreshOn && (autoRefreshInterval || 1) * 1000, }, ); }; diff --git a/airflow/www/static/js/dag/details/taskInstance/Logs/index.tsx b/airflow/www/static/js/dag/details/taskInstance/Logs/index.tsx index 8b35c3bc3a..ec6249cb27 100644 --- a/airflow/www/static/js/dag/details/taskInstance/Logs/index.tsx +++ b/airflow/www/static/js/dag/details/taskInstance/Logs/index.tsx @@ -87,6 +87,7 @@ interface Props { mapIndex?: TaskInstance['mapIndex']; executionDate: DagRun['executionDate']; tryNumber: TaskInstance['tryNumber']; + state?: TaskInstance['state']; } const Logs = ({ @@ -96,6 +97,7 @@ const Logs = ({ mapIndex, executionDate, tryNumber, + state, }: Props) => { const [internalIndexes, externalIndexes] = getLinkIndexes(tryNumber); const [selectedTryNumber, setSelectedTryNumber] = useState<number | undefined>(); @@ -105,7 +107,6 @@ const Logs = ({ const [fileSourceFilters, setFileSourceFilters] = useState<Array<FileSourceOption>>([]); const { timezone } = useTimezone(); - // const taskTryNumber = selectedTryNumber || tryNumber || 1; const { data, isSuccess } = useTaskLog({ dagId, @@ -114,6 +115,7 @@ const Logs = ({ mapIndex, taskTryNumber, fullContent: shouldRequestFullContent, + state, }); const params = new URLSearchParamsWrapper({ diff --git a/airflow/www/static/js/dag/details/taskInstance/index.tsx b/airflow/www/static/js/dag/details/taskInstance/index.tsx index fd6a59c8ba..0061be5983 100644 --- a/airflow/www/static/js/dag/details/taskInstance/index.tsx +++ b/airflow/www/static/js/dag/details/taskInstance/index.tsx @@ -124,7 +124,7 @@ const TaskInstance = ({ operator={operator} /> )} - <Tabs size="lg" index={selectedTabIndex} onChange={handleTabsChange}> + <Tabs size="lg" index={selectedTabIndex} onChange={handleTabsChange} isLazy> <TabList> <Tab> <Text as="strong">Details</Text> @@ -183,6 +183,7 @@ const TaskInstance = ({ mapIndex={mapIndex} executionDate={executionDate} tryNumber={instance?.tryNumber} + state={instance?.state} /> </TabPanel> )}
