Remove comments and verbose logging from services
This commit is contained in:
@@ -44,12 +44,6 @@ The system consists of 6 independent microservices coordinated by an API Gateway
|
||||
|
||||
## 🚀 Quick Start
|
||||
|
||||
### Prerequisites
|
||||
- Docker 20.0+
|
||||
- Docker Compose 2.0+
|
||||
- 8GB RAM minimum
|
||||
- 10GB free disk space
|
||||
|
||||
### 1. Deploy the Complete System
|
||||
```bash
|
||||
cd microservices/
|
||||
|
||||
@@ -27,16 +27,12 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
"""Application lifespan manager"""
|
||||
logger.info("API Gateway starting up...")
|
||||
|
||||
# Initialize service registry
|
||||
await service_registry.initialize()
|
||||
|
||||
# Register all services
|
||||
await service_registry.register_services(SERVICES)
|
||||
|
||||
# Start health check task
|
||||
asyncio.create_task(health_check_task())
|
||||
|
||||
logger.info("API Gateway startup complete")
|
||||
|
||||
@@ -39,7 +39,6 @@ class ServiceRegistry:
|
||||
|
||||
logger.info(f"Registered {len(services)} services")
|
||||
|
||||
# Perform initial health check
|
||||
await self.update_all_service_health()
|
||||
|
||||
async def register_service(self, service_config: ServiceConfig):
|
||||
@@ -83,7 +82,6 @@ class ServiceRegistry:
|
||||
if response.status == 200:
|
||||
health_data = await response.json()
|
||||
status = "healthy" if health_data.get("status") in ["healthy", "ok"] else "unhealthy"
|
||||
|
||||
health = ServiceHealth(
|
||||
service=service_name,
|
||||
status=status,
|
||||
@@ -114,10 +112,8 @@ class ServiceRegistry:
|
||||
error_message=f"Health check failed: {str(e)}"
|
||||
)
|
||||
|
||||
# Update health status
|
||||
self.service_health[service_name] = health
|
||||
|
||||
# Log health status changes
|
||||
if health.status != "healthy":
|
||||
logger.warning(f"Service {service_name} health check failed: {health.error_message}")
|
||||
|
||||
@@ -128,13 +124,12 @@ class ServiceRegistry:
|
||||
self.check_service_health(service_name)
|
||||
for service_name in self.services.keys()
|
||||
]
|
||||
|
||||
if health_checks:
|
||||
await asyncio.gather(*health_checks, return_exceptions=True)
|
||||
|
||||
healthy_count = sum(1 for h in self.service_health.values() if h.status == "healthy")
|
||||
total_count = len(self.services)
|
||||
logger.info(f"Health check complete: {healthy_count}/{total_count} services healthy {self.service_health.values()}")
|
||||
logger.info(f"Health check complete: {healthy_count}/{total_count} services healthy")
|
||||
|
||||
async def get_service_health(self, service_name: str) -> Optional[ServiceHealth]:
|
||||
return self.service_health.get(service_name)
|
||||
|
||||
@@ -19,19 +19,12 @@ db_manager = None
|
||||
async def lifespan(app: FastAPI):
|
||||
global ftp_monitor, db_manager
|
||||
|
||||
logger.info("Starting SA4CPS Data Ingestion Service...")
|
||||
|
||||
db_manager = DatabaseManager()
|
||||
await db_manager.connect()
|
||||
logger.info("Database connection established")
|
||||
|
||||
ftp_monitor = FTPMonitor(db_manager)
|
||||
logger.info("FTP monitor created")
|
||||
|
||||
monitoring_task = asyncio.create_task(ftp_monitor.start_monitoring())
|
||||
logger.info("FTP monitoring task started in background")
|
||||
|
||||
logger.info("Service startup complete - HTTP server ready to accept requests")
|
||||
|
||||
yield
|
||||
|
||||
@@ -78,7 +71,8 @@ async def health_check():
|
||||
global ftp_monitor, db_manager
|
||||
|
||||
health_status = {
|
||||
"service": "healthy",
|
||||
"service": "data-ingestion-service",
|
||||
"status": "healthy",
|
||||
"timestamp": datetime.now().isoformat(),
|
||||
"database": "unknown",
|
||||
"ftp_monitor": "unknown"
|
||||
|
||||
@@ -169,7 +169,6 @@ services:
|
||||
# networks:
|
||||
# - energy-network
|
||||
|
||||
# Data Ingestion Service (FTP Monitoring & SA4CPS Integration)
|
||||
data-ingestion-service:
|
||||
build:
|
||||
context: ./data-ingestion-service
|
||||
|
||||
@@ -17,7 +17,6 @@ redis_client: Optional[redis.Redis] = None
|
||||
database = None
|
||||
|
||||
async def connect_to_mongo():
|
||||
"""Connect to MongoDB"""
|
||||
global mongo_client, database
|
||||
|
||||
try:
|
||||
@@ -26,7 +25,6 @@ async def connect_to_mongo():
|
||||
mongo_client = AsyncIOMotorClient(mongo_url)
|
||||
database = mongo_client.energy_dashboard_sensors
|
||||
|
||||
# Test connection
|
||||
await mongo_client.admin.command('ping')
|
||||
logger.info("Connected to MongoDB successfully")
|
||||
|
||||
@@ -35,14 +33,12 @@ async def connect_to_mongo():
|
||||
raise
|
||||
|
||||
async def close_mongo_connection():
|
||||
"""Close MongoDB connection"""
|
||||
global mongo_client
|
||||
if mongo_client:
|
||||
mongo_client.close()
|
||||
logger.info("Closed MongoDB connection")
|
||||
|
||||
async def connect_to_redis():
|
||||
"""Connect to Redis"""
|
||||
global redis_client
|
||||
|
||||
try:
|
||||
@@ -58,9 +54,7 @@ async def connect_to_redis():
|
||||
raise
|
||||
|
||||
async def get_database():
|
||||
"""Get database instance"""
|
||||
return database
|
||||
|
||||
async def get_redis():
|
||||
"""Get Redis client instance"""
|
||||
return redis_client
|
||||
@@ -25,21 +25,17 @@ from room_service import RoomService
|
||||
from analytics_service import AnalyticsService
|
||||
from websocket_manager import WebSocketManager
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# WebSocket manager for real-time updates
|
||||
websocket_manager = WebSocketManager()
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
"""Application lifespan manager"""
|
||||
logger.info("Sensor Service starting up...")
|
||||
await connect_to_mongo()
|
||||
await connect_to_redis()
|
||||
|
||||
# Initialize default rooms if none exist
|
||||
db = await get_database()
|
||||
redis_client = await get_redis()
|
||||
room_service = RoomService(db, redis_client)
|
||||
|
||||
Reference in New Issue
Block a user