Skip to content

Commit b08240f

Browse files
alanbchristieAlan Christie
and
Alan Christie
authored
fix: Fix for tunnel connection failure metrics (#597)
Co-authored-by: Alan Christie <alan.christie@matildapeak.com>
1 parent c909329 commit b08240f

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

api/security.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from django.db.models import Q
1313
from django.http import Http404, HttpResponse
1414
from ispyb.connector.mysqlsp.main import ISPyBMySQLSPConnector as Connector
15-
from ispyb.connector.mysqlsp.main import ISPyBNoResultException
15+
from ispyb.exception import ISPyBConnectionException, ISPyBNoResultException
1616
from rest_framework import viewsets
1717

1818
from viewer.models import Project
@@ -102,16 +102,23 @@ def get_remote_conn(force_error_display=False) -> Optional[SSHConnector]:
102102
conn: Optional[SSHConnector] = None
103103
try:
104104
conn = SSHConnector(**credentials)
105+
except ISPyBConnectionException:
106+
# Got SSH tunnel but the ISPyB connection failed
107+
PrometheusMetrics.new_tunnel()
105108
except Exception:
109+
# Any other exception will be a problem with the SSH tunnel connection
110+
PrometheusMetrics.failed_tunnel()
106111
if logging.DEBUG >= logger.level or force_error_display:
107112
logger.info("credentials=%s", credentials)
108113
logger.exception("Got the following exception creating Connector...")
109-
if conn:
110-
logger.debug("Got remote connector")
114+
else:
115+
# No exception - we must have created an SSH tunnel
111116
PrometheusMetrics.new_tunnel()
117+
118+
if conn:
119+
logger.debug("Got remote ISPyB connector")
112120
else:
113-
logger.debug("Failed to get a remote connector")
114-
PrometheusMetrics.failed_tunnel()
121+
logger.debug("Failed to get a remote ISPyB connector")
115122

116123
return conn
117124

0 commit comments

Comments
 (0)