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

Fix for tunnel connection failure metrics #597

Merged
merged 1 commit into from
May 23, 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
17 changes: 12 additions & 5 deletions api/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from django.db.models import Q
from django.http import Http404, HttpResponse
from ispyb.connector.mysqlsp.main import ISPyBMySQLSPConnector as Connector
from ispyb.connector.mysqlsp.main import ISPyBNoResultException
from ispyb.exception import ISPyBConnectionException, ISPyBNoResultException
from rest_framework import viewsets

from viewer.models import Project
Expand Down Expand Up @@ -102,16 +102,23 @@ def get_remote_conn(force_error_display=False) -> Optional[SSHConnector]:
conn: Optional[SSHConnector] = None
try:
conn = SSHConnector(**credentials)
except ISPyBConnectionException:
# Got SSH tunnel but the ISPyB connection failed
PrometheusMetrics.new_tunnel()
except Exception:
# Any other exception will be a problem with the SSH tunnel connection
PrometheusMetrics.failed_tunnel()
if logging.DEBUG >= logger.level or force_error_display:
logger.info("credentials=%s", credentials)
logger.exception("Got the following exception creating Connector...")
if conn:
logger.debug("Got remote connector")
else:
# No exception - we must have created an SSH tunnel
PrometheusMetrics.new_tunnel()

if conn:
logger.debug("Got remote ISPyB connector")
else:
logger.debug("Failed to get a remote connector")
PrometheusMetrics.failed_tunnel()
logger.debug("Failed to get a remote ISPyB connector")

return conn

Expand Down