rc/SIENTIAPDE-2165- refactor: inline counter=1 for API_ERROR, drop unnecessary dispatch (review finding)
This commit is contained in:
@@ -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
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
@@ -6,13 +6,7 @@ from sientia_do.notifications.models import NotificationLevel
|
||||
from sientia_do.observability.metrics_controller import MetricsController
|
||||
from sientia_do.observability.sientia_monitoring import SientiaMonitoring
|
||||
|
||||
from laborious.activities.gates import (
|
||||
Gates,
|
||||
input_filter_counters,
|
||||
input_filter_functions,
|
||||
mlflow_response_filter_counters,
|
||||
mlflow_response_filter_functions,
|
||||
)
|
||||
from laborious.activities.gates import Gates, input_filter_counters, input_filter_functions
|
||||
|
||||
|
||||
@fixture(autouse=True)
|
||||
@@ -448,14 +442,6 @@ def test_mlflow_response_gate_with_filter_not_caught(gates_activity):
|
||||
gates_activity.debug.assert_called()
|
||||
|
||||
|
||||
def test_mlflow_response_filter_counters_covers_every_mlflow_response_filter_function():
|
||||
# Same parity guard as `test_input_filter_counters_covers_every_input_filter_function`
|
||||
# (review finding, 2026-09-30): a filter added to `mlflow_response_filter_functions` without
|
||||
# a matching counter here degrades to counter=0 instead of crashing, but this test still
|
||||
# catches the gap before it ships.
|
||||
assert set(mlflow_response_filter_counters) == set(mlflow_response_filter_functions)
|
||||
|
||||
|
||||
def test_mlflow_content_gate_invalid_filter(gates_activity):
|
||||
# Arrange
|
||||
input_data = {
|
||||
|
||||
Reference in New Issue
Block a user