Skip to content
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

Revert "Add %z for %(asctime)s to fix timezone for logs on UI (#24373)" #24810

Merged
merged 1 commit into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions airflow/config_templates/airflow_local_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,13 @@
# settings.py and cli.py. Please see AIRFLOW-1455.
LOG_LEVEL: str = conf.get_mandatory_value('logging', 'LOGGING_LEVEL').upper()


# Flask appbuilder's info level log is very verbose,
# so it's set to 'WARN' by default.
FAB_LOG_LEVEL: str = conf.get_mandatory_value('logging', 'FAB_LOGGING_LEVEL').upper()

LOG_FORMAT: str = conf.get_mandatory_value('logging', 'LOG_FORMAT')

LOG_FORMATTER_CLASS: str = conf.get_mandatory_value(
'logging', 'LOG_FORMATTER_CLASS', fallback='airflow.utils.log.timezone_aware.TimezoneAware'
)

COLORED_LOG_FORMAT: str = conf.get_mandatory_value('logging', 'COLORED_LOG_FORMAT')

COLORED_LOG: bool = conf.getboolean('logging', 'COLORED_CONSOLE_LOG')
Expand All @@ -63,13 +60,10 @@
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'airflow': {
'format': LOG_FORMAT,
'class': LOG_FORMATTER_CLASS,
},
'airflow': {'format': LOG_FORMAT},
'airflow_coloured': {
'format': COLORED_LOG_FORMAT if COLORED_LOG else LOG_FORMAT,
'class': COLORED_FORMATTER_CLASS if COLORED_LOG else LOG_FORMATTER_CLASS,
'class': COLORED_FORMATTER_CLASS if COLORED_LOG else 'logging.Formatter',
},
},
'filters': {
Expand Down
6 changes: 0 additions & 6 deletions airflow/config_templates/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -633,12 +633,6 @@
type: string
example: ~
default: "%%(asctime)s %%(levelname)s - %%(message)s"
- name: log_formatter_class
description: ~
version_added: 2.3.3
type: string
example: ~
default: "airflow.utils.log.timezone_aware.TimezoneAware"
- name: task_log_prefix_template
description: |
Specify prefix pattern like mentioned below with stream handler TaskHandlerWithCustomFormatter
Expand Down
1 change: 0 additions & 1 deletion airflow/config_templates/default_airflow.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ colored_formatter_class = airflow.utils.log.colored_log.CustomTTYColoredFormatte
# Format of Log line
log_format = [%%(asctime)s] {{%%(filename)s:%%(lineno)d}} %%(levelname)s - %%(message)s
simple_log_format = %%(asctime)s %%(levelname)s - %%(message)s
log_formatter_class = airflow.utils.log.timezone_aware.TimezoneAware

# Specify prefix pattern like mentioned below with stream handler TaskHandlerWithCustomFormatter
# Example: task_log_prefix_template = {{ti.dag_id}}-{{ti.task_id}}-{{execution_date}}-{{try_number}}
Expand Down
4 changes: 0 additions & 4 deletions airflow/utils/log/colored_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ class CustomTTYColoredFormatter(TTYColoredFormatter):
traceback.
"""

# copy of airflow.utils.log.timezone_aware.TimezoneAware
default_time_format = '%Y-%m-%d %H:%M:%S%z'
default_msec_format = '%s %03dms'

def __init__(self, *args, **kwargs):
kwargs["stream"] = sys.stdout or kwargs.get("stream")
kwargs["log_colors"] = DEFAULT_COLORS
Expand Down
39 changes: 0 additions & 39 deletions airflow/utils/log/timezone_aware.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -61,41 +61,18 @@ export const parseLogs = (
}

const regExp = /\[(.*?)\] \{(.*?)\}/;
// e.g) '2022-06-15 10:30:06,020' or '2022-06-15 10:30:06+0900'
const dateRegex = /(\d{4}[./-]\d{2}[./-]\d{2} \d{2}:\d{2}:\d{2})((,\d{3})|([+-]\d{4} \d{3}ms))/;
// above regex is a kind of duplication of 'dateRegex'
// in airflow/www/static/js/tl_log.js
const matches = line.match(regExp);
let logGroup = '';
if (matches) {
// Replace system timezone with user selected timezone.
// Replace UTC with the local timezone.
const dateTime = matches[1];

// e.g) '2022-06-15 10:30:06,020' or '2022-06-15 10:30:06+0900 123ms'
const dateMatches = dateTime?.match(dateRegex);
if (dateMatches) {
const [date, msecOrUTCOffset] = [dateMatches[1], dateMatches[2]];
if (msecOrUTCOffset.startsWith(',')) { // e.g) date='2022-06-15 10:30:06', msecOrUTCOffset=',020'
// for backward compatibility. (before 2.3.3)
// keep previous behavior if utcoffset not found. (consider it UTC)
//
if (dateTime && timezone) { // dateTime === fullMatch
// @ts-ignore
const localDateTime = moment.utc(dateTime).tz(timezone).format(defaultFormatWithTZ);
parsedLine = line.replace(dateTime, localDateTime);
}
} else {
// e.g) date='2022-06-15 10:30:06', msecOrUTCOffset='+0900 123ms'
// (formatted by airflow.utils.log.timezone_aware.TimezoneAware) (since 2.3.3)
const [utcoffset, threeDigitMs] = msecOrUTCOffset.split(' ');
const msec = threeDigitMs.replace(/\D+/g, ''); // drop 'ms'
// e.g) datetime='2022-06-15 10:30:06.123+0900'
// @ts-ignore
const localDateTime = moment(`${date}.${msec}${utcoffset}`).tz(timezone).format(defaultFormatWithTZ);
parsedLine = line.replace(dateTime, localDateTime);
}
}
[logGroup] = matches[2].split(':');
if (dateTime && timezone) {
// @ts-ignore
const localDateTime = moment.utc(dateTime).tz(timezone).format(defaultFormatWithTZ);
parsedLine = line.replace(dateTime, localDateTime);
}

fileSources.add(logGroup);
}

Expand Down
21 changes: 2 additions & 19 deletions airflow/www/static/js/ti_log.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ function autoTailingLog(tryNumber, metadata = null, autoTailing = false) {

// Detect urls and log timestamps
const urlRegex = /http(s)?:\/\/[\w.-]+(\.?:[\w.-]+)*([/?#][\w\-._~:/?#[\]@!$&'()*+,;=.%]+)?/g;
const dateRegex = /(\d{4}[./-]\d{2}[./-]\d{2} \d{2}:\d{2}:\d{2})((,\d{3})|([+-]\d{4} \d{3}ms))/g;
// above regex is a kind of duplication of 'dateRegex'
// in airflow/www/static/js/grid/details/content/taskinstance/Logs/utils.js
const dateRegex = /\d{4}[./-]\d{2}[./-]\d{2} \d{2}:\d{2}:\d{2},\d{3}/g;

res.message.forEach((item) => {
const logBlockElementId = `try-${tryNumber}-${item[0]}`;
Expand All @@ -122,22 +120,7 @@ function autoTailingLog(tryNumber, metadata = null, autoTailing = false) {
const escapedMessage = escapeHtml(item[1]);
const linkifiedMessage = escapedMessage
.replace(urlRegex, (url) => `<a href="${url}" target="_blank">${url}</a>`)
.replaceAll(dateRegex, (dateMatches, date, msecOrUTCOffset) => {
// e.g) '2022-06-15 10:30:06,020' or '2022-06-15 10:30:06+0900 123ms'
if (msecOrUTCOffset.startsWith(',')) { // e.g) date='2022-06-15 10:30:06', msecOrUTCOffset=',020'
// for backward compatibility. (before 2.3.3)
// keep previous behavior if utcoffset not found.
//
return `<time datetime="${dateMatches}+00:00" data-with-tz="true">${formatDateTime(`${dateMatches}+00:00`)}</time>`;
}
// e.g) date='2022-06-15 10:30:06', msecOrUTCOffset='+0900 123ms'
// (formatted by airflow.utils.log.timezone_aware.TimezoneAware) (since 2.3.3)
const [utcoffset, threeDigitMs] = msecOrUTCOffset.split(' ');
const msec = threeDigitMs.replace(/\D+/g, ''); // drop 'ms'
const dateTime = `${date}.${msec}${utcoffset}`; // e.g) datetime='2022-06-15 10:30:06.123+0900'
//
return `<time datetime="${dateTime}" data-with-tz="true">${formatDateTime(`${dateTime}`)}</time>`;
});
.replaceAll(dateRegex, (date) => `<time datetime="${date}+00:00" data-with-tz="true">${formatDateTime(`${date}+00:00`)}</time>`);
logBlock.innerHTML += `${linkifiedMessage}\n`;
});

Expand Down
23 changes: 0 additions & 23 deletions newsfragments/24373.significant.rst

This file was deleted.