Skip to content

[AIRFLOW-4292] Cleanup and improve SLA code#5517

Closed
serkef wants to merge 5 commits intoapache:masterfrom
serkef:AIRFLOW-4292_cleanup_improve_SLA
Closed

[AIRFLOW-4292] Cleanup and improve SLA code#5517
serkef wants to merge 5 commits intoapache:masterfrom
serkef:AIRFLOW-4292_cleanup_improve_SLA

Conversation

@serkef
Copy link
Contributor

@serkef serkef commented Jul 2, 2019

  • Replace unnecessary list allocations with generators
  • Remove redundant filter
  • Fix typos
  • Improve readability and comments

(This continues #5083 which got quite hard to rebase)
Make sure you have checked all steps below.

Jira

Description

  • Here are some details about my PR, including screenshots of any UI changes:
    This is code cleanup. Some small functional improvements, improve readability by adding comments and fixing typos

Tests

  • My PR adds the following unit tests OR does not need testing for this extremely good reason:
    No new features. This is already covered.

Commits

  • My commits all reference Jira issues in their subject lines, and I have squashed multiple commits if they address the same issue. In addition, my commits follow the guidelines from "How to write a good git commit message":
    1. Subject is separated from body by a blank line
    2. Subject is limited to 50 characters (not including Jira issue reference)
    3. Subject does not end with a period
    4. Subject uses the imperative mood ("add", not "adding")
    5. Body wraps at 72 characters
    6. Body explains "what" and "why", not "how"

Documentation

  • In case of new functionality, my PR adds documentation that describes how to use it.
    • All the public functions and the classes in the PR contain docstrings that explain what it does
    • If you implement backwards incompatible changes, please leave a note in the Updating.md so we can assign it to a appropriate release

Code Quality

  • Passes flake8

* Replace unnecessary list allocators with generators
* Remove redundant filter
* Fix typos
* Improve readability and comments
Copy link
Member

@turbaszek turbaszek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you try to remove this file from pylint TODO list?

We are assuming that the scheduler runs often, so we only check for
tasks that should have succeeded in the past hour.
"""
if not any([isinstance(ti.sla, timedelta) for ti in dag.tasks]):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing such refactor it would be a good idea to change this sq name to something more pylint compatible. Maybe then we will be able to remove it from TODO list?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, didn't know about this one. Will change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm seems that file has several issues. I would prefer to keep the scope of this ticket on the specific function.

session.merge(sla)
session.commit()
if not slas:
return
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reversing the control statement for readability. Will comment below on the specific changes.

if not slas:
return

sla_dates = {sla.execution_date for sla in slas}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing list to set

session.commit()

task_list = "\n".join(
sla.task_id + ' on ' + sla.execution_date.isoformat()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing list to generator

sla.task_id + ' on ' + sla.execution_date.isoformat()
for sla in slas)
blocking_task_list = "\n".join(
ti.task_id + ' on ' + ti.execution_date.isoformat()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing list to generator

@serkef
Copy link
Contributor Author

serkef commented Jul 10, 2019

Can one help me with the pylint errors? It complains for accessing unknown property. Issue is class has a method __get_token that is normally translated to _SlackHook__get_token. Naming was not my choice. Should I rename or disable the check?

@potiuk
Copy link
Member

potiuk commented Jul 10, 2019

Neither. I have a change pending approval/merge to CONTRIBUTING.md on how to deal with pylint errors. You should disable the pylint error for that particular line:

https://github.com/PolideaInternal/airflow/blob/ms-travis-ci-tests/CONTRIBUTING.md#pylint-checks-work-in-progress

@codecov-io
Copy link

codecov-io commented Jul 10, 2019

Codecov Report

Merging #5517 into master will decrease coverage by 0.33%.
The diff coverage is 84.78%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5517      +/-   ##
==========================================
- Coverage   79.07%   78.74%   -0.34%     
==========================================
  Files         489      489              
  Lines       30744    30727      -17     
==========================================
- Hits        24312    24196     -116     
- Misses       6432     6531      +99
Impacted Files Coverage Δ
airflow/jobs/scheduler_job.py 70.43% <84.78%> (+0.15%) ⬆️
airflow/operators/mysql_operator.py 0% <0%> (-100%) ⬇️
airflow/operators/mysql_to_hive.py 0% <0%> (-100%) ⬇️
airflow/utils/operator_resources.py 56.52% <0%> (-30.44%) ⬇️
airflow/utils/sqlalchemy.py 74.41% <0%> (-4.66%) ⬇️
airflow/utils/dag_processing.py 58.25% <0%> (-2.02%) ⬇️
airflow/hooks/hive_hooks.py 75.94% <0%> (-1.78%) ⬇️
airflow/models/connection.py 63.88% <0%> (-1.12%) ⬇️
airflow/utils/helpers.py 82.58% <0%> (-0.98%) ⬇️
airflow/hooks/dbapi_hook.py 87.71% <0%> (-0.88%) ⬇️
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0fe8cbe...7fa8b2b. Read the comment docs.

@stale
Copy link

stale bot commented Sep 3, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Stale PRs per the .github/workflows/stale.yml policy file label Sep 3, 2019
@serkef
Copy link
Contributor Author

serkef commented Sep 8, 2019

Working on it...

@stale stale bot removed the stale Stale PRs per the .github/workflows/stale.yml policy file label Sep 8, 2019
@stale
Copy link

stale bot commented Nov 26, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Stale PRs per the .github/workflows/stale.yml policy file label Nov 26, 2019
@stale stale bot closed this Dec 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Stale PRs per the .github/workflows/stale.yml policy file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Comments