Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metrics basic deprecated validators removed in favor of pattern matching #41975

Merged
merged 5 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions airflow/metrics/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ class MetricNameLengthExemptionWarning(Warning):

def get_validator() -> ListValidator:
validators = {
"pattern": {"allow": PatternAllowListValidator, "block": PatternBlockListValidator},
"allow": PatternAllowListValidator,
"block": PatternBlockListValidator,
}
metric_lists = {
"allow": (metric_allow_list := conf.get("metrics", "metrics_allow_list", fallback=None)),
Expand All @@ -106,7 +107,7 @@ def get_validator() -> ListValidator:
else:
list_type = DEFAULT_VALIDATOR_TYPE

return validators["pattern"][list_type](metric_lists[list_type])
return validators[list_type](metric_lists[list_type])
potiuk marked this conversation as resolved.
Show resolved Hide resolved


def validate_stat(fn: Callable) -> Callable:
Expand Down
1 change: 1 addition & 0 deletions newsfragments/41975.significant.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Metrics basic deprecated validators (``AllowListValidator`` and ``BlockListValidator``) were removed in favor of pattern matching. Pattern matching validators (``PatternAllowListValidator`` and ``PatternBlockListValidator``) are enabled by default. Configuration parameter ``metrics_use_pattern_match``was removed from the ``metrics`` section.
7 changes: 6 additions & 1 deletion tests/core/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,11 @@ def teardown_method(self):
PatternBlockListValidator,
id="pattern_block_list_provided",
),
pytest.param(
{**stats_on, **allow_list, **block_list},
PatternAllowListValidator,
id="pattern_block_list_provided",
),
],
)
def test_pattern_picker(self, config, expected):
Expand All @@ -362,7 +367,7 @@ def test_pattern_picker(self, config, expected):
assert isinstance(airflow.stats.Stats.statsd, statsd.StatsClient)
assert type(airflow.stats.Stats.instance.metrics_validator) is expected

@conf_vars({**stats_on, **block_list, ("metrics", "metrics_allow_list"): "bax,qux"})
@conf_vars({**stats_on, **block_list, ("metrics", "metrics_allow_list"): "baz,qux"})
dirrao marked this conversation as resolved.
Show resolved Hide resolved
def test_setting_allow_and_block_logs_warning(self, caplog):
importlib.reload(airflow.stats)

Expand Down
Loading