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