mik-laj commented on a change in pull request #12158:
URL: https://github.com/apache/airflow/pull/12158#discussion_r529499699
##########
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
+ def incr(self, stat, count=1, rate=1, labels=None):
"""Increment stat"""
+ del labels
Review comment:
This prevents an error about an unused variable and at the same time we
do not have a poorly descriptive variable `_`.
----------------------------------------------------------------
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]