-
Notifications
You must be signed in to change notification settings - Fork 14.5k
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
Add %z for %(asctime)s to fix timezone for logs on UI #24373
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d589b9d
Fix #23796 by adding %z in %(asctime)s
rino0601 72f2cd4
fulfil static test
rino0601 53f24d3
fix regex to support backward compatibility
rino0601 d5b31cc
Make log_formatter_class configurable
rino0601 4668c65
fix grid view ui to understand timezone aware log
rino0601 02eed05
Attach newsfragments
rino0601 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
import logging | ||
|
||
|
||
class TimezoneAware(logging.Formatter): | ||
""" | ||
Override `default_time_format` and `default_msec_format` to specify utc offset. | ||
|
||
utc offset is the matter, without it, time conversion could be wrong. With this Formatter, `%(asctime)s` | ||
will be formatted containing utc offset. (e.g. 2022-06-12 13:00:00+0000 123ms) | ||
|
||
moments.js couldn't parse milliseconds comes after utc offset, so it would be ideal `%(asctime)s` | ||
formatted with millisecond comes before utc offset in th first place. (e.g 2022-06-12 13:00:00.123+0000) | ||
But python standard lib doesn't support format like that. | ||
|
||
Omitting milliseconds is possible by assigning `default_msec_format` to `None`. But this requires | ||
python3.9 or higher, so we can't omit milliseconds until dropping support 3.8 or under. | ||
|
||
Therefore, to use in moments.js, formatted `%(asctime)s` has to be re-formatted by javascript side. | ||
""" | ||
|
||
default_time_format = '%Y-%m-%d %H:%M:%S%z' | ||
default_msec_format = '%s %03dms' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Added new config ``[logging]log_formatter_class`` to fix timezone display for logs on UI | ||
|
||
If you are using a custom Formatter subclass in your ``[logging]logging_config_class``, please inherit from ``airflow.utils.log.timezone_aware.TimezoneAware`` instead of ``logging.Formatter``. | ||
For example, in your ``custom_config.py``: | ||
|
||
.. code-block:: python | ||
|
||
from airflow.utils.log.timezone_aware import TimezoneAware | ||
|
||
# before | ||
class YourCustomFormatter(logging.Formatter): | ||
... | ||
|
||
|
||
# after | ||
class YourCustomFormatter(TimezoneAware): | ||
... | ||
|
||
|
||
AIRFLOW_FORMATTER = LOGGING_CONFIG["formatters"]["airflow"] | ||
AIRFLOW_FORMATTER["class"] = "somewhere.your.custom_config.YourCustomFormatter" | ||
# or use TimezoneAware class directly. If you don't have custom Formatter. | ||
AIRFLOW_FORMATTER["class"] = "airflow.utils.log.timezone_aware.TimezoneAware" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we adding milliseconds to this PR? I don't think the logs showed ms before...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bbovenzi
The original value before override in this part is
%s,%03d
.If left as is, the file will have something like
2022-06-14 06:00:00-0600,123
which is a bit awkward. Also, it's in a format that moments.js doesn't understand.It would be ideal to have a format like
2022-06-14 06:00:00,123-0600
, but that would be a very difficult because it would have to modify the standard library.There are 3 ways to solve this problem:
default_msec_format
toNone
, but this requires python3.9 or higher. Dropping 3.7 and 3.8 because of this small change is ridiculous. so this is not an option. (if there is a way to consume an argument in the %-format but not print it, we can do this without dropping 3.7 and 3.8. but I don't think such a method exists.)-0600 123ms
is easier to understand than-0600,123
.Previously, milliseconds was not shown because it was discarded from the format of moments.js added on August 3, 2018. While searching for this, I found that the most recently added format (presumably used in grid views) uses milliseconds. Based on this, I guessed that there is a demand for milliseconds.
If you think displaying milliseconds is too verbose, I'll edit the code to use the second method. However, the regular expression become a bit more complicated than it is now, and code of replaceAll become getting the milliseconds value and then ignoring it. This can be awkward code for anyone who hasn't read the conversation in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should send the date to the UI that moment can parse. But that is annoying if it's non-trivial. We can go with this for now. But we should get that single log parsing function soon so the gird view keeps this in consideration too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bbovenzi
After I git rebase onto main:
It would be desirable to fix it in this PR because it takes more effort to find and process it later. so I've spend some times try to fix it. it seems that if I fix the regular expression in
grid/details/content/taskInstance/Logs/utils.js
I can fix it for now, but if I do, as you concerned, we will have two log parsers.Then I stopped trying, to ask you comment. Also, my front-end knowledge is frozen in the days of react15, so I need some time to review if I understand the grid code properly.
Anyway,
I wonder if logs in the grid view feature will be released in 2.3 or 2.4.
If it's going to be released in 2.4, so if this PR also has to go out in 2.4 too, I'd like to know in advance.
I'm using 1.10.15 at work, and dozens of instances are stuck with that version. I recently migrated one instance to 2.3.2 as a pilot. Then I discovered this time zone problem. Therefore, other instances are waiting for the result of this PR.
My co-worker's previous contribution was classified as a minor release, it took 5 months to release. If this PR is going to be classified as minor release, I would like to say "migrate now (with workaround config)" to my colleagues because I can guess that it will be released in a few months.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Go ahead and do the simple fix for now. I'm happy to help out combine them into a single parser in a subsequent PR. I think for this change we can target 2.3.3, so it shouldn't be months.