rc/SIENTIAPDE-2165- refactor: inline counter=1 for API_ERROR, drop unnecessary dispatch (review finding)

This commit is contained in:
Carla Pinto
2026-10-08 13:58:55 +02:00
parent bba4daaddd
commit 2649476571
2 changed files with 10 additions and 44 deletions

View File

@@ -28,7 +28,6 @@ InputFilterFunc = Callable[[DataFrame, dict[str, Any]], bool]
ResponseFilterFunc = Callable[[dict[str, Any], dict[str, Any]], bool]
ContentFilterFunc = Callable[[DataFrame, dict[str, Any]], bool]
InputCounterFunc = Callable[[DataFrame, dict[str, Any]], int]
ResponseCounterFunc = Callable[[dict[str, Any], dict[str, Any]], int]
# Input filter function mappings
input_filter_functions: dict[str, InputFilterFunc] = {
@@ -80,30 +79,11 @@ input_path_confidence: Mapping[str, int] = {
}
def _count_api_error(_response: dict[str, Any], _config: dict[str, Any]) -> int:
"""
Count for the API_ERROR filter.
There's no per-row/per-item unit to count here — `api_error_filter` evaluates a single
API response as a whole, not tabular data — so this mirrors `_count_empty_data`'s
approach to a structural (not countable) trigger: a fixed value, here 1 (one API error
event), instead of 0 (zero rows present) like `_count_empty_data`'s own case.
Return:
int: Always 1.
"""
return 1
# MLFlow response filter function mappings
mlflow_response_filter_functions: dict[str, ResponseFilterFunc] = {
'API_ERROR': api_error_filter,
}
mlflow_response_filter_counters: dict[str, ResponseCounterFunc] = {
'API_ERROR': _count_api_error,
}
mlflow_response_path_confidence: Mapping[str, int] = {
'STOP': -1,
'CONTINUE': 10,
@@ -439,21 +419,21 @@ class Gates(SientiaMonitoring):
if path_flag in triggered_policies:
self.info(f'Mlflow response gate result: {path_flag}', metadata)
matched = [
(fil, filter_config)
for fil, policy, filter_config in triggered_filters
if policy == path_flag
]
matched = [fil for fil, policy, _ in triggered_filters if policy == path_flag]
document = {
'filters': [
{
'name': fil,
'policy': path_flag,
'counter': mlflow_response_filter_counters.get(fil, lambda *_: 0)(
status, filter_config
),
# No per-row/per-item unit to count here — `api_error_filter`
# evaluates a single API response as a whole, not tabular data —
# so, unlike `input_gate`'s per-filter counters, this is a fixed
# value: 1 (one API error event). Inlined rather than a counter
# function/dict, since there's only one response filter today and
# this isn't an override of anything (review finding).
'counter': 1,
}
for fil, filter_config in matched
for fil in matched
],
}