SIENTIAPDE-988
Enhance ingestor and manager classes with notification handling - Integrated NotificationHandler into Ingestor, DataManager, IngestorManager, and OpcManager for improved error reporting and monitoring. - Updated methods to send notifications on critical events such as Kafka publishing errors, OPC connection issues, and cycle count warnings. - Refactored related tests to ensure coverage of new notification functionalities and validate integration with existing components. - Improved logging and error handling across the system to enhance traceability and operational insights.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from unittest.mock import ANY, MagicMock, patch
|
||||
from pytest import fixture
|
||||
from kafka.errors import NoBrokersAvailable
|
||||
|
||||
from sientia_do.notifications.models import NotificationLevel
|
||||
from ingestor.managers.data_manager import DataManager
|
||||
|
||||
|
||||
@@ -10,7 +10,8 @@ from ingestor.managers.data_manager import DataManager
|
||||
def data_manager(kafka):
|
||||
return DataManager(
|
||||
kafka_servers="localhost:9092",
|
||||
logger=MagicMock()
|
||||
logger=MagicMock(),
|
||||
notification_handler=MagicMock()
|
||||
)
|
||||
|
||||
|
||||
@@ -20,7 +21,8 @@ def test___init___success(kafka):
|
||||
|
||||
data_manager = DataManager(
|
||||
kafka_servers="localhost:9092",
|
||||
logger=logger_mock
|
||||
logger=logger_mock,
|
||||
notification_handler=MagicMock()
|
||||
)
|
||||
|
||||
kafka.assert_called_once_with(
|
||||
@@ -46,7 +48,8 @@ def test___init___second_attempt(kafka):
|
||||
|
||||
data_manager = DataManager(
|
||||
kafka_servers="localhost:9092",
|
||||
logger=logger_mock
|
||||
logger=logger_mock,
|
||||
notification_handler=MagicMock()
|
||||
)
|
||||
|
||||
kafka.assert_any_call(
|
||||
@@ -79,7 +82,8 @@ def test___init___failure_max_attempts(kafka):
|
||||
try:
|
||||
DataManager(
|
||||
kafka_servers="localhost:9092",
|
||||
logger=logger_mock
|
||||
logger=logger_mock,
|
||||
notification_handler=MagicMock()
|
||||
)
|
||||
except NoBrokersAvailable as e:
|
||||
assert str(
|
||||
@@ -172,7 +176,8 @@ def test_publish(data_manager):
|
||||
data_manager.kafka_producer.flush.assert_called_once()
|
||||
|
||||
|
||||
def test_publish_error(data_manager):
|
||||
@patch("ingestor.managers.data_manager.traceback")
|
||||
def test_publish_error(traceback, data_manager):
|
||||
topic = "test_topic"
|
||||
data = {"key": "value"}
|
||||
|
||||
@@ -189,6 +194,10 @@ def test_publish_error(data_manager):
|
||||
)
|
||||
|
||||
# Check if the error was logged
|
||||
data_manager.logger.error.assert_called_once_with(
|
||||
"Failed to publish message: Test error"
|
||||
data_manager.notification_handler.build_and_send_notification.assert_called_once_with(
|
||||
notification_id=f"KAFKA_PRODUCER_ERROR_{topic}",
|
||||
message=f"Error publishing message to topic {topic}: Test error",
|
||||
block="kafka_producer",
|
||||
level=NotificationLevel.ERROR,
|
||||
attachment_content=traceback.format_exc.return_value
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user