rabbitmq / rabbitmq-management

RabbitMQ Management UI and HTTP API
https://www.rabbitmq.com/management.html
Other
370 stars 165 forks source link

Make healthchecks failures return an HTTP 500 instead of 200. #841

Closed coderanger closed 3 years ago

coderanger commented 4 years ago

Fixes #840.

My Erlang is extremely rusty so this might be entirely the wrong way to do this, but I figured I would try.

pivotal-issuemaster commented 4 years ago

@coderanger Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

pivotal-issuemaster commented 4 years ago

@coderanger Thank you for signing the Contributor License Agreement!

michaelklishin commented 4 years ago

@essen is there are more typical way of returning a 500 response in modern Cowboy?

essen commented 4 years ago

It's a response like any other so cowboy_req:reply is the way to go.

coderanger commented 4 years ago

Is the way I'm calling it correct? Most of the examples were a lot simpler so I wasn't entirely certain if I plugged it all together correctly :)

essen commented 4 years ago

Assuming Response is the response body yes. Sorry I'm not available to check further at the moment.

michaelklishin commented 3 years ago

To reproduce a failure, use a very low timeout:

curl -v -H "Accept:application/json" -H "timeout: 1" -u guest:guest "http://localhost:15672/api/healthchecks/node"

which will return

< HTTP/1.1 500 Internal Server Error
< cache-control: no-cache
< content-length: 38
< content-security-policy: script-src 'self' 'unsafe-eval' 'unsafe-inline'; object-src 'self'
< content-type: application/json
< date: Wed, 09 Sep 2020 12:19:22 GMT
< server: Cowboy
< vary: accept, accept-encoding, origin
{
  "status": "failed",
  "reason": "timeout"
}
michaelklishin commented 3 years ago

Thank you!

michaelklishin commented 3 years ago

Backported to v3.8.x.