You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/02/23 21:32:58 UTC

[GitHub] [airflow] mik-laj opened a new pull request #7516: [AIRFLOW-6894] Prevent db query in example_dags

mik-laj opened a new pull request #7516: [AIRFLOW-6894] Prevent db query in example_dags
URL: https://github.com/apache/airflow/pull/7516
 
 
   
   CC: @kaxil @nuclearpinguin 
   
   @ANiteckiP Dear SQLAlchemy expert.  Do you want to add something? 
   ---
   Issue link: WILL BE INSERTED BY [boring-cyborg](https://github.com/kaxil/boring-cyborg)
   
   Make sure to mark the boxes below before creating PR: [x]
   
   - [X] Description above provides context of the change
   - [X] Commit message/PR title starts with `[AIRFLOW-NNNN]`. AIRFLOW-NNNN = JIRA ID<sup>*</sup>
   - [X] Unit tests coverage for changes (not needed for documentation changes)
   - [X] Commits follow "[How to write a good git commit message](http://chris.beams.io/posts/git-commit/)"
   - [X] Relevant documentation is updated including usage instructions.
   - [X] I will engage committers as explained in [Contribution Workflow Example](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#contribution-workflow-example).
   
   <sup>*</sup> For document-only changes commit message can start with `[AIRFLOW-XXXX]`.
   
   ---
   In case of fundamental code change, Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in [UPDATING.md](https://github.com/apache/airflow/blob/master/UPDATING.md).
   Read the [Pull Request Guidelines](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#pull-request-guidelines) for more information.
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [airflow] codecov-io commented on issue #7516: [AIRFLOW-6894] Prevent DB query in example_dags

Posted by GitBox <gi...@apache.org>.
codecov-io commented on issue #7516: [AIRFLOW-6894] Prevent DB query in example_dags
URL: https://github.com/apache/airflow/pull/7516#issuecomment-590131157
 
 
   # [Codecov](https://codecov.io/gh/apache/airflow/pull/7516?src=pr&el=h1) Report
   > Merging [#7516](https://codecov.io/gh/apache/airflow/pull/7516?src=pr&el=desc) into [master](https://codecov.io/gh/apache/airflow/commit/4e0e2f0da39626c1bc8026a33c2080a6b11f2c41?src=pr&el=desc) will **decrease** coverage by `0.26%`.
   > The diff coverage is `100%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/airflow/pull/7516/graphs/tree.svg?width=650&token=WdLKlKHOAU&height=150&src=pr)](https://codecov.io/gh/apache/airflow/pull/7516?src=pr&el=tree)
   
   ```diff
   @@            Coverage Diff             @@
   ##           master    #7516      +/-   ##
   ==========================================
   - Coverage   86.79%   86.53%   -0.27%     
   ==========================================
     Files         887      893       +6     
     Lines       41976    42191     +215     
   ==========================================
   + Hits        36432    36508      +76     
   - Misses       5544     5683     +139
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/airflow/pull/7516?src=pr&el=tree) | Coverage Δ | |
   |---|---|---|
   | [...flow/providers/google/cloud/operators/cloud\_sql.py](https://codecov.io/gh/apache/airflow/pull/7516/diff?src=pr&el=tree#diff-YWlyZmxvdy9wcm92aWRlcnMvZ29vZ2xlL2Nsb3VkL29wZXJhdG9ycy9jbG91ZF9zcWwucHk=) | `84.68% <100%> (+0.06%)` | :arrow_up: |
   | [airflow/kubernetes/volume\_mount.py](https://codecov.io/gh/apache/airflow/pull/7516/diff?src=pr&el=tree#diff-YWlyZmxvdy9rdWJlcm5ldGVzL3ZvbHVtZV9tb3VudC5weQ==) | `44.44% <0%> (-55.56%)` | :arrow_down: |
   | [airflow/kubernetes/volume.py](https://codecov.io/gh/apache/airflow/pull/7516/diff?src=pr&el=tree#diff-YWlyZmxvdy9rdWJlcm5ldGVzL3ZvbHVtZS5weQ==) | `52.94% <0%> (-47.06%)` | :arrow_down: |
   | [airflow/kubernetes/pod\_launcher.py](https://codecov.io/gh/apache/airflow/pull/7516/diff?src=pr&el=tree#diff-YWlyZmxvdy9rdWJlcm5ldGVzL3BvZF9sYXVuY2hlci5weQ==) | `47.18% <0%> (-45.08%)` | :arrow_down: |
   | [...viders/cncf/kubernetes/operators/kubernetes\_pod.py](https://codecov.io/gh/apache/airflow/pull/7516/diff?src=pr&el=tree#diff-YWlyZmxvdy9wcm92aWRlcnMvY25jZi9rdWJlcm5ldGVzL29wZXJhdG9ycy9rdWJlcm5ldGVzX3BvZC5weQ==) | `69.38% <0%> (-25.52%)` | :arrow_down: |
   | [airflow/kubernetes/refresh\_config.py](https://codecov.io/gh/apache/airflow/pull/7516/diff?src=pr&el=tree#diff-YWlyZmxvdy9rdWJlcm5ldGVzL3JlZnJlc2hfY29uZmlnLnB5) | `50.98% <0%> (-23.53%)` | :arrow_down: |
   | [airflow/utils/file.py](https://codecov.io/gh/apache/airflow/pull/7516/diff?src=pr&el=tree#diff-YWlyZmxvdy91dGlscy9maWxlLnB5) | `87.83% <0%> (-1.36%)` | :arrow_down: |
   | [airflow/utils/dag\_processing.py](https://codecov.io/gh/apache/airflow/pull/7516/diff?src=pr&el=tree#diff-YWlyZmxvdy91dGlscy9kYWdfcHJvY2Vzc2luZy5weQ==) | `87.93% <0%> (-0.2%)` | :arrow_down: |
   | [airflow/api/common/experimental/trigger\_dag.py](https://codecov.io/gh/apache/airflow/pull/7516/diff?src=pr&el=tree#diff-YWlyZmxvdy9hcGkvY29tbW9uL2V4cGVyaW1lbnRhbC90cmlnZ2VyX2RhZy5weQ==) | `98.03% <0%> (-0.04%)` | :arrow_down: |
   | [airflow/models/baseoperator.py](https://codecov.io/gh/apache/airflow/pull/7516/diff?src=pr&el=tree#diff-YWlyZmxvdy9tb2RlbHMvYmFzZW9wZXJhdG9yLnB5) | `96.52% <0%> (ø)` | :arrow_up: |
   | ... and [33 more](https://codecov.io/gh/apache/airflow/pull/7516/diff?src=pr&el=tree-more) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/airflow/pull/7516?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/airflow/pull/7516?src=pr&el=footer). Last update [4e0e2f0...7a3707f](https://codecov.io/gh/apache/airflow/pull/7516?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [airflow] mik-laj commented on a change in pull request #7516: [AIRFLOW-6894] Prevent DB query in example_dags

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #7516: [AIRFLOW-6894] Prevent DB query in example_dags
URL: https://github.com/apache/airflow/pull/7516#discussion_r383040768
 
 

 ##########
 File path: tests/test_utils/asserts.py
 ##########
 @@ -16,9 +16,53 @@
 # under the License.
 
 import re
+from contextlib import contextmanager
+
+from sqlalchemy import event
+
+from airflow.settings import engine
 
 
 def assert_equal_ignore_multiple_spaces(case, first, second, msg=None):
     def _trim(s):
         return re.sub(r"\s+", " ", s.strip())
     return case.assertEqual(_trim(first), _trim(second), msg)
+
+
+class CountQueriesResult:
+    def __init__(self):
+        self.count = 0
+
+
+class CountQueries(object):
+    """
+    Counts the number of queries sent to Airflow Database in a given context.
+
+    Does not support multiple processes. When a new process is started in context, its queries will
+    not be included.
+    """
+    def __init__(self):
+        self.result = CountQueriesResult()
+
+    def __enter__(self):
+        event.listen(engine, "after_cursor_execute", self.after_cursor_execute)
+        return self.result
+
+    def __exit__(self, type, value, traceback):
+        event.remove(engine, "after_cursor_execute", self.after_cursor_execute)
+
+    def after_cursor_execute(self, *args, **kwargs):
+        self.result.count += 1
+
+
+count_queries = CountQueries
+
+
+@contextmanager
+def assert_queries_count(expected_count, message_fmt=None):
 
 Review comment:
   This decorator also wants to use it to prevent regression in scheduler performance. Some methods are critical and I have optimized it to use very few queries, but it can be easily broken.  This context manager will allow us to detect a regression regarding it.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [airflow] mik-laj merged pull request #7516: [AIRFLOW-6894] Prevent DB query in example_dags

Posted by GitBox <gi...@apache.org>.
mik-laj merged pull request #7516: [AIRFLOW-6894] Prevent DB query in example_dags
URL: https://github.com/apache/airflow/pull/7516
 
 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [airflow] kaxil commented on a change in pull request #7516: [AIRFLOW-6894] Prevent DB query in example_dags

Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #7516: [AIRFLOW-6894] Prevent DB query in example_dags
URL: https://github.com/apache/airflow/pull/7516#discussion_r383042446
 
 

 ##########
 File path: tests/test_utils/asserts.py
 ##########
 @@ -16,9 +16,53 @@
 # under the License.
 
 import re
+from contextlib import contextmanager
+
+from sqlalchemy import event
+
+from airflow.settings import engine
 
 
 def assert_equal_ignore_multiple_spaces(case, first, second, msg=None):
     def _trim(s):
         return re.sub(r"\s+", " ", s.strip())
     return case.assertEqual(_trim(first), _trim(second), msg)
+
+
+class CountQueriesResult:
+    def __init__(self):
+        self.count = 0
+
+
+class CountQueries(object):
+    """
+    Counts the number of queries sent to Airflow Database in a given context.
+
+    Does not support multiple processes. When a new process is started in context, its queries will
+    not be included.
+    """
+    def __init__(self):
+        self.result = CountQueriesResult()
+
+    def __enter__(self):
+        event.listen(engine, "after_cursor_execute", self.after_cursor_execute)
+        return self.result
+
+    def __exit__(self, type, value, traceback):
+        event.remove(engine, "after_cursor_execute", self.after_cursor_execute)
+
+    def after_cursor_execute(self, *args, **kwargs):
+        self.result.count += 1
+
+
+count_queries = CountQueries
+
+
+@contextmanager
+def assert_queries_count(expected_count, message_fmt=None):
 
 Review comment:
   awesome

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [airflow] mik-laj commented on a change in pull request #7516: [AIRFLOW-6894] Prevent DB query in example_dags

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #7516: [AIRFLOW-6894] Prevent DB query in example_dags
URL: https://github.com/apache/airflow/pull/7516#discussion_r383040768
 
 

 ##########
 File path: tests/test_utils/asserts.py
 ##########
 @@ -16,9 +16,53 @@
 # under the License.
 
 import re
+from contextlib import contextmanager
+
+from sqlalchemy import event
+
+from airflow.settings import engine
 
 
 def assert_equal_ignore_multiple_spaces(case, first, second, msg=None):
     def _trim(s):
         return re.sub(r"\s+", " ", s.strip())
     return case.assertEqual(_trim(first), _trim(second), msg)
+
+
+class CountQueriesResult:
+    def __init__(self):
+        self.count = 0
+
+
+class CountQueries(object):
+    """
+    Counts the number of queries sent to Airflow Database in a given context.
+
+    Does not support multiple processes. When a new process is started in context, its queries will
+    not be included.
+    """
+    def __init__(self):
+        self.result = CountQueriesResult()
+
+    def __enter__(self):
+        event.listen(engine, "after_cursor_execute", self.after_cursor_execute)
+        return self.result
+
+    def __exit__(self, type, value, traceback):
+        event.remove(engine, "after_cursor_execute", self.after_cursor_execute)
+
+    def after_cursor_execute(self, *args, **kwargs):
+        self.result.count += 1
+
+
+count_queries = CountQueries
+
+
+@contextmanager
+def assert_queries_count(expected_count, message_fmt=None):
 
 Review comment:
   I want to use this decorator also to prevent regression in scheduler performance. Some methods are critical and I have optimized it to use very few queries, but it can be easily broken.  This context manager will allow us to detect a regression regarding it.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services