This is an automated email from the ASF dual-hosted git repository.
jscheffl pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 91ea7fc81c Skip highlighting lines that contain log group markers.
(#41222)
91ea7fc81c is described below
commit 91ea7fc81c002232a6f533088f6a961a36b7275a
Author: Karthikeyan Singaravelan <[email protected]>
AuthorDate: Wed Aug 7 00:17:04 2024 +0530
Skip highlighting lines that contain log group markers. (#41222)
* Skip highlighting lines that contain log group markers.
* Use regex instead of substring match.
---
.../js/dag/details/taskInstance/Logs/utils.ts | 19 +++++-----
airflow/www/static/js/utils/index.test.ts | 42 +++++++++++++++++++---
airflow/www/static/js/utils/index.ts | 9 ++++-
3 files changed, 57 insertions(+), 13 deletions(-)
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 49e922a91d..2123f48001 100644
--- a/airflow/www/static/js/dag/details/taskInstance/Logs/utils.ts
+++ b/airflow/www/static/js/dag/details/taskInstance/Logs/utils.ts
@@ -48,6 +48,14 @@ const warningKeywords =
getMetaValue("color_log_warning_keywords")
.filter((keyword) => keyword.length > 0)
.map((keyword) => keyword.toLowerCase());
+// 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
+// Or in ADO pipeline like format '##[group]<group name>' to '##[endgroup]'
+// see
https://learn.microsoft.com/en-us/azure/devops/pipelines/scripts/logging-commands?view=azure-devops&tabs=powershell#formatting-commands
+export const logGroupStart = / INFO - (::|##\[])group(::|\])([^\n])*/g;
+export const logGroupEnd = / INFO - (::|##\[])endgroup(::|\])/g;
+
export const parseLogs = (
data: string | undefined,
timezone: string | null,
@@ -75,13 +83,6 @@ export const parseLogs = (
ansiUp.url_allowlist = {};
const urlRegex = /((https?:\/\/|http:\/\/)(?:(?!'|")[^\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
- // Or in ADO pipeline like format '##[group]<group name>' to '##[endgroup]'
- // see
https://learn.microsoft.com/en-us/azure/devops/pipelines/scripts/logging-commands?view=azure-devops&tabs=powershell#formatting-commands
- const logGroupStart = / INFO - (::|##\[])group(::|\])([^\n])*/g;
- const logGroupEnd = / INFO - (::|##\[])endgroup(::|\])/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;";
@@ -125,7 +126,9 @@ export const parseLogs = (
parsedLine = highlightByKeywords(
parsedLine,
errorKeywords,
- warningKeywords
+ warningKeywords,
+ logGroupStart,
+ logGroupEnd
);
// for lines with color convert to nice HTML
const coloredLine = ansiUp.ansi_to_html(parsedLine);
diff --git a/airflow/www/static/js/utils/index.test.ts
b/airflow/www/static/js/utils/index.test.ts
index aba3312bfb..a12f66b36c 100644
--- a/airflow/www/static/js/utils/index.test.ts
+++ b/airflow/www/static/js/utils/index.test.ts
@@ -25,6 +25,10 @@ import {
getTaskSummary,
highlightByKeywords,
} from ".";
+import {
+ logGroupStart,
+ logGroupEnd,
+} from "../dag/details/taskInstance/Logs/utils";
const sampleTasks = {
id: null,
@@ -160,7 +164,9 @@ describe("Test highlightByKeywords", () => {
const highlightedLine = highlightByKeywords(
originalLine,
["error"],
- ["warn"]
+ ["warn"],
+ logGroupStart,
+ logGroupEnd
);
expect(highlightedLine).toBe(expected);
});
@@ -170,7 +176,9 @@ describe("Test highlightByKeywords", () => {
const highlightedLine = highlightByKeywords(
originalLine,
["error"],
- ["warn"]
+ ["warn"],
+ logGroupStart,
+ logGroupEnd
);
expect(highlightedLine).toBe(expected);
});
@@ -180,16 +188,42 @@ describe("Test highlightByKeywords", () => {
const highlightedLine = highlightByKeywords(
originalLine,
["error"],
- ["warn"]
+ ["warn"],
+ logGroupStart,
+ logGroupEnd
);
expect(highlightedLine).toBe(expected);
});
+ test("No highlight for line with start log marker", async () => {
+ const originalLine = " INFO - ::group::error";
+ const highlightedLine = highlightByKeywords(
+ originalLine,
+ ["error"],
+ ["warn"],
+ logGroupStart,
+ logGroupEnd
+ );
+ expect(highlightedLine).toBe(originalLine);
+ });
+ test("No highlight for line with end log marker", async () => {
+ const originalLine = " INFO - ::endgroup::";
+ const highlightedLine = highlightByKeywords(
+ originalLine,
+ ["endgroup"],
+ ["warn"],
+ logGroupStart,
+ logGroupEnd
+ );
+ expect(highlightedLine).toBe(originalLine);
+ });
test("No highlight", async () => {
const originalLine = "sample line";
const highlightedLine = highlightByKeywords(
originalLine,
["error"],
- ["warn"]
+ ["warn"],
+ logGroupStart,
+ logGroupEnd
);
expect(highlightedLine).toBe(originalLine);
});
diff --git a/airflow/www/static/js/utils/index.ts
b/airflow/www/static/js/utils/index.ts
index ff887b8569..747ca474c7 100644
--- a/airflow/www/static/js/utils/index.ts
+++ b/airflow/www/static/js/utils/index.ts
@@ -188,8 +188,15 @@ const toSentenceCase = (camelCase: string): string => {
const highlightByKeywords = (
parsedLine: string,
errorKeywords: string[],
- warningKeywords: string[]
+ warningKeywords: string[],
+ logGroupStart: RegExp,
+ logGroupEnd: RegExp
): string => {
+ // Don't color log marker lines that are already highlighted.
+ if (logGroupStart.test(parsedLine) || logGroupEnd.test(parsedLine)) {
+ return parsedLine;
+ }
+
const lowerParsedLine = parsedLine.toLowerCase();
const red = (line: string) => `\x1b[1m\x1b[31m${line}\x1b[39m\x1b[0m`;
const yellow = (line: string) => `\x1b[1m\x1b[33m${line}\x1b[39m\x1b[0m`;