Refactor metrics handling and improve logging

- Removed the MetricsManager initialization from `run_helper.py` to avoid duplication, as metrics are now handled in `main.py`.
- Updated logging levels in `server_prometheus.py` and `metrics_middleware.py` to use debug instead of info for less critical messages.
- Added metrics configuration to `BaseDependencyFactory` for better management of metrics settings.
- Deleted the obsolete `metrics_exporter.py` file to streamline the codebase.
- Updated various tests to reflect changes in the metrics handling and ensure proper functionality.
This commit is contained in:
2025-09-03 00:33:20 +03:00
parent 6fcecff97c
commit c8c7d50cbb
19 changed files with 402 additions and 605 deletions

View File

@@ -63,18 +63,23 @@ class TestVoiceHandler:
@pytest.mark.asyncio
async def test_voice_bot_button_handler_welcome_received(self, voice_handler, mock_message, mock_state, mock_db, mock_settings):
"""Тест обработчика кнопки когда приветствие уже получено"""
mock_db.check_voice_bot_welcome_received.return_value = True
from unittest.mock import AsyncMock
mock_db.check_voice_bot_welcome_received = AsyncMock(return_value=True)
with patch.object(voice_handler, 'restart_function') as mock_restart:
await voice_handler.voice_bot_button_handler(mock_message, mock_state, mock_db, mock_settings)
mock_db.check_voice_bot_welcome_received.assert_called_once_with(123)
mock_restart.assert_called_once_with(mock_message, mock_state, mock_db, mock_settings)
with patch('helper_bot.handlers.voice.voice_handler.update_user_info') as mock_update_user:
mock_update_user.return_value = None
await voice_handler.voice_bot_button_handler(mock_message, mock_state, mock_db, mock_settings)
mock_db.check_voice_bot_welcome_received.assert_called_once_with(123)
mock_restart.assert_called_once_with(mock_message, mock_state, mock_db, mock_settings)
@pytest.mark.asyncio
async def test_voice_bot_button_handler_welcome_not_received(self, voice_handler, mock_message, mock_state, mock_db, mock_settings):
"""Тест обработчика кнопки когда приветствие не получено"""
mock_db.check_voice_bot_welcome_received.return_value = False
from unittest.mock import AsyncMock
mock_db.check_voice_bot_welcome_received = AsyncMock(return_value=False)
with patch.object(voice_handler, 'start') as mock_start:
await voice_handler.voice_bot_button_handler(mock_message, mock_state, mock_db, mock_settings)