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 2019/06/21 15:40:17 UTC

[GitHub] [airflow] ashb commented on a change in pull request #5139: [AIRFLOW-4360] Add performance metrics for Webserver UI.

ashb commented on a change in pull request #5139: [AIRFLOW-4360] Add performance metrics for Webserver UI.
URL: https://github.com/apache/airflow/pull/5139#discussion_r296290010
 
 

 ##########
 File path: airflow/www/decorators.py
 ##########
 @@ -125,3 +127,29 @@ def wrapper(self, *args, **kwargs):
                                         __class__.__name__ + ".login"))
         return wrapper
     return decorator
+
+
+def log_webserver_stats(endpoint, log_views=False, log_duration=False, log_failures=False):
+    """
+    Decorator to log server side stats from webserver UI.
+
+    Currently supports logging views and load failures as counters
+    and load duration as timing.
+    """
+    def decorator(f):
+        @functools.wraps(f)
+        def wrapper(*args, **kwargs):
+            start_dttm = timezone.utcnow()
+            if (log_views):
+                Stats.incr('webserver.{}.views'.format(endpoint))
+            if (log_failures):
+                Stats.incr('webserver.{}.load_failures'.format(endpoint))
+            response = f(*args, **kwargs)
+            if (log_duration):
+                duration = (timezone.utcnow() - start_dttm).total_seconds() * 1000
+                Stats.timing('webserver.{}.load_time'.format(endpoint), duration)
+            if (log_failures):
+                Stats.decr('webserver.{}.load_failures'.format(endpoint))
 
 Review comment:
   This is going to do funny things to the stats over time.

----------------------------------------------------------------
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