From ef6f551f5574aaa9b42824c8c8788c89b5c2aa9e Mon Sep 17 00:00:00 2001 From: DLT1412 Date: Mon, 24 Jun 2024 15:49:05 +0000 Subject: [PATCH] fix(statsd): handle unsupport operand int + str when value of tag is int (job_id) --- airflow/metrics/statsd_logger.py | 2 +- tests/core/test_stats.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/airflow/metrics/statsd_logger.py b/airflow/metrics/statsd_logger.py index 5b04c0b95a32d..ecd6cfc231ad8 100644 --- a/airflow/metrics/statsd_logger.py +++ b/airflow/metrics/statsd_logger.py @@ -55,7 +55,7 @@ def wrapper( if stat is not None and tags is not None: for k, v in tags.items(): if self.metric_tags_validator.test(k): - if all(c not in [",", "="] for c in v + k): + if all(c not in [",", "="] for c in f"{v}{k}"): stat += f",{k}={v}" else: log.error("Dropping invalid tag: %s=%s.", k, v) diff --git a/tests/core/test_stats.py b/tests/core/test_stats.py index 3c5fde872c5ec..80570b9ddd9a8 100644 --- a/tests/core/test_stats.py +++ b/tests/core/test_stats.py @@ -502,9 +502,9 @@ def test_increment_counter(self): def test_increment_counter_with_tags(self): self.stats.incr( "test_stats_run.delay", - tags={"key0": "val0", "key1": "val1", "key2": "val2"}, + tags={"key0": 0, "key1": "val1", "key2": "val2"}, ) - self.statsd_client.incr.assert_called_once_with("test_stats_run.delay,key0=val0,key1=val1", 1, 1) + self.statsd_client.incr.assert_called_once_with("test_stats_run.delay,key0=0,key1=val1", 1, 1) def test_does_not_increment_counter_drops_invalid_tags(self): self.stats.incr(