SIENTIAPDE-1445
Update GITHUB_BRANCH to feature/SIENTIAPDE-1445 and enhance formatters with a new registry for workflow types, improving configuration management. Refactor process_schedules to utilize the new registry and add error handling for unsupported workflow types. Update tests to validate new functionality and ensure proper integration.
This commit is contained in:
@@ -21,6 +21,9 @@ def formatters():
|
||||
formatters.send_notification = MagicMock()
|
||||
formatters.send_notification_async = AsyncMock()
|
||||
formatters.emit_metric = AsyncMock()
|
||||
formatters.error = MagicMock()
|
||||
formatters.info = MagicMock()
|
||||
formatters.debug = MagicMock()
|
||||
return formatters
|
||||
|
||||
|
||||
@@ -35,31 +38,42 @@ metadata = {
|
||||
|
||||
|
||||
@mark.asyncio
|
||||
@patch('orchestrator.activities.formatters.scouter', return_value={'test_scouter': 'test_scouter'})
|
||||
@patch(
|
||||
'orchestrator.activities.formatters.predictions_batch',
|
||||
return_value={'test_predictions_batch': 'test_predictions_batch'},
|
||||
)
|
||||
@patch(
|
||||
'orchestrator.activities.formatters.minimal_retrain',
|
||||
return_value={'test_minimal_retrain': 'test_minimal_retrain'},
|
||||
)
|
||||
@patch(
|
||||
'orchestrator.activities.formatters.drift',
|
||||
return_value={'test_drift': 'test_drift'},
|
||||
)
|
||||
@patch(
|
||||
'orchestrator.activities.formatters.simple_metrics',
|
||||
return_value={'test_simple_metrics': 'test_simple_metrics'},
|
||||
)
|
||||
async def test_process_schedules(
|
||||
mock_simple_metrics,
|
||||
mock_drift,
|
||||
mock_minimal_retrain,
|
||||
mock_predictions_batch,
|
||||
mock_scouter,
|
||||
formatters,
|
||||
):
|
||||
async def test_process_schedules(formatters):
|
||||
mock_scouter = MagicMock(return_value={'test_scouter': 'test_scouter'})
|
||||
mock_predictions_batch = MagicMock(
|
||||
return_value={'test_predictions_batch': 'test_predictions_batch'}
|
||||
)
|
||||
mock_minimal_retrain = MagicMock(return_value={'test_minimal_retrain': 'test_minimal_retrain'})
|
||||
mock_drift = MagicMock(return_value={'test_drift': 'test_drift'})
|
||||
mock_simple_metrics = MagicMock(return_value={'test_simple_metrics': 'test_simple_metrics'})
|
||||
|
||||
mock_schedule_types = {
|
||||
'scouter': {
|
||||
'namespace': 'scouter',
|
||||
'function': mock_scouter,
|
||||
},
|
||||
'pi_web_api_scouter': {
|
||||
'namespace': 'scouter',
|
||||
'function': mock_scouter,
|
||||
},
|
||||
'predictions_batch': {
|
||||
'namespace': 'laborious',
|
||||
'function': mock_predictions_batch,
|
||||
},
|
||||
'minimal_retrain': {
|
||||
'namespace': 'laborious',
|
||||
'function': mock_minimal_retrain,
|
||||
},
|
||||
'drift': {
|
||||
'namespace': 'laborious',
|
||||
'function': mock_drift,
|
||||
},
|
||||
'simple_metrics': {
|
||||
'namespace': 'laborious',
|
||||
'function': mock_simple_metrics,
|
||||
},
|
||||
}
|
||||
|
||||
input_data = {
|
||||
'pipelines': [
|
||||
{
|
||||
@@ -100,7 +114,8 @@ async def test_process_schedules(
|
||||
]
|
||||
}
|
||||
|
||||
result = await formatters.process_schedules(input_data)
|
||||
with patch('orchestrator.activities.formatters.schedule_types', mock_schedule_types):
|
||||
result = await formatters.process_schedules(input_data)
|
||||
|
||||
assert result == {
|
||||
'scouter': {
|
||||
@@ -133,6 +148,79 @@ async def test_process_schedules(
|
||||
mock_simple_metrics.assert_called_once_with(input_data['pipelines'][4])
|
||||
|
||||
|
||||
@mark.asyncio
|
||||
async def test_process_schedules_with_invalid_workflow_type(formatters):
|
||||
"""Test that process_schedules handles invalid workflow types correctly"""
|
||||
mock_scouter = MagicMock(return_value={'test_scouter': 'test_scouter'})
|
||||
|
||||
mock_schedule_types = {
|
||||
'scouter': {
|
||||
'namespace': 'scouter',
|
||||
'function': mock_scouter,
|
||||
},
|
||||
}
|
||||
|
||||
pipelines = [
|
||||
{
|
||||
'schedule_name': 'test_schedule_name_valid',
|
||||
'workflow_type': 'scouter',
|
||||
'model_name': 'test_model_name',
|
||||
'model_id': 'test_model_id',
|
||||
'updated_at': '2021-01-01',
|
||||
},
|
||||
{
|
||||
'schedule_name': 'test_schedule_name_invalid',
|
||||
'workflow_type': 'invalid_workflow_type',
|
||||
'model_name': 'test_model_name',
|
||||
'model_id': 'test_model_id',
|
||||
'updated_at': '2021-01-02',
|
||||
},
|
||||
{
|
||||
'schedule_name': 'test_schedule_name_valid2',
|
||||
'workflow_type': 'scouter',
|
||||
'model_name': 'test_model_name',
|
||||
'model_id': 'test_model_id',
|
||||
'updated_at': '2021-01-03',
|
||||
},
|
||||
]
|
||||
|
||||
input_data = {
|
||||
'pipelines': pipelines,
|
||||
'metadata': {
|
||||
'schedule_name': 'test_schedule',
|
||||
'workflow_name': 'test_workflow',
|
||||
},
|
||||
}
|
||||
|
||||
with patch('orchestrator.activities.formatters.schedule_types', mock_schedule_types):
|
||||
result = await formatters.process_schedules(input_data)
|
||||
|
||||
# Assert that error was called for invalid workflow type
|
||||
formatters.error.assert_called_once_with(
|
||||
'Workflow type invalid_workflow_type not supported', metadata=input_data['metadata']
|
||||
)
|
||||
|
||||
# Assert that only valid pipelines were processed
|
||||
assert result == {
|
||||
'scouter': {
|
||||
'test_schedule_name_valid': {
|
||||
'test_scouter': 'test_scouter',
|
||||
'updated_at': '2021-01-01',
|
||||
},
|
||||
'test_schedule_name_valid2': {
|
||||
'test_scouter': 'test_scouter',
|
||||
'updated_at': '2021-01-03',
|
||||
},
|
||||
},
|
||||
'laborious': {},
|
||||
}
|
||||
|
||||
# Assert that the mock function was called only for valid pipelines
|
||||
assert mock_scouter.call_count == 2
|
||||
mock_scouter.assert_any_call(pipelines[0])
|
||||
mock_scouter.assert_any_call(pipelines[2])
|
||||
|
||||
|
||||
@mark.asyncio
|
||||
@patch(
|
||||
'orchestrator.activities.formatters.gather_read_tags',
|
||||
|
||||
@@ -486,7 +486,13 @@ def test_pi_web_api_scouter():
|
||||
'schema': 'sientia_data',
|
||||
'table_name': 'laborious_data',
|
||||
'retention_time': 10 * 60,
|
||||
'model_tags': {'test_tag_name': {'webid': 'test_webid', 'aggr_func': 'test_aggr_func', 'data_range': [1, 2]}},
|
||||
'model_tags': {
|
||||
'test_tag_name': {
|
||||
'webid': 'test_webid',
|
||||
'aggr_func': 'test_aggr_func',
|
||||
'data_range': [1, 2],
|
||||
}
|
||||
},
|
||||
'debug_data_package': False,
|
||||
'execution_timeout_seconds': 300,
|
||||
'task_timeout_seconds': 300,
|
||||
@@ -496,7 +502,7 @@ def test_pi_web_api_scouter():
|
||||
'period': '*-2d',
|
||||
'max_count': 5,
|
||||
'api_timeout': 30,
|
||||
}
|
||||
},
|
||||
}
|
||||
assert result == expected
|
||||
|
||||
@@ -536,7 +542,9 @@ def test_pi_web_api_scouter_with_timeout_greater_than_frequency():
|
||||
'schema': 'sientia_data',
|
||||
'table_name': 'laborious_data',
|
||||
'retention_time': 10 * 60,
|
||||
'model_tags': {'test_tag_name': {'webid': 'test_webid', 'aggr_func': 'lts', 'data_range': [-100, 100]}},
|
||||
'model_tags': {
|
||||
'test_tag_name': {'webid': 'test_webid', 'aggr_func': 'lts', 'data_range': [-100, 100]}
|
||||
},
|
||||
'debug_data_package': False,
|
||||
'execution_timeout_seconds': 300,
|
||||
'task_timeout_seconds': 300,
|
||||
@@ -546,7 +554,7 @@ def test_pi_web_api_scouter_with_timeout_greater_than_frequency():
|
||||
'period': '*-1d',
|
||||
'max_count': 1,
|
||||
'api_timeout': 60,
|
||||
}
|
||||
},
|
||||
}
|
||||
assert result == expected
|
||||
|
||||
@@ -585,7 +593,9 @@ def test_pi_web_api_scouter_with_no_timeout():
|
||||
'schema': 'sientia_data',
|
||||
'table_name': 'laborious_data',
|
||||
'retention_time': 10 * 60,
|
||||
'model_tags': {'test_tag_name': {'webid': 'test_webid', 'aggr_func': 'lts', 'data_range': [-100, 100]}},
|
||||
'model_tags': {
|
||||
'test_tag_name': {'webid': 'test_webid', 'aggr_func': 'lts', 'data_range': [-100, 100]}
|
||||
},
|
||||
'debug_data_package': False,
|
||||
'execution_timeout_seconds': 300,
|
||||
'task_timeout_seconds': 300,
|
||||
@@ -595,6 +605,6 @@ def test_pi_web_api_scouter_with_no_timeout():
|
||||
'period': '*-1d',
|
||||
'max_count': 1,
|
||||
'api_timeout': 30,
|
||||
}
|
||||
},
|
||||
}
|
||||
assert result == expected
|
||||
|
||||
Reference in New Issue
Block a user