Skip to content

Commit

Permalink
Fix details tab log url detection (apache#42104) (apache#42114)
Browse files Browse the repository at this point in the history
* Fix details tab log url detection

* Add test

(cherry picked from commit b543932)
  • Loading branch information
pierrejeambrun authored Sep 9, 2024
1 parent a8187d9 commit 5371ffc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.", () => {
Expand Down Expand Up @@ -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,
Expand All @@ -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))&amp;_a=(columns:!(_source),filters:!((&#x27;$state&#x27;:(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))&amp;_a=(columns:!(_source),filters:!((&#x27;$state&#x27;:(store:appState))))</a>'
);
});
});
6 changes: 4 additions & 2 deletions airflow/www/static/js/dag/details/taskInstance/Logs/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ export const parseLogs = (
const ansiUp = new AnsiUp();
ansiUp.url_allowlist = {};

const urlRegex = /((https?:\/\/|http:\/\/)(?:(?!&#x27;|&quot;)[^\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;";

Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit 5371ffc

Please sign in to comment.