Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ pip install allgreen[fastapi]

### 1. Create your health checks

Create an `allgood.py` file in your project root:
Create an `allgreen.py` file in your project root:

```python
# allgood.py
# allgreen.py

@check("Database connection is healthy")
def database_check():
Expand Down Expand Up @@ -248,7 +248,7 @@ app = Flask(__name__)
mount_healthcheck(
app,
app_name="My Flask API",
config_path="config/allgood.py",
config_path="config/allgreen.py",
environment="production"
)

Expand Down Expand Up @@ -306,8 +306,8 @@ async def health(request: Request):

Check out the `examples/` directory for complete working examples:

- **[`examples/allgood.py`](examples/allgood.py)** - Basic health checks configuration
- **[`examples/advanced_allgood.py`](examples/advanced_allgood.py)** - Advanced features (timeouts, rate limiting)
- **[`examples/allgreen.py`](examples/allgreen.py)** - Basic health checks configuration
- **[`examples/advanced_allgreen.py`](examples/advanced_allgreen.py)** - Advanced features (timeouts, rate limiting)
- **[`examples/core_only_example.py`](examples/core_only_example.py)** - Core-only usage (no web dependencies)
- **[`examples/flask_example.py`](examples/flask_example.py)** - Flask integration example
- **[`examples/django_example.py`](examples/django_example.py)** - Django integration example
Expand All @@ -317,8 +317,8 @@ Check out the `examples/` directory for complete working examples:

Allgreen automatically looks for configuration files in these locations:

1. `allgood.py` (project root)
2. `config/allgood.py`
1. `allgreen.py` (project root)
2. `config/allgreen.py`
3. Custom path via `config_path` parameter

## πŸŽ›οΈ Environment Variables
Expand Down
10 changes: 5 additions & 5 deletions allgreen/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ def __init__(self, config_path: str | None = None):
self._loaded_path: str | None = None

def find_config_file(self) -> str | None:
"""Find allgood.py configuration file in standard locations."""
"""Find allgreen.py configuration file in standard locations."""
if self.config_path:
if os.path.exists(self.config_path):
return os.path.abspath(self.config_path)
raise FileNotFoundError(f"Config file not found: {self.config_path}")

# Standard locations to check
possible_paths = [
"allgood.py",
"config/allgood.py",
os.path.join(os.getcwd(), "allgood.py"),
os.path.join(os.getcwd(), "config", "allgood.py"),
"allgreen.py",
"config/allgreen.py",
os.path.join(os.getcwd(), "allgreen.py"),
os.path.join(os.getcwd(), "config", "allgreen.py"),
]

for path in possible_paths:
Expand Down
24 changes: 19 additions & 5 deletions allgreen/integrations/django_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
# ... other apps
'allgreen',
]
2. Create health checks in allgood.py file in your project root

2. Create health checks in allgreen.py file in your project root

Usage:
# In urls.py
from allgreen.integrations import django_integration

urlpatterns = [
path('healthcheck/', django_integration.healthcheck_view, name='healthcheck'),
]
Expand Down Expand Up @@ -85,7 +85,7 @@ def healthcheck_view(
Args:
request: Django HTTP request
app_name: Application name to display
config_path: Path to allgood.py config file
config_path: Path to allgreen.py config file
environment: Environment name (defaults to 'development')
"""

Expand Down Expand Up @@ -118,8 +118,22 @@ def healthcheck_view(
)
else:
# Return HTML response
# Add formatted duration for template compatibility
formatted_results = []
for check, result in results:
# Create a copy of result with formatted duration
result_dict = {
'status': result.status,
'message': result.message,
'error': result.error,
'duration_ms': result.duration_ms,
'duration_formatted': f"{result.duration_ms:.1f}" if result.duration_ms is not None else None,
'skip_reason': result.skip_reason,
}
formatted_results.append((check, type('Result', (), result_dict)()))

context = {
'results': results,
'results': formatted_results,
'stats': stats,
'overall_status': overall_status,
'app_name': app_name,
Expand Down
2 changes: 1 addition & 1 deletion allgreen/integrations/fastapi_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def create_router(

Args:
app_name: Application name to display
config_path: Path to allgood.py config file
config_path: Path to allgreen.py config file
environment: Environment name
prefix: URL prefix for routes (use with app.include_router(router, prefix="/..."))

Expand Down
6 changes: 3 additions & 3 deletions allgreen/templates/healthcheck.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Health Check - {{ app_name|default:"Application" }}</title>
<title>Health Check - {% if app_name %}{{ app_name }}{% else %}Application{% endif %}</title>
<style>
:root {
--bg-color: #ffffff;
Expand Down Expand Up @@ -261,7 +261,7 @@ <h1>
Health Check
{% endif %}
</h1>
<p>{{ app_name|default:"Application" }} Status</p>
<p>{% if app_name %}{{ app_name }}{% else %}Application{% endif %} Status</p>
</div>

<div class="container">
Expand Down Expand Up @@ -300,7 +300,7 @@ <h1>
{% endif %}
<div class="check-title">{{ check.description }}</div>
{% if result.duration_ms is not none %}
<div class="check-duration">{{ result.duration_ms|floatformat:1 }}ms</div>
<div class="check-duration">{{ result.duration_formatted }}ms</div>
{% endif %}
</div>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Advanced allgood.py configuration demonstrating rate limiting and timeouts
# Advanced allgreen.py configuration demonstrating rate limiting and timeouts

@check("Basic health check")
def basic_check():
Expand Down
2 changes: 1 addition & 1 deletion examples/allgood.py β†’ examples/allgreen.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sample allgood.py configuration file
# Sample allgreen.py configuration file
# This demonstrates various types of health checks

@check("Basic truth check")
Expand Down
2 changes: 1 addition & 1 deletion examples/core_only_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def run_health_checks():
"""Run all health checks and return results."""
# Load additional checks from config file (if available)
try:
load_config("examples/allgood.py", "development")
load_config("examples/allgreen.py", "development")
except Exception:
print("πŸ’‘ No config file found, using inline checks only")

Expand Down
2 changes: 1 addition & 1 deletion examples/django_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def index(request):
print("πŸš€ Django + Allgreen Example")
print("πŸ“‹ Health checks: http://localhost:8000/healthcheck/")
print("πŸ”§ JSON API: http://localhost:8000/healthcheck/?format=json")
print("πŸ’‘ Using config: examples/allgood.py")
print("πŸ’‘ Using config: examples/allgreen.py")
print()

# Run Django dev server
Expand Down
4 changes: 2 additions & 2 deletions examples/fastapi_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async def index():
# Method 1: Mount the health check router
health_router = create_router(
app_name="FastAPI Example App",
config_path="examples/allgood.py",
config_path="examples/allgreen.py",
environment="development"
)
app.include_router(health_router)
Expand All @@ -52,7 +52,7 @@ async def health_check(request: Request):
return await healthcheck_endpoint(
request,
app_name="FastAPI Direct Endpoint",
config_path="examples/allgood.py",
config_path="examples/allgreen.py",
environment="development"
)

Expand Down
2 changes: 1 addition & 1 deletion examples/flask_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def index():
mount_healthcheck(
app,
app_name="Flask Example App",
config_path="examples/allgood.py",
config_path="examples/allgreen.py",
environment="development"
)

Expand Down
4 changes: 2 additions & 2 deletions test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

if __name__ == "__main__":
print("πŸš€ Starting allgreen health check server...")
print("πŸ“‹ Config: examples/allgood.py")
print("πŸ“‹ Config: examples/allgreen.py")
print("🌐 URL: http://127.0.0.1:5000/healthcheck")
print("πŸ”§ Environment: development")
print()

run_standalone(
app_name="Allgreen Test Server",
config_path="examples/allgood.py",
config_path="examples/allgreen.py",
environment="development",
host="127.0.0.1",
port=5000,
Expand Down
6 changes: 3 additions & 3 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
def test_find_config_file():
# Test with a temporary config file
with tempfile.TemporaryDirectory() as tmpdir:
config_path = os.path.join(tmpdir, "allgood.py")
config_path = os.path.join(tmpdir, "allgreen.py")
with open(config_path, 'w') as f:
f.write('# test config')

Expand All @@ -17,7 +17,7 @@ def test_find_config_file():
os.chdir(tmpdir)
found_path = find_config()
assert found_path is not None
assert found_path.endswith("allgood.py")
assert found_path.endswith("allgreen.py")
finally:
os.chdir(original_cwd)

Expand Down Expand Up @@ -63,7 +63,7 @@ def math_check():


def test_load_nonexistent_config():
success = load_config("/nonexistent/path/allgood.py")
success = load_config("/nonexistent/path/allgreen.py")
assert not success, "Should fail to load nonexistent config"


Expand Down