-
Notifications
You must be signed in to change notification settings - Fork 13.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add XCom tab to Grid #35719
Merged
Merged
Add XCom tab to Grid #35719
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
05de510
Add XCom tab to Grid
hduong-mwam 170847b
Combine showLogs and showXcom logic evaluation to isIndividualTaskIns…
hduong-mwam 824049d
Remove link to /xcom page from UI grid view
hduong-mwam b2b6fab
Use consistent naming to distinguish XcomCollection and XcomEntry
hduong-mwam fec1bae
Refactor boolean vars
hduong-mwam File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/*! | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import type { API } from "src/types"; | ||
import { getMetaValue } from "src/utils"; | ||
import { useQuery } from "react-query"; | ||
import axios, { AxiosResponse } from "axios"; | ||
|
||
// tryNumber is not required to get XCom keys or values but is used | ||
// in query key so refetch will occur if new tries are available | ||
interface TaskXcomCollectionProps extends API.GetXcomEntriesVariables { | ||
tryNumber: number; | ||
} | ||
interface TaskXcomProps extends API.GetXcomEntryVariables { | ||
tryNumber: number; | ||
} | ||
|
||
export const useTaskXcomCollection = ({ | ||
dagId, | ||
dagRunId, | ||
taskId, | ||
mapIndex, | ||
tryNumber, | ||
}: TaskXcomCollectionProps) => | ||
useQuery(["taskXcoms", dagId, dagRunId, taskId, mapIndex, tryNumber], () => | ||
axios.get<AxiosResponse, API.XComCollection>( | ||
getMetaValue("task_xcom_entries_api") | ||
.replace("_DAG_RUN_ID_", dagRunId) | ||
.replace("_TASK_ID_", taskId), | ||
{ params: { map_index: mapIndex } } | ||
) | ||
); | ||
|
||
export const useTaskXcomEntry = ({ | ||
dagId, | ||
dagRunId, | ||
taskId, | ||
mapIndex, | ||
xcomKey, | ||
tryNumber, | ||
}: TaskXcomProps) => | ||
useQuery( | ||
["taskXcom", dagId, dagRunId, taskId, mapIndex, xcomKey, tryNumber], | ||
() => | ||
axios.get<AxiosResponse, API.XCom>( | ||
getMetaValue("task_xcom_entry_api") | ||
.replace("_DAG_RUN_ID_", dagRunId) | ||
.replace("_TASK_ID_", taskId) | ||
.replace("_XCOM_KEY_", xcomKey), | ||
{ params: { map_index: mapIndex } } | ||
), | ||
{ | ||
enabled: !!xcomKey, | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
airflow/www/static/js/dag/details/taskInstance/Xcom/XcomEntry.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/*! | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { Alert, AlertIcon, Spinner, Td, Text, Tr } from "@chakra-ui/react"; | ||
import React from "react"; | ||
import { useTaskXcomEntry } from "src/api"; | ||
import type { Dag, DagRun, TaskInstance } from "src/types"; | ||
|
||
interface Props { | ||
dagId: Dag["id"]; | ||
dagRunId: DagRun["runId"]; | ||
taskId: TaskInstance["taskId"]; | ||
mapIndex?: TaskInstance["mapIndex"]; | ||
xcomKey: string; | ||
tryNumber: TaskInstance["tryNumber"]; | ||
} | ||
|
||
const XcomEntry = ({ | ||
dagId, | ||
dagRunId, | ||
taskId, | ||
mapIndex, | ||
xcomKey, | ||
tryNumber, | ||
}: Props) => { | ||
const { | ||
data: xcom, | ||
isLoading, | ||
error, | ||
} = useTaskXcomEntry({ | ||
dagId, | ||
dagRunId, | ||
taskId, | ||
mapIndex, | ||
xcomKey, | ||
tryNumber: tryNumber || 1, | ||
}); | ||
|
||
let content = <Text fontFamily="monospace">{xcom?.value}</Text>; | ||
if (isLoading) { | ||
content = <Spinner />; | ||
} else if (error) { | ||
content = ( | ||
<Alert status="error"> | ||
<AlertIcon /> | ||
Error loading XCom entry | ||
</Alert> | ||
); | ||
} else if (!xcom) { | ||
content = ( | ||
<Alert status="info"> | ||
<AlertIcon /> | ||
No value found for XCom key | ||
</Alert> | ||
); | ||
} | ||
|
||
return ( | ||
<Tr> | ||
<Td>{xcomKey}</Td> | ||
<Td>{content}</Td> | ||
</Tr> | ||
); | ||
}; | ||
|
||
export default XcomEntry; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you test this with an extremely large json text blob?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested with 49344 bytes of lorem ipsum generated from https://www.lipsum.com/ and it seems to render out fine. Do you think this is a reasonable test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's good but do you mind putting in a check to see if the value is valid json and then we can format it accordingly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I am afraid I am not following. In my test, I just have a task which returns this dict
{"long_string": "Lorem..."}
. This results in two XCom entries:long_string
:Lorem...
return_value
:{"long_string": "Lorem..."}
Do you mean check that the entry value is a valid JSON and format that? I personally haven't have a use-case that I return an entry that is a JSON but instead if the task returns a dict then I can access the attributes as keys (if that makes sense)
Keyed portion
Full return_value portion
(Apologies for the handwriting 😄) Here is an example of shorter XCom but with many keys to illustrate my point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the table showing key and value as separate columns. I meant to say that we could try to check if the value follows any forma and then render it accordingly. It's an additional nice-to-have. We can do it in another PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I get you. Would be a nice addition for sure