-
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
Conversation
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
|
9633f50
to
1718474
Compare
cc: @uranusjr |
The logging side (Python) looks reasonable to me, thanks for the effort! On the JavaScript side though, I think we need some compatibiliy code to be able to deal with existing log files, which lack the timezone part. We probably should add some tests as well. (Do we have a mechanism to test non-React code now?) |
1718474
to
b09da7a
Compare
@bbovenzi @uranusjr And, speaking of ui test, although the jest configuration file is seen in the If someone makes a test procedure for the files under |
'airflow': {'format': LOG_FORMAT}, | ||
'airflow': { | ||
'format': LOG_FORMAT, | ||
'class': 'airflow.utils.log.timezone_aware.TimezoneAware', |
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.
Let’s make this string a constant like COLORED_FORMATTER_CLASS
.
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.
Like COLORED_FORMATTER_CLASS
, I changed it to be user configurable. This is a bugfix, and backwards compatibility was adjusted in js, so a new class was designated as fallback.
Could you check it out?
@@ -43,6 +43,9 @@ class CustomTTYColoredFormatter(TTYColoredFormatter): | |||
traceback. | |||
""" | |||
|
|||
default_time_format = '%Y-%m-%d %H:%M:%S%z' | |||
default_msec_format = '%s %03dms' |
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.
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:
- Avoid specifying milliseconds in the first place. by doing that we can leave the same level of information both in the UI and in the file (which is currently not. file is verbose than UI). It is possible by assigning
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.) - In order to stick current behavior, modify the regex to match including the rear part of datetime, and then not use the rear part in replaceAll. In this case, the file side has more detailed information, anyway I think
-0600 123ms
is easier to understand than-0600,123
. - (which I chose) To provide the same level of information to both the UI and the file, the regex didn't match the milliseconds part. so they could exposed as they is. By doing this, UI shows more information that wasn't there before, but I didn't think that would be a problem.
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.
After I git rebase onto main:
A lot of thoughts went through my mind when I saw this screen. 😢
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.
We've started to add logs into the grid view too. I think a useful thing is that we can have a single log parser function that both pages use and we write tests for. I can play around with that after this PR. |
b261672
to
579b9c9
Compare
@bbovenzi I updated PR (579b9c92bf749783a888eb6d2eb5b9644a6ff929): |
579b9c9
to
b7aae8a
Compare
Just realised, we should add a news entry to tell users using custom loggers to update their configuration so they can benefit from this enhancement. |
e5a0568
to
c3b3a4d
Compare
Since the UI side code maintains backwards compatibility, I thought it would not be a significant addition, so I wrote it as an improvement and a bugfix. Would it be appropriate? |
newsfragments/24373.improvement.rst
Outdated
@@ -0,0 +1 @@ | |||
Support config ``[logging]log_formatter_class`` for overriding logging.Formatter |
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 probably only need one of these. Also, this should add a sentence saying something like
If you are using a custom Formatter subclass in your logging_config_class
, please inherit from airflow.utils.log.timezone_aware.TimezoneAware
instead of logging.Formatter
.
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.
@uranusjr
I misinterpreted significant as breaking change.
Referring to the following paragraph of the contribution guide, it seems that 'body' to explain the procedure is supported only in the 'significant' type. is that right?
In general newsfragments must be one line. For newsfragment type
significant
, you may include summary and body separated by a blank line, similar togit
commit messages.
If so, I think you should change it to a significant type and put the explanation you suggested. thanks for the comment
The PR most likely needs to run full matrix of tests because it modifies parts of the core of Airflow. However, committers might decide to merge it quickly and take the risk. If they don't merge it quickly - please rebase it to the latest main at your convenience, or amend the last commit of the PR, and push it with --force-with-lease. |
c3b3a4d
to
5e52f77
Compare
5e52f77
to
02eed05
Compare
Failure unrelated (and this doesn’t change the providers). |
Awesome work, congrats on your first merged pull request! |
The failure was because oit was not rebased BTW |
Dear @rino0601 @uranusjr I already suggested in my PR to use ISO 8601 for ES Logger because it is native for it. |
@millin Thanks for the suggestion. |
In this PR I have fixed the bug with logs display in UI.
For those who not using UTC on their system, time conversion doesn't work correctly.
Because previous fix(PR #23075) consider UTC only.
This PR:
%z
tologging.Formatter.default_time_format
so that moments.js could understand the time properly.closes: #23796
^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code change, Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragement file, named
{pr_number}.significant.rst
, in newsfragments.