sortega commented on code in PR #68568:
URL: https://github.com/apache/airflow/pull/68568#discussion_r3551704986
##########
shared/observability/src/airflow_shared/observability/metrics/datadog_logger.py:
##########
@@ -68,12 +79,11 @@ def incr(
tags: dict[str, str] | None = None,
) -> None:
"""Increment stat."""
- if self.metrics_tags and isinstance(tags, dict):
- tags_list = [
- f"{key}:{value}" for key, value in tags.items() if
self.metric_tags_validator.test(key)
- ]
- else:
- tags_list = []
+ tags_list = (
+ self._build_tags_list(tags, self.metric_tags_validator)
+ if self.metrics_tags and isinstance(tags, dict)
+ else []
+ )
Review Comment:
Done — folded the guard into _build_tags_list(tags), so each of the five
call sites is a single line.
##########
shared/observability/tests/observability/metrics/test_stats.py:
##########
@@ -259,6 +260,26 @@ def test_decr(self):
metric="empty", sample_rate=1, value=1, tags=[]
)
+ def test_key_value_tag_emitted_with_colon(self):
+ dogstatsd = SafeDogStatsdLogger(self.dogstatsd_client,
metrics_tags=True)
+ dogstatsd.incr("my_metric", tags={"env": "prod"})
+ self.dogstatsd_client.increment.assert_called_once_with(
+ metric="my_metric", sample_rate=1, value=1, tags=["env:prod"]
+ )
+
+ def test_standalone_tag_empty_value_emitted_without_colon(self):
+ dogstatsd = SafeDogStatsdLogger(self.dogstatsd_client,
metrics_tags=True)
+ dogstatsd.incr("my_metric", tags={"production": ""})
+ self.dogstatsd_client.increment.assert_called_once_with(
+ metric="my_metric", sample_rate=1, value=1, tags=["production"]
+ )
+
+ def test_mixed_tags_standalone_and_key_value(self):
+ dogstatsd = SafeDogStatsdLogger(self.dogstatsd_client,
metrics_tags=True)
+ dogstatsd.incr("my_metric", tags={"production": "", "env": "staging"})
+ call_kwargs = self.dogstatsd_client.increment.call_args
+ assert set(call_kwargs.kwargs["tags"]) == {"production", "env:staging"}
Review Comment:
Done
--
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]