Skip to content

Commit

Permalink
Recognize quotes when parsing urls in logs (#40508)
Browse files Browse the repository at this point in the history

---------

Co-authored-by: Jacob Lee <seungmin_lee3@apple.com>
  • Loading branch information
smlee729 and Jacob Lee authored Jul 2, 2024
1 parent eb3e199 commit 2f9b23d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
25 changes: 22 additions & 3 deletions airflow/www/static/js/dag/details/taskInstance/Logs/utils.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +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"
`;

describe("Test Logs Utils.", () => {
Expand All @@ -64,7 +65,7 @@ describe("Test Logs Utils.", () => {
test.each([
{
logLevelFilters: [LogLevel.INFO],
expectedNumberOfLines: 11,
expectedNumberOfLines: 12,
expectedNumberOfFileSources: 4,
},
{
Expand Down Expand Up @@ -111,7 +112,7 @@ describe("Test Logs Utils.", () => {
"taskinstance.py",
]);
const lines = parsedLogs!.split("\n");
expect(lines).toHaveLength(7);
expect(lines).toHaveLength(8);
lines.forEach((line) => expect(line).toContain("taskinstance.py"));
});

Expand All @@ -131,7 +132,25 @@ describe("Test Logs Utils.", () => {
"taskinstance.py",
]);
const lines = parsedLogs!.split("\n");
expect(lines).toHaveLength(7);
expect(lines).toHaveLength(8);
lines.forEach((line) => expect(line).toMatch(/INFO|WARNING/));
});

test("parseLogs function with quoted urls", () => {
const { parsedLogs } = parseLogs(
mockTaskLog,
null,
[LogLevel.INFO, LogLevel.WARNING],
["taskinstance.py"],
[]
);

const lines = parsedLogs!.split("\n");
expect(lines[lines.length - 1]).toContain(
'<a href="https://apple.com" target="_blank" style="color: blue; text-decoration: underline;">https://apple.com</a>'
);
expect(lines[lines.length - 1]).toContain(
'<a href="https://google.com" target="_blank" style="color: blue; text-decoration: underline;">https://google.com</a>'
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const parseLogs = (
const ansiUp = new AnsiUp();
ansiUp.url_allowlist = {};

const urlRegex = /((https?:\/\/|http:\/\/)[^\s]+)/g;
const urlRegex = /((https?:\/\/|http:\/\/)(?:(?!&#x27;|&quot;)[^\s])+)/g;
// Detect log groups which can be collapsed
// Either in Github like format '::group::<group name>' to '::endgroup::'
// see https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#grouping-log-lines
Expand Down

0 comments on commit 2f9b23d

Please sign in to comment.