ashb commented on a change in pull request #12158:
URL: https://github.com/apache/airflow/pull/12158#discussion_r529430812



##########
File path: airflow/stats.py
##########
@@ -191,93 +443,121 @@ def test(self, stat):
             return True  # default is all metrics allowed
 
 
+def _format_safe_stats_logger_args(func):
+    @functools.wraps(func)
+    def func_wrap(_self, stat, *args, labels=None, **kwargs):
+        if labels:
+            # Remove {} from stat key e.g. {class_name} => class_name
+            stat = stat.format(**labels)
+        return validate_stat(func)(_self, stat, *args, **kwargs)
+
+    return func_wrap
+
+
 class SafeStatsdLogger:
     """Statsd Logger"""
 
     def __init__(self, statsd_client, 
allow_list_validator=AllowListValidator()):
         self.statsd = statsd_client
         self.allow_list_validator = allow_list_validator
 
-    @validate_stat
-    def incr(self, stat, count=1, rate=1):
+    @_format_safe_stats_logger_args

Review comment:
       I'd rather we didn't have to do string processing every time we emitted 
a metric, given this is "static"/precomputable.
   
   How much work would it be to have this done once in 
get_statsd_logger/get_dogstatsd_logger?




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


Reply via email to