Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more precise generic healthcheck #2519

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion api_app/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,20 @@ def health_check(self, user: User = None) -> bool:
# momentarily set this to False to
# avoid fails for https services
response = requests.head(url, timeout=10, verify=False)
# This may happen when even the HEAD request is protected by authentication
# We cannot create a generic health check that consider auth too
# because every analyzer has its own way to authenticate
# So, in this case, we will consider it as check passed because we got an answer
# For ex 405 code is when HEADs are not allowed. But it is the same. The service answered.
if 400 <= response.status_code <= 408:
return True
response.raise_for_status()
except (
requests.exceptions.ConnectionError,
requests.exceptions.Timeout,
requests.exceptions.HTTPError,
) as e:
logger.info(f"healthcheck failed: url {url}" f" for {self}. Error: {e}")
logger.info(f"healthcheck failed: url {url} for {self}. Error: {e}")
return False
else:
return True
Expand Down
Loading