Spaces:
Sleeping
Sleeping
File size: 4,679 Bytes
1d4dc07 f0b765c 1d4dc07 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | #!/usr/bin/env python3
"""
Deployment readiness check for Atlas analytics system
"""
import asyncio
import os
import sys
from dotenv import load_dotenv
load_dotenv()
async def check_environment_variables():
"""Check if all required environment variables are set"""
print("π Environment Variables Check")
print("=" * 40)
required_vars = {
"GOOGLE_API_KEY": "Google Gemini API",
"BRAVE_API_KEY": "Brave Search API",
"MONGODB_URL": "MongoDB Atlas connection",
"MONGODB_DATABASE": "MongoDB database name"
}
all_set = True
for var, description in required_vars.items():
value = os.getenv(var)
if value:
print(f"β
{var}: Set ({description})")
else:
print(f"β {var}: Missing ({description})")
all_set = False
return all_set
async def check_database_connection():
"""Check MongoDB connection"""
print("\nποΈ Database Connection Check")
print("=" * 40)
try:
from analytics.database import test_connection
connected = await test_connection()
if connected:
print("β
MongoDB connection successful")
return True
else:
print("β MongoDB connection failed")
return False
except Exception as e:
print(f"β Database connection error: {e}")
return False
async def check_analytics_system():
"""Check analytics system functionality"""
print("\nπ Analytics System Check")
print("=" * 40)
try:
# Test dashboard
from analytics.dashboard import get_basic_stats
stats = await get_basic_stats()
if "error" in stats:
print(f"β Dashboard error: {stats['error']}")
return False
else:
print("β
Dashboard working")
print(f" Sessions: {stats.get('total_sessions', 0)}")
print(f" Messages: {stats.get('total_messages', 0)}")
# Test collectors
from analytics.collectors import create_session
test_session = await create_session(user_agent="Deployment Test")
if test_session:
print("β
Session creation working")
else:
print("β Session creation failed")
return False
return True
except Exception as e:
print(f"β Analytics system error: {e}")
return False
async def check_dependencies():
"""Check if all required packages are available"""
print("\nπ¦ Dependencies Check")
print("=" * 40)
required_packages = [
("fastapi", "FastAPI web framework"),
("motor", "MongoDB async driver"),
("google.generativeai", "Google Gemini API"),
("httpx", "HTTP client"),
("pydantic", "Data validation"),
("dotenv", "Environment variables")
]
all_available = True
for package, description in required_packages:
try:
__import__(package.replace("-", "_"))
print(f"β
{package}: Available ({description})")
except ImportError:
print(f"β {package}: Missing ({description})")
all_available = False
return all_available
async def main():
"""Run all deployment checks"""
print("π Atlas Analytics Deployment Check")
print("=" * 50)
checks = [
("Environment Variables", check_environment_variables()),
("Dependencies", check_dependencies()),
("Database Connection", check_database_connection()),
("Analytics System", check_analytics_system())
]
results = []
for name, check_coro in checks:
try:
result = await check_coro
results.append((name, result))
except Exception as e:
print(f"β {name} check failed: {e}")
results.append((name, False))
# Summary
print("\nπ Deployment Readiness Summary")
print("=" * 50)
all_passed = True
for name, passed in results:
status = "β
PASS" if passed else "β FAIL"
print(f"{status} {name}")
if not passed:
all_passed = False
print("\n" + "=" * 50)
if all_passed:
print("π DEPLOYMENT READY: All checks passed!")
print(" You can deploy the Atlas analytics system.")
sys.exit(0)
else:
print("β οΈ DEPLOYMENT NOT READY: Some checks failed.")
print(" Please fix the issues above before deploying.")
sys.exit(1)
if __name__ == "__main__":
asyncio.run(main()) |