feat(dashboard): time range filter for operational metrics (30d/90d/6m/1y/all)
Aegis CI / lint-and-test (push) Waiting to run
Snyk Security Scan / Python vulnerabilities (backend) (push) Waiting to run
Snyk Security Scan / npm vulnerabilities (frontend) (push) Waiting to run
Snyk Security Scan / Docker image vulnerabilities (backend) (push) Waiting to run
Aegis CI / lint-and-test (push) Waiting to run
Snyk Security Scan / Python vulnerabilities (backend) (push) Waiting to run
Snyk Security Scan / npm vulnerabilities (frontend) (push) Waiting to run
Snyk Security Scan / Docker image vulnerabilities (backend) (push) Waiting to run
This commit is contained in:
@@ -19,8 +19,11 @@ from app.dependencies.auth import get_current_user
|
||||
# Import User from app.models.user
|
||||
from app.models.user import User
|
||||
|
||||
from datetime import datetime, date
|
||||
|
||||
# Import from app.services.operational_metrics_service
|
||||
from app.services.operational_metrics_service import (
|
||||
get_all_operational_metrics,
|
||||
get_metrics_by_team,
|
||||
get_operational_trend,
|
||||
)
|
||||
@@ -33,18 +36,20 @@ router = APIRouter(prefix="/metrics/operational", tags=["operational-metrics"])
|
||||
|
||||
|
||||
@router.get("")
|
||||
# Define function operational_metrics
|
||||
def operational_metrics(
|
||||
# Entry: db
|
||||
db: Session = Depends(get_db),
|
||||
# Entry: current_user
|
||||
current_user: User = Depends(get_current_user),
|
||||
since: str | None = Query(None, description="ISO date YYYY-MM-DD — filter metrics to tests on or after this date"),
|
||||
) -> dict:
|
||||
"""Get all operational metrics (MTTD, MTTR, etc.) — cached for 5 min."""
|
||||
# Import get_operational_metrics_cached from app.services.score_cache
|
||||
from app.services.score_cache import get_operational_metrics_cached
|
||||
"""Get all operational metrics (MTTD, MTTR, etc.). Uses cache when no time filter is set."""
|
||||
if since:
|
||||
try:
|
||||
since_dt = datetime.combine(date.fromisoformat(since), datetime.min.time())
|
||||
except ValueError:
|
||||
since_dt = None
|
||||
return get_all_operational_metrics(db, since_dt)
|
||||
|
||||
# Return get_operational_metrics_cached(db)
|
||||
from app.services.score_cache import get_operational_metrics_cached
|
||||
return get_operational_metrics_cached(db)
|
||||
|
||||
|
||||
@@ -70,13 +75,16 @@ def operational_trend(
|
||||
|
||||
|
||||
@router.get("/by-team")
|
||||
# Define function metrics_by_team
|
||||
def metrics_by_team(
|
||||
# Entry: db
|
||||
db: Session = Depends(get_db),
|
||||
# Entry: current_user
|
||||
current_user: User = Depends(get_current_user),
|
||||
since: str | None = Query(None, description="ISO date YYYY-MM-DD — filter to tests on or after this date"),
|
||||
) -> dict:
|
||||
"""Get metrics broken down by Red Team vs Blue Team."""
|
||||
# Return get_metrics_by_team(db)
|
||||
return get_metrics_by_team(db)
|
||||
since_dt = None
|
||||
if since:
|
||||
try:
|
||||
since_dt = datetime.combine(date.fromisoformat(since), datetime.min.time())
|
||||
except ValueError:
|
||||
pass
|
||||
return get_metrics_by_team(db, since_dt)
|
||||
|
||||
Reference in New Issue
Block a user