mik-laj 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_r281043516
 
 

 ##########
 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:
   I have doubts whether increasing and decreasing the counter is the best 
solution. Can not the counter be increased only when an error has occurred? 

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to