Skip to content

Commit

Permalink
Resolve unexpected errors when statuses other than 'running' or 'idle…
Browse files Browse the repository at this point in the history
…' is received (#9428)

* traceback error

* fix KeyError

Possible to receive undocumented status e.g. receiving,sending

* Update metadata

* typo

* typo

* adjust test

* Apply suggestions from code review

Co-authored-by: Florian Veaux <florian.veaux@datadoghq.com>

* adjust test

Co-authored-by: Florian Veaux <florian.veaux@datadoghq.com>
  • Loading branch information
ian28223 and FlorianVeaux authored May 31, 2021
1 parent 04a6651 commit c0d4e94
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
11 changes: 8 additions & 3 deletions sap_hana/datadog_checks/sap_hana/sap_hana.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def check(self, instance):
self.log.error('Error querying %s: %s', e.source(), str(e))
continue
except Exception as e:
self.log.error('Unexpected error running `%s`: %s', query_method.__name__, str(e))
self.log.exception('Unexpected error running `%s`: %s', query_method.__name__, str(e))
continue
finally:
if self._connection_lost:
Expand Down Expand Up @@ -183,8 +183,9 @@ def query_licenses(self):
self.gauge('license.utilized', utilized, tags=tags, hostname=host)

def query_connection_overview(self):
# https://help.sap.com/viewer/4fe29514fd584807ac9f2a04f6754767/2.0.02/en-US/20abcf1f75191014a254a82b3d0f66bf.html
db_counts = defaultdict(lambda: {'running': 0, 'idle': 0})
# https://help.sap.com/viewer/4fe29514fd584807ac9f2a04f6754767/2.0.05/en-US/20abcf1f75191014a254a82b3d0f66bf.html
# Documented statuses: RUNNING, IDLE, QUEUING, EMPTY
db_counts = defaultdict(lambda: defaultdict(int))
for conn in self.iter_rows(queries.GlobalSystemConnectionsStatus):
db_counts[(conn['db_name'], conn['host'], conn['port'])][conn['status'].lower()] += conn['total']

Expand All @@ -196,10 +197,14 @@ def query_connection_overview(self):
host = self.get_hana_hostname(host)
running = counts['running']
idle = counts['idle']
queuing = counts['queuing']
empty = counts['empty']

self.gauge('connection.running', running, tags=tags, hostname=host)
self.gauge('connection.idle', idle, tags=tags, hostname=host)
self.gauge('connection.open', running + idle, tags=tags, hostname=host)
self.gauge('connection.queuing', queuing, tags=tags, hostname=host)
self.gauge('connection.empty', empty, tags=tags, hostname=host)

def query_disk_usage(self):
# https://help.sap.com/viewer/4fe29514fd584807ac9f2a04f6754767/2.0.02/en-US/a2aac2ee72b341699fa8eb3988d8cecb.html
Expand Down
2 changes: 2 additions & 0 deletions sap_hana/metadata.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ sap_hana.backup.latest,gauge,,second,,The time elapsed since the latest database
sap_hana.connection.idle,gauge,,connection,,The current number of idle connections.,0,sap_hana,
sap_hana.connection.open,gauge,,connection,,The current number of connections.,0,sap_hana,
sap_hana.connection.running,gauge,,connection,,The current number of running connections.,0,sap_hana,
sap_hana.connection.queuing,gauge,,connection,,The current number of queued connections.,0,sap_hana,
sap_hana.connection.empty,gauge,,connection,,Historic connections that are removed after a period of time.,0,sap_hana,
sap_hana.cpu.service.utilized,gauge,,percent,,The CPU utilization of services as a percentage.,0,sap_hana,
sap_hana.disk.free,gauge,,byte,,The total free size of the disk in bytes.,1,sap_hana,
sap_hana.disk.size,gauge,,byte,,The total size of the disk in bytes.,0,sap_hana,
Expand Down
2 changes: 2 additions & 0 deletions sap_hana/tests/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
'sap_hana.connection.idle',
'sap_hana.connection.open',
'sap_hana.connection.running',
'sap_hana.connection.queuing',
'sap_hana.connection.empty',
'sap_hana.cpu.service.utilized',
'sap_hana.disk.free',
'sap_hana.disk.size',
Expand Down
2 changes: 1 addition & 1 deletion sap_hana/tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def query_master_database():
check.query_master_database = query_master_database

check.check(None)
check.log.error.assert_any_call('Unexpected error running `%s`: %s', 'query_master_database', 'test')
check.log.exception.assert_any_call('Unexpected error running `%s`: %s', 'query_master_database', 'test')


def test_custom_query_configuration(instance):
Expand Down

0 comments on commit c0d4e94

Please sign in to comment.