Question

We manage a .net mvc application that is hosted on two AWS machines. An AWS Load Balancer manages the traffic to each machine. The Load Balancer is configured to perform a Health Check to each machine every 30 seconds. It does this with a TCP request to port 80.

The application expects that behind every request is a human, so the Health Check causes side-effects such as unnecessary writes to the database and bloated log files. The tell-tale sign of the Health Check Request is that there is just one key-value-pair in the HttpContext.Request.ServerVariables property: "Host: mysite.com"

How should the application best identify this Health Check Request so that it can respond in a way that causes no side-effects? I am thinking ActionFilter but is there a more accurate way of isolating the request other than checking for a lack of server variables?

Was it helpful?

Solution

In my app, I simply switched to an AWS http check and set up a "Heartbeat" controller with an Index action; there was no logic, but it returned a 200 when AWS hit /Heartbeat. Your IIS log will catch this request by default; your application infrastructure wasn't outlined in your question, but in my case the lack of any logic in the action was sufficient.

http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/gs-ec2classic.html#ConfigureHealthCheck

However, implementing your own IHttpModule is another option here. You're at the raw HttpApplication level here, so you don't tap into the MVC pipeline at this point. I've used it for (among other things), forcing the https redirect in my AWS-hosted apps by looking for the "X-Forwarded-Proto" header.

OTHER TIPS

If anyone would be looking for this in 2018 (like I just was), AWS ELB health check request now has a header "User-Agent=ELB-HealthChecker/2.0"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top