-
Notifications
You must be signed in to change notification settings - Fork 14.2k
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 info log message about duration taken to load plugins #12308
Conversation
/cc @mjpieters |
The PR needs to run all tests because it modifies core of Airflow! Please rebase it to latest master or ask committer to re-run it! |
476a67b
to
c8f4dc8
Compare
@@ -90,8 +90,9 @@ def _color_record_traceback(self, record: LogRecord) -> LogRecord: | |||
|
|||
def format(self, record: LogRecord) -> str: | |||
try: | |||
record = self._color_record_args(record) | |||
record = self._color_record_traceback(record) | |||
if self.stream.isatty(): |
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.
This is so that caplog
fixture from pytest doesn't get poluted with escape code.
from airflow import plugins_manager | ||
|
||
# assert not logs | ||
with self.assertRaises(AssertionError), self.assertLogs(plugins_manager.log): |
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.
I found this a huge code smell, and a funny/hard to follow way of saying "does not log".
So I switched it all out to pytests caplog
fixture.
|
||
def test_should_warning_about_incompatible_plugins(self): | ||
assert caplog.records[0].levelname == 'INFO' | ||
assert caplog.records[0].msg == 'Loading %d plugin(s) took %.2f seconds' |
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.
his is the un-formatted message string
c8f4dc8
to
330c542
Compare
@@ -262,6 +263,8 @@ def ensure_plugins_loaded(): | |||
|
|||
log.debug("Loading plugins") | |||
|
|||
start = time.monotonic() |
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.
Might there be a usecase for a general timing context manager here?
with timer() as t:
# ...
log.info("Frobbing the foonars took %.2f seconds", t.elapsed.total_seconds())
Encapsulation makes it easier to make sure everyone gets this right (using time.monotonic()
!), and might make it easier to automatically export metrics to statd / prometheus if desired (with timer(metric="metric_name") as t:
).
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.
Could be. For metrics there is already a with Stats.timer("my_metric_name":)
though.
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.
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.
Only problem I see is that context manager introduces additional level of indentation which can require a pylint disable sometimes... Apart from that I like the idea!
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.
Can also do it like this:
timer = Stats.timer().start()
...
timer.end()
# use timer.duration
https://github.com/apache/airflow/pull/12308/checks?check_run_id=1399669598#step:6:1249
|
Hmmmmm, passes for me locally. Fun. Including when using Found it:
That fails. Any test in test_standard_task_runner causes the problem. I think the problem may be an "errant" logging.shutdown. This test had a |
Loading plugins, particularly from setuptools entry points can be slow, and since by default this happens per-task, it can slow down task execution unexpectedly. By having this log message users can know the source of the delay
a46acfe
to
1170c72
Compare
Loading plugins, particularly from setuptools entry points can be slow,
and since by default this happens per-task, it can slow down task
execution unexpectedly.
By having this log message users can know the source of the delay
^ 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 UPDATING.md.