Enhanced: Comprehensive production debugging and Nginx proxy support
Debugging Tools: - Added /debug endpoint to verify deployment and test distribution functionality - Added browser console test function: testDistributionChart() - Enhanced SocketIO settings with better transport priorities - Added comprehensive error tracking and status reporting Nginx Configuration: - Created NGINX_CONFIG.md with complete proxy setup guide - Improved WebSocket transport settings and timeouts - Better ping/pong settings for connection stability Production Compatibility: - Optimized SocketIO for proxy environments - Enhanced fallback mechanisms - Production-ready logging and error handling This should resolve proxy-related issues and provide clear diagnostic tools.
This commit is contained in:
@@ -15,8 +15,13 @@ from app.models import SimulationManager
|
||||
socketio = SocketIO(
|
||||
cors_allowed_origins="*",
|
||||
async_mode='threading',
|
||||
logger=True,
|
||||
engineio_logger=True
|
||||
logger=False, # Disable to avoid log spam in production
|
||||
engineio_logger=False,
|
||||
# Transport order: try websocket first, then polling
|
||||
transports=['websocket', 'polling'],
|
||||
# Ping settings for better connection detection
|
||||
ping_timeout=60,
|
||||
ping_interval=25
|
||||
)
|
||||
|
||||
# Global simulation manager instance
|
||||
@@ -45,7 +50,9 @@ def create_app(config_name=None):
|
||||
async_mode='threading',
|
||||
cors_allowed_origins="*",
|
||||
allow_upgrades=True,
|
||||
transports=['websocket', 'polling']
|
||||
transports=['websocket', 'polling'],
|
||||
ping_timeout=60,
|
||||
ping_interval=25
|
||||
)
|
||||
|
||||
# Register blueprints
|
||||
|
@@ -101,6 +101,59 @@ def results(simulation_id):
|
||||
title=f"Results - Simulation {simulation_id[:8]}")
|
||||
|
||||
|
||||
@main_bp.route('/debug')
|
||||
def debug_info():
|
||||
"""
|
||||
Debug endpoint to verify deployment and test functionality.
|
||||
|
||||
Returns:
|
||||
JSON response with debug information
|
||||
"""
|
||||
import os
|
||||
from datetime import datetime
|
||||
from app.models.economic_model import EconomicSimulation, SimulationParameters
|
||||
|
||||
# Test distribution functionality
|
||||
test_params = SimulationParameters(
|
||||
r_rate=0.05,
|
||||
g_rate=0.03,
|
||||
initial_capital=1000,
|
||||
initial_consumption=1000,
|
||||
num_agents=10,
|
||||
iterations=5
|
||||
)
|
||||
|
||||
test_sim = EconomicSimulation(test_params)
|
||||
# Run a few steps
|
||||
for _ in range(5):
|
||||
test_sim.step()
|
||||
|
||||
# Get distribution data
|
||||
labels, counts = test_sim.get_wealth_histogram(5)
|
||||
|
||||
debug_data = {
|
||||
'timestamp': datetime.now().isoformat(),
|
||||
'environment': os.getenv('FLASK_ENV', 'unknown'),
|
||||
'config': os.getenv('FLASK_CONFIG', 'unknown'),
|
||||
'python_version': os.sys.version,
|
||||
'distribution_test': {
|
||||
'labels': labels,
|
||||
'counts': counts,
|
||||
'total_agents': len(test_sim.agents),
|
||||
'snapshots': len(test_sim.snapshots)
|
||||
},
|
||||
'fixes_deployed': {
|
||||
'fallback_polling': True,
|
||||
'enhanced_socketio': True,
|
||||
'production_debug': True,
|
||||
'environment_fix': True
|
||||
},
|
||||
'version_info': 'v2.1-proxy-fixes'
|
||||
}
|
||||
|
||||
return jsonify(debug_data)
|
||||
|
||||
|
||||
@main_bp.route('/health')
|
||||
def health_check():
|
||||
"""
|
||||
|
@@ -1,3 +1,63 @@
|
||||
/**
|
||||
* Production debugging test function
|
||||
* Call from browser console: testDistributionChart()
|
||||
*/
|
||||
window.testDistributionChart = function() {
|
||||
debugLog('=== DISTRIBUTION CHART DIAGNOSTIC TEST ===');
|
||||
|
||||
// Test 1: Check if elements exist
|
||||
const canvas = document.getElementById('distributionChart');
|
||||
debugLog('Canvas element found', !!canvas);
|
||||
|
||||
// Test 2: Check Chart.js availability
|
||||
debugLog('Chart.js available', typeof Chart !== 'undefined');
|
||||
|
||||
// Test 3: Check chart instance
|
||||
debugLog('Chart instance exists', !!charts.distribution);
|
||||
|
||||
// Test 4: Check current data
|
||||
debugLog('Current simulation data', {
|
||||
hasId: !!currentSimulation.id,
|
||||
isRunning: currentSimulation.isRunning,
|
||||
distributionData: currentSimulation.data.distribution
|
||||
});
|
||||
|
||||
// Test 5: Check WebSocket connection
|
||||
debugLog('WebSocket status', {
|
||||
socketExists: !!window.MarkovEconomics.socket,
|
||||
isConnected: window.MarkovEconomics ? window.MarkovEconomics.isConnected : 'unknown'
|
||||
});
|
||||
|
||||
// Test 6: Manually test API endpoint
|
||||
if (currentSimulation.id) {
|
||||
fetch(`/api/simulation/${currentSimulation.id}/distribution?bins=5`)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
debugLog('Manual API test result', data);
|
||||
})
|
||||
.catch(error => {
|
||||
debugLog('Manual API test failed', error);
|
||||
});
|
||||
}
|
||||
|
||||
// Test 7: Try to create test data and update chart
|
||||
if (charts.distribution) {
|
||||
const testLabels = ['$0-100', '$100-200', '$200-300'];
|
||||
const testCounts = [5, 8, 2];
|
||||
|
||||
try {
|
||||
charts.distribution.data.labels = testLabels;
|
||||
charts.distribution.data.datasets[0].data = testCounts;
|
||||
charts.distribution.update();
|
||||
debugLog('Manual chart update test: SUCCESS');
|
||||
} catch (error) {
|
||||
debugLog('Manual chart update test: FAILED', error);
|
||||
}
|
||||
}
|
||||
|
||||
debugLog('=== TEST COMPLETE ===');
|
||||
};
|
||||
|
||||
// Debug flag - can be enabled even in production for troubleshooting
|
||||
const DEBUG_DISTRIBUTION = true;
|
||||
|
||||
|
Reference in New Issue
Block a user