Skip to content

Commit

Permalink
Fix Metrics for Oracle DPI errors
Browse files Browse the repository at this point in the history
Jira: CDPD-77746

Testing:
Manually tested and was also tested at customer end.
  • Loading branch information
quadoss authored and mbalakrishnan@cloudera.com committed Jan 8, 2025
1 parent 642146b commit 6b151fa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions apps/useradmin/src/useradmin/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from datetime import datetime, timedelta

from django.db import connection
from django.db.utils import OperationalError
from django.db.utils import DatabaseError, OperationalError
from prometheus_client import Gauge

from desktop.lib.metrics import global_registry
Expand All @@ -35,7 +35,7 @@ def active_users():
first_login=False,
hostname__isnull=False
).count()
except OperationalError as oe:
except (OperationalError, DatabaseError) as oe:
LOG.debug('active_users recovering from %s' % str(oe))
connection.close()
connection.connect()
Expand Down Expand Up @@ -67,7 +67,7 @@ def active_users_per_instance():
try:
count = UserProfile.objects.filter(last_activity__gt=datetime.now() - timedelta(hours=1),
hostname=get_localhost_name()).count()
except OperationalError as oe:
except (OperationalError, DatabaseError) as oe:
LOG.debug('active_users_per_instance recovering from %s' % str(oe))
connection.close()
connection.connect()
Expand Down
6 changes: 3 additions & 3 deletions desktop/core/src/desktop/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from datetime import datetime, timedelta

from django.db import connection
from django.db.utils import OperationalError
from django.db.utils import DatabaseError, OperationalError
from future import standard_library
from prometheus_client import REGISTRY, Gauge

Expand Down Expand Up @@ -149,7 +149,7 @@ def user_count():
users = 0
try:
users = User.objects.count()
except OperationalError as oe:
except (OperationalError, DatabaseError) as oe:
LOG.debug('user_count recovering from %s' % str(oe))
connection.close()
connection.connect()
Expand Down Expand Up @@ -207,7 +207,7 @@ def num_of_queries():
is_history=True,
last_modified__gt=datetime.now() - timedelta(minutes=10)
).count()
except OperationalError as oe:
except (OperationalError, DatabaseError) as oe:
LOG.debug('num_of_queries recovering from %s' % str(oe))
connection.close()
connection.connect()
Expand Down

0 comments on commit 6b151fa

Please sign in to comment.