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

 ##########
 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:
   The idea around this is to catch silent errors in the implementation. We 
sometimes have errors that are more transient/unexpected, which causes 
endpoints to fail. In that case we might not hit the try catch to increment the 
failures count. This seemed like an assured way to catch any and all failures.

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