Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust health check logic of
wait_for_service
function
There are a few potential issues of note with the `wait_for_service` function. This function is intended to check if a service is ready by ensuring its health check passes before interacting with it. * The first potential issue is the URL construction. The string `/healthcheck` is appended to the end of the given URL. This assumes that the URL given does not have a path at all. * The second potential issue has to do with how we check for a "success". The success is determined by receiving any response back from the server. This means that if the server returns an error code, such as `404`, the health check would still pass. Normally health checks must ensure that a 200 status code is returned. To fix these potential issues we addressed them directly. First he URL construction was modified to use the `Url::join` method, as it is aware of relative and absolute path references. Second the reqwest call was re-written to ensure that the response retrieved is an Ok. This didn't have a direct chagne to the logic, but helped with the readability of the next portion, and it ensures that the `response` variable persists beyond a single closure. Third the response's status code is checked with the `http::status::StatusCode::is_success` method. Finally, some comments were added to provide a simple explanation of what the `wait_for_service` function is doing, and some behavior implications. Beyond these changes, no other behavior modifications have been made. This means that the health check still checks to see of the `Response` is able to retrieve a textual representation of the response.
- Loading branch information