ferruzzi commented on code in PR #43340:
URL: https://github.com/apache/airflow/pull/43340#discussion_r1824972012
##########
airflow/metrics/statsd_logger.py:
##########
@@ -79,80 +86,84 @@ def __init__(
self.influxdb_tags_enabled = influxdb_tags_enabled
self.metric_tags_validator = metric_tags_validator
- @prepare_stat_with_tags
- @validate_stat
def incr(
self,
- stat: str,
+ metric_name: str,
count: int = 1,
rate: float = 1,
*,
tags: dict[str, str] | None = None,
) -> None:
"""Increment stat."""
- if self.metrics_validator.test(stat):
- return self.statsd.incr(stat, count, rate)
+ full_metric_name = self.get_name(metric_name, tags)
+
+ if self.metrics_validator.test(full_metric_name):
+ self.statsd.incr(full_metric_name, count, rate)
return None
- @prepare_stat_with_tags
- @validate_stat
def decr(
self,
- stat: str,
+ metric_name: str,
count: int = 1,
rate: float = 1,
*,
tags: dict[str, str] | None = None,
) -> None:
"""Decrement stat."""
- if self.metrics_validator.test(stat):
- return self.statsd.decr(stat, count, rate)
+ full_metric_name = self.get_name(metric_name, tags)
+ if self.metrics_validator.test(full_metric_name):
+ return self.statsd.decr(full_metric_name, count, rate)
return None
- @prepare_stat_with_tags
- @validate_stat
def gauge(
self,
- stat: str,
+ metric_name: str,
value: int | float,
rate: float = 1,
delta: bool = False,
*,
tags: dict[str, str] | None = None,
) -> None:
"""Gauge stat."""
- if self.metrics_validator.test(stat):
- return self.statsd.gauge(stat, value, rate, delta)
+ full_metric_name = self.get_name(metric_name, tags)
+ if self.metrics_validator.test(full_metric_name):
+ return self.statsd.gauge(full_metric_name, value, rate, delta)
return None
- @prepare_stat_with_tags
- @validate_stat
def timing(
self,
- stat: str,
+ metric_name: str,
dt: DeltaType,
*,
tags: dict[str, str] | None = None,
) -> None:
"""Stats timing."""
- if self.metrics_validator.test(stat):
- return self.statsd.timing(stat, dt)
+ full_metric_name = self.get_name(metric_name, tags)
+ if self.metrics_validator.test(full_metric_name):
+ return self.statsd.timing(full_metric_name, dt)
return None
- @prepare_stat_with_tags
- @validate_stat
def timer(
self,
- stat: str | None = None,
+ metric_name: str | None = None,
*args,
tags: dict[str, str] | None = None,
**kwargs,
) -> TimerProtocol:
"""Timer metric that can be cancelled."""
- if stat and self.metrics_validator.test(stat):
- return Timer(self.statsd.timer(stat, *args, **kwargs))
+ full_metric_name = self.get_name(metric_name, tags)
+ if full_metric_name and self.metrics_validator.test(full_metric_name):
Review Comment:
For now, leave it how you have it I think. I'm not sure offhand why that
was the only one that allowed the option not to provide a name but I'm also
still on flu meds and not thinking as clearly as I might. :P If that is the
only one that accepts None for a name, then having that check is good.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]