navapbc / template-application-flask

Apache License 2.0
9 stars 4 forks source link

Don't log health check endpoint accesses when the request is coming from AWS #115

Open lorenyu opened 1 year ago

lorenyu commented 1 year ago

To avoid cluttering the logs, consider removing access logs for the health check endpoint when they are coming from AWS

Implementation note

one possible way to filter is to check if request path is healthcheck and check if user agent starts with ELB-HealthChecker/

jamesbursa commented 1 year ago

Sample function that was used in AWS:

def is_load_balancer_health_check(request):
    """Test if the request comes from a load balancer."""
    return request.path == "/v1/status" and request.headers.get("User-Agent", "").startswith(
        "ELB-HealthChecker/"
    )