-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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
Fix calculation of health check threshold for SchedulerJob #31277
Merged
Merged
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -264,27 +264,6 @@ def _debug_dump(self, signum: int, frame: FrameType | None) -> None: | |
self.job.executor.debug_dump() | ||
self.log.info("-" * 80) | ||
|
||
def is_alive(self, grace_multiplier: float | None = None) -> bool: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not used any more - I missed during the refactor that this "special" case for SchedulerJob is not called any more. |
||
""" | ||
Whether the SchedulerJob is alive. | ||
|
||
We define alive as in a state of running and a heartbeat within the | ||
threshold defined in the ``scheduler_health_check_threshold`` config | ||
setting. | ||
|
||
``grace_multiplier`` is accepted for compatibility with the parent class. | ||
|
||
""" | ||
if grace_multiplier is not None: | ||
# Accept the same behaviour as superclass | ||
return self.job.is_alive(grace_multiplier=grace_multiplier) | ||
scheduler_health_check_threshold: int = conf.getint("scheduler", "scheduler_health_check_threshold") | ||
return ( | ||
self.job.state == State.RUNNING | ||
and (timezone.utcnow() - self.job.latest_heartbeat).total_seconds() | ||
< scheduler_health_check_threshold | ||
) | ||
|
||
def __get_concurrency_maps(self, states: Iterable[TaskInstanceState], session: Session) -> ConcurrencyMap: | ||
""" | ||
Get the concurrency maps. | ||
|
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,8 @@ | ||
Clarifications of the external Health Check mechanism and using ``Job`` classes. | ||
ashb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
In the past SchedulerJob and other ``*Job`` classes are known to have been used to perform | ||
external health checks for Airflow components. Those are, however, Airflow DB ORM related classes. | ||
The DB models and database structure of Airflow are considered as internal implementation detail, following | ||
`public interface <https://airflow.apache.org/docs/apache-airflow/stable/public-airflow-interface.html>`_). | ||
Therefore, they should not be used for external health checks. Instead, you should use the | ||
``airflow jobs check`` CLI command (introduced in Airflow 2.1) for that purpose. |
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
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.
We don't need to hard-code this, we can create an internal method on this base class that returns
health_check_threshold
and override that onSchedulerJob
classThere 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 is no
SchedulerJob
class any 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.
That was the gist of the change in #30302 and #30255 - to get rid of the Polymorphism we had and keep one "Job" which is not a "BaseJob" any more. We can (as next step and I might do it) move the threshold calculation to SchedulerJobRunner, but this one is the easiest and safest fix to put specific exception in the "is_alive" method.
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.
BTW. There is also a follow-up from @jedcunningham to move the Job to models #31194 (where it actually belongs) and we could do it as part of that move - the whole decoupling actually made it possible to do such a move.
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 tiny a change in behaviour.
Previously if you called
SchedulerJob.is_alive(2.2)
it would use the multiplier instead of the configures threshold.This is probably okay to ignore the difference but should be called out in a news fragment?
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.
But yeah - might be actually good to spell it out that you should use
airflow jobs check
now instead of SchedulerJob model as we know poeple DID use the queries (In Matthew's chart for one). Let me add it.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've addded description. I will be weakly available this afternoon to follow-up, but I am perfectly fine with refining the message I explained in the newsfragment if someone would like to describe it better (feel free to add changes and merge without me doing so :) )
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.
@ashb - I think it makes little sense to mention the multiplier as a change - it's better to say (if you've used it in the past - don't do it at all).
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.
cc: @kaxil -> I also added another fixup, where I went a bit further - i.e. I implemented in the way that SchedulerJobRunner is overriding the threshold, so that it is not "hard-coded" (so what I discussed above) - I think it might be a bit nicer in the sense it is now not "hard-coded" in Job and moved to the runner- Job is now not aware about Scheduler Job at all. Maybe that is a better idea?
(and I removed the grace_multiplier altogether as parameter - converted it to a constant).
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 moved it back - I realized that we cannot do it - > the check should be based on the job_type not set externally by the runner - the way it is used by
job check
is that it retrives it from the DB - and runner is not involved. So really the "is_alive" check must apply different threshold based on the type, not set by the runner.