SIENTIAPDE-1273
Implement simple metrics configuration in formatters and orchestrator utilities. Update tests to validate new simple metrics functionality and ensure proper integration with existing workflows.
This commit is contained in:
@@ -20,6 +20,7 @@ with workflow.unsafe.imports_passed_through():
|
|||||||
predictions_batch,
|
predictions_batch,
|
||||||
scouter,
|
scouter,
|
||||||
drift,
|
drift,
|
||||||
|
simple_metrics,
|
||||||
)
|
)
|
||||||
|
|
||||||
topic_separator = '\n ========== \n'
|
topic_separator = '\n ========== \n'
|
||||||
@@ -140,6 +141,13 @@ class Formatters(SientiaMonitoring):
|
|||||||
'updated_at', now().strftime(DATETIME_FORMAT_MS_WITH_TZ)
|
'updated_at', now().strftime(DATETIME_FORMAT_MS_WITH_TZ)
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
elif pipeline['workflow_type'] == 'simple_metrics':
|
||||||
|
schedule_config[self.laborious_namespace][pipeline['schedule_name']] = {
|
||||||
|
**simple_metrics(pipeline),
|
||||||
|
'updated_at': pipeline.get(
|
||||||
|
'updated_at', now().strftime(DATETIME_FORMAT_MS_WITH_TZ)
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
self.info('Processed schedules', metadata=metadata)
|
self.info('Processed schedules', metadata=metadata)
|
||||||
self.debug(json.dumps(schedule_config, indent=4, sort_keys=True), metadata=metadata)
|
self.debug(json.dumps(schedule_config, indent=4, sort_keys=True), metadata=metadata)
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ def drift(config: dict[str, Any]):
|
|||||||
"""
|
"""
|
||||||
Build drift configuration from pipeline config.
|
Build drift configuration from pipeline config.
|
||||||
"""
|
"""
|
||||||
model = config['model']
|
|
||||||
return {
|
return {
|
||||||
**common_config(config),
|
**common_config(config),
|
||||||
'schema': 'sientia_data',
|
'schema': 'sientia_data',
|
||||||
@@ -51,6 +50,20 @@ def drift(config: dict[str, Any]):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def simple_metrics(config: dict[str, Any]):
|
||||||
|
"""
|
||||||
|
Build simple metrics configuration from pipeline config.
|
||||||
|
"""
|
||||||
|
return {
|
||||||
|
**common_config(config),
|
||||||
|
'schema': 'sientia_data',
|
||||||
|
'predictions_table_name': 'predictions',
|
||||||
|
'data_table_name': 'laborious_data',
|
||||||
|
'interval_minutes': config.get('interval_minutes', 60),
|
||||||
|
'metrics': config.get('metrics', ['rmse', 'mse', 'mae', 'r2']),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def minimal_retrain(config: dict[str, Any]):
|
def minimal_retrain(config: dict[str, Any]):
|
||||||
"""
|
"""
|
||||||
Build minimal retrain configuration from pipeline config.
|
Build minimal retrain configuration from pipeline config.
|
||||||
|
|||||||
@@ -48,8 +48,17 @@ metadata = {
|
|||||||
'orchestrator.activities.formatters.drift',
|
'orchestrator.activities.formatters.drift',
|
||||||
return_value={'test_drift': 'test_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(
|
async def test_process_schedules(
|
||||||
mock_drift, mock_minimal_retrain, mock_predictions_batch, mock_scouter, formatters
|
mock_simple_metrics,
|
||||||
|
mock_drift,
|
||||||
|
mock_minimal_retrain,
|
||||||
|
mock_predictions_batch,
|
||||||
|
mock_scouter,
|
||||||
|
formatters,
|
||||||
):
|
):
|
||||||
input_data = {
|
input_data = {
|
||||||
'pipelines': [
|
'pipelines': [
|
||||||
@@ -81,6 +90,13 @@ async def test_process_schedules(
|
|||||||
'model_id': 'test_model_id',
|
'model_id': 'test_model_id',
|
||||||
'updated_at': '2021-01-04',
|
'updated_at': '2021-01-04',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
'schedule_name': 'test_schedule_name5',
|
||||||
|
'workflow_type': 'simple_metrics',
|
||||||
|
'model_name': 'test_model_name',
|
||||||
|
'model_id': 'test_model_id',
|
||||||
|
'updated_at': '2021-01-05',
|
||||||
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,6 +119,10 @@ async def test_process_schedules(
|
|||||||
'test_drift': 'test_drift',
|
'test_drift': 'test_drift',
|
||||||
'updated_at': '2021-01-04',
|
'updated_at': '2021-01-04',
|
||||||
},
|
},
|
||||||
|
'test_schedule_name5': {
|
||||||
|
'test_simple_metrics': 'test_simple_metrics',
|
||||||
|
'updated_at': '2021-01-05',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,6 +130,7 @@ async def test_process_schedules(
|
|||||||
mock_predictions_batch.assert_called_once_with(input_data['pipelines'][1])
|
mock_predictions_batch.assert_called_once_with(input_data['pipelines'][1])
|
||||||
mock_minimal_retrain.assert_called_once_with(input_data['pipelines'][2])
|
mock_minimal_retrain.assert_called_once_with(input_data['pipelines'][2])
|
||||||
mock_drift.assert_called_once_with(input_data['pipelines'][3])
|
mock_drift.assert_called_once_with(input_data['pipelines'][3])
|
||||||
|
mock_simple_metrics.assert_called_once_with(input_data['pipelines'][4])
|
||||||
|
|
||||||
|
|
||||||
@mark.asyncio
|
@mark.asyncio
|
||||||
|
|||||||
@@ -18,8 +18,7 @@ metadata = {
|
|||||||
|
|
||||||
|
|
||||||
@fixture
|
@fixture
|
||||||
@patch('orchestrator.activities.temporal_manager.Client.connect')
|
def temporal_manager():
|
||||||
def temporal_manager(connect_mock):
|
|
||||||
temporal_manager = TemporalManager(
|
temporal_manager = TemporalManager(
|
||||||
host='localhost:7233',
|
host='localhost:7233',
|
||||||
scouter_namespace='scouter',
|
scouter_namespace='scouter',
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ from orchestrator.utils.orchestrator_functions import (
|
|||||||
predictions_batch,
|
predictions_batch,
|
||||||
process_path_priority,
|
process_path_priority,
|
||||||
scouter,
|
scouter,
|
||||||
|
simple_metrics,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -66,6 +67,36 @@ def test_drift():
|
|||||||
assert result == expected
|
assert result == expected
|
||||||
|
|
||||||
|
|
||||||
|
def test_simple_metrics():
|
||||||
|
config = {
|
||||||
|
'workflow_type': 'simple_metrics',
|
||||||
|
'schedule_name': 'test_schedule',
|
||||||
|
'model_id': 'test_model_id',
|
||||||
|
'model': {'name': 'test_model_name', 'model_config': {'test_config': 'test_config'}},
|
||||||
|
'interval_minutes': 120,
|
||||||
|
'metrics': ['rmse', 'mse'],
|
||||||
|
}
|
||||||
|
result = simple_metrics(config)
|
||||||
|
expected = {
|
||||||
|
'workflow_type': 'simple_metrics',
|
||||||
|
'schedule_name': 'test_schedule',
|
||||||
|
'frequency': '1m',
|
||||||
|
'offset': '0m',
|
||||||
|
'max_retry_policy': 1,
|
||||||
|
'model_id': 'test_model_id',
|
||||||
|
'model_name': 'test_model_name',
|
||||||
|
'model_config': {'test_config': 'test_config'},
|
||||||
|
'schema': 'sientia_data',
|
||||||
|
'predictions_table_name': 'predictions',
|
||||||
|
'data_table_name': 'laborious_data',
|
||||||
|
'interval_minutes': 120,
|
||||||
|
'metrics': ['rmse', 'mse'],
|
||||||
|
'execution_timeout_seconds': 300,
|
||||||
|
'task_timeout_seconds': 300,
|
||||||
|
}
|
||||||
|
assert result == expected
|
||||||
|
|
||||||
|
|
||||||
def test_minimal_retrain():
|
def test_minimal_retrain():
|
||||||
config = {
|
config = {
|
||||||
'workflow_type': 'minimal_retrain',
|
'workflow_type': 'minimal_retrain',
|
||||||
|
|||||||
Reference in New Issue
Block a user