feat: Add extended health check endpoint /health/full
- Checks 14 critical endpoints (public + admin pages) - Returns JSON with pass/fail status for each endpoint - HTTP 200 if all OK, HTTP 503 if any failures - Useful for deployment verification and monitoring Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
9fdcee35d0
commit
8ed3724970
87
app.py
87
app.py
@ -781,6 +781,93 @@ def health():
|
||||
return {'status': 'ok'}, 200
|
||||
|
||||
|
||||
@app.route('/health/full')
|
||||
def health_full():
|
||||
"""
|
||||
Extended health check - verifies all critical endpoints.
|
||||
Returns detailed status of each endpoint.
|
||||
Access: /health/full
|
||||
"""
|
||||
results = []
|
||||
all_ok = True
|
||||
|
||||
# List of endpoints to check (path, name)
|
||||
endpoints = [
|
||||
('/', 'Strona główna'),
|
||||
('/login', 'Logowanie'),
|
||||
('/register', 'Rejestracja'),
|
||||
('/companies', 'Katalog firm'),
|
||||
('/release-notes', 'Historia zmian'),
|
||||
('/search?q=test', 'Wyszukiwarka'),
|
||||
('/raporty', 'Raporty'),
|
||||
('/api/companies', 'API: Lista firm'),
|
||||
('/admin/security', 'Admin: Bezpieczeństwo'),
|
||||
('/admin/news', 'Admin: Aktualności'),
|
||||
('/admin/seo', 'Admin: SEO'),
|
||||
('/admin/social-media', 'Admin: Social Media'),
|
||||
('/admin/analytics', 'Admin: Analityka'),
|
||||
]
|
||||
|
||||
# Dodaj losową firmę do sprawdzenia
|
||||
db = SessionLocal()
|
||||
try:
|
||||
random_company = db.query(Company).first()
|
||||
if random_company:
|
||||
endpoints.append((f'/company/{random_company.slug}', f'Profil: {random_company.name[:25]}'))
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
# Testuj każdy endpoint używając test client
|
||||
with app.test_client() as client:
|
||||
for path, name in endpoints:
|
||||
try:
|
||||
response = client.get(path, follow_redirects=False)
|
||||
status = response.status_code
|
||||
|
||||
# 200 = OK, 302 = redirect (np. do logowania) = OK
|
||||
# 500 = błąd serwera, 404 = nie znaleziono
|
||||
if status in (200, 302, 304):
|
||||
results.append({
|
||||
'endpoint': path,
|
||||
'name': name,
|
||||
'status': status,
|
||||
'ok': True
|
||||
})
|
||||
else:
|
||||
results.append({
|
||||
'endpoint': path,
|
||||
'name': name,
|
||||
'status': status,
|
||||
'ok': False
|
||||
})
|
||||
all_ok = False
|
||||
|
||||
except Exception as e:
|
||||
results.append({
|
||||
'endpoint': path,
|
||||
'name': name,
|
||||
'status': 500,
|
||||
'ok': False,
|
||||
'error': str(e)[:100]
|
||||
})
|
||||
all_ok = False
|
||||
|
||||
# Podsumowanie
|
||||
passed = sum(1 for r in results if r['ok'])
|
||||
failed = len(results) - passed
|
||||
|
||||
return {
|
||||
'status': 'ok' if all_ok else 'degraded',
|
||||
'summary': {
|
||||
'total': len(results),
|
||||
'passed': passed,
|
||||
'failed': failed
|
||||
},
|
||||
'endpoints': results,
|
||||
'timestamp': datetime.now().isoformat()
|
||||
}, 200 if all_ok else 503
|
||||
|
||||
|
||||
# ============================================================
|
||||
# PUBLIC ROUTES
|
||||
# ============================================================
|
||||
|
||||
Loading…
Reference in New Issue
Block a user