This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch v2-10-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/v2-10-test by this push:
new 5371ffc67f4 Fix details tab log url detection (#42104) (#42114)
5371ffc67f4 is described below
commit 5371ffc67f41f73c1aa92227f1a25411a2ff5838
Author: Pierre Jeambrun <[email protected]>
AuthorDate: Tue Sep 10 00:44:04 2024 +0800
Fix details tab log url detection (#42104) (#42114)
* Fix details tab log url detection
* Add test
(cherry picked from commit b5439323927d81270db0a957a9e1c27dbbfe720b)
---
airflow/www/static/js/dag/details/taskInstance/Logs/utils.test.tsx | 7 +++++--
airflow/www/static/js/dag/details/taskInstance/Logs/utils.ts | 6 ++++--
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/airflow/www/static/js/dag/details/taskInstance/Logs/utils.test.tsx
b/airflow/www/static/js/dag/details/taskInstance/Logs/utils.test.tsx
index ce6b082cb19..8e577068d27 100644
--- a/airflow/www/static/js/dag/details/taskInstance/Logs/utils.test.tsx
+++ b/airflow/www/static/js/dag/details/taskInstance/Logs/utils.test.tsx
@@ -38,7 +38,7 @@ const mockTaskLog = `
[2022-06-04 00:00:01,921] {dagbag.py:507} INFO - Filling up the DagBag from
/files/dags/test_ui_grid.py
[2022-06-04 00:00:01,964] {task_command.py:377} INFO - Running <TaskInstance:
test_ui_grid.section_1.get_entry_group scheduled__2022-06-03T00:00:00+00:00
[running]> on host 5d28cfda3219
[2022-06-04 00:00:02,010] {taskinstance.py:1548} WARNING - Exporting env vars:
AIRFLOW_CTX_DAG_OWNER=*** AIRFLOW_CTX_DAG_ID=test_ui_grid
-[2024-07-01 00:00:02,010] {taskinstance.py:1548} INFO - Url parsing test =>
"https://apple.com", "https://google.com"
+[2024-07-01 00:00:02,010] {taskinstance.py:1548} INFO - Url parsing test =>
"https://apple.com", "https://google.com",
https://something.logs/_dashboard/?_g=(filters:!(),refreshInterval:(pause:!t,value:0),time:(from:now-1d,to:now))&_a=(columns:!(_source),filters:!(('$state':(store:appState))))
`;
describe("Test Logs Utils.", () => {
@@ -136,7 +136,7 @@ describe("Test Logs Utils.", () => {
lines.forEach((line) => expect(line).toMatch(/INFO|WARNING/));
});
- test("parseLogs function with quoted urls", () => {
+ test("parseLogs function with urls", () => {
const { parsedLogs } = parseLogs(
mockTaskLog,
null,
@@ -152,5 +152,8 @@ describe("Test Logs Utils.", () => {
expect(lines[lines.length - 1]).toContain(
'<a href="https://google.com" target="_blank" rel="noopener noreferrer"
style="color: blue; text-decoration: underline;">https://google.com</a>'
);
+ expect(lines[lines.length - 1]).toContain(
+ '<a
href="https://something.logs/_dashboard/?_g=(filters:!(),refreshInterval:(pause:!t,value:0),time:(from:now-1d,to:now))&_a=(columns:!(_source),filters:!(('$state':(store:appState))))"
target="_blank" rel="noopener noreferrer" style="color: blue; text-decoration:
underline;">https://something.logs/_dashboard/?_g=(filters:!(),refreshInterval:(pause:!t,value:0),time:(from:now-1d,to:now))&_a=(columns:!(_source),filters:!(('$state':(store:appState))))</a>'
+ );
});
});
diff --git a/airflow/www/static/js/dag/details/taskInstance/Logs/utils.ts
b/airflow/www/static/js/dag/details/taskInstance/Logs/utils.ts
index 4be81a6d0cb..f5340f0afb8 100644
--- a/airflow/www/static/js/dag/details/taskInstance/Logs/utils.ts
+++ b/airflow/www/static/js/dag/details/taskInstance/Logs/utils.ts
@@ -82,7 +82,8 @@ export const parseLogs = (
const ansiUp = new AnsiUp();
ansiUp.url_allowlist = {};
- const urlRegex = /((https?:\/\/|http:\/\/)(?:(?!'|")[^\s])+)/g;
+ const urlRegex =
+
/http(s)?:\/\/[\w.-]+(\.?:[\w.-]+)*([/?#][\w\-._~:/?#[\]@!$&'()*+,;=.%]+)?/g;
// Coloring (blue-60 as chakra style, is #0060df) and style such that log
group appears like a link
const logGroupStyle = "color:#0060df;cursor:pointer;font-weight:bold;";
@@ -137,7 +138,8 @@ export const parseLogs = (
const lineWithHyperlinks = coloredLine
.replace(
urlRegex,
- '<a href="$1" target="_blank" rel="noopener noreferrer"
style="color: blue; text-decoration: underline;">$1</a>'
+ (url) =>
+ `<a href="${url}" target="_blank" rel="noopener noreferrer"
style="color: blue; text-decoration: underline;">${url}</a>`
)
.replace(logGroupStart, (textLine) => {
const unfoldIdSuffix = "_unfold";