Skip to content

Commit

Permalink
Sy/fix msk (#19552)
Browse files Browse the repository at this point in the history
* allow for check to skip over empty brokerinfo

* changelog

* Update 19552.added

* Update 19552.added
  • Loading branch information
steveny91 authored Feb 4, 2025
1 parent fce85a9 commit 9870517
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
1 change: 1 addition & 0 deletions amazon_msk/changelog.d/19552.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow for check to skip over nodes with empty `BrokerNodeInfo` fields
6 changes: 5 additions & 1 deletion amazon_msk/datadog_checks/amazon_msk/amazon_msk.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ def check(self, _):
self.service_check(self.SERVICE_CHECK_CONNECT, self.OK, tags=self._scraper_config['custom_tags'])

for node_info in response['NodeInfoList']:
broker_info = node_info['BrokerNodeInfo']
broker_info = node_info.get('BrokerNodeInfo')
if not broker_info:
self.log.debug('NodeInfo does not contain BrokerNodeInfo, skipping')
continue

self._scraper_config['_metric_tags'] = ['broker_id:{}'.format(broker_info['BrokerId'])]

for endpoint in broker_info['Endpoints']:
Expand Down
6 changes: 5 additions & 1 deletion amazon_msk/datadog_checks/amazon_msk/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ def refresh_scrapers(self):
scrapers = {}

for node_info in response['NodeInfoList']:
broker_info = node_info['BrokerNodeInfo']
broker_info = node_info.get('BrokerNodeInfo')
if not broker_info:
self.log.debug('NodeInfo does not contain BrokerNodeInfo, skipping')
continue

broker_id_tag = f'broker_id:{broker_info["BrokerId"]}'

for endpoint in broker_info['Endpoints']:
Expand Down
8 changes: 8 additions & 0 deletions amazon_msk/tests/fixtures/list_nodes.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
{
"NodeInfoList": [
{
"nodeType": "CONTROLLER",
"controllerNodeInfo": {
"endpoints": [
"b-2.msk-integrate.ch6uni.c6.kafka.us-east-1.amazonaws.com"
]
}
},
{
"AddedToClusterTime": "2019-11-22T23:44:28.725Z",
"BrokerNodeInfo": {
Expand Down
13 changes: 10 additions & 3 deletions amazon_msk/tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def test_node_check_legacy(aggregator, instance_legacy, mock_client):
aggregator.assert_service_check(c.SERVICE_CHECK_CONNECT, c.OK, tags=global_tags)

for node_info in client.list_nodes()['NodeInfoList']:
broker_info = node_info['BrokerNodeInfo']
broker_info = node_info.get('BrokerNodeInfo')
if broker_info is None:
continue
broker_tags = ['broker_id:{}'.format(broker_info['BrokerId'])]
broker_tags.extend(global_tags)

Expand Down Expand Up @@ -99,7 +101,10 @@ def test_node_check(aggregator, dd_run_check, instance, mock_client):
aggregator.assert_service_check('aws.msk.{}'.format(c.SERVICE_CHECK_CONNECT), c.OK, tags=global_tags)

for node_info in client.list_nodes()['NodeInfoList']:
broker_info = node_info['BrokerNodeInfo']
broker_info = node_info.get('BrokerNodeInfo')
if broker_info is None:
continue

broker_tags = ['broker_id:{}'.format(broker_info['BrokerId'])]
broker_tags.extend(global_tags)

Expand Down Expand Up @@ -222,7 +227,9 @@ def test_custom_metric_path(aggregator, instance_legacy, mock_client):
aggregator.assert_service_check(c.SERVICE_CHECK_CONNECT, c.OK, tags=global_tags)

for node_info in client.list_nodes()['NodeInfoList']:
broker_info = node_info['BrokerNodeInfo']
broker_info = node_info.get('BrokerNodeInfo')
if broker_info is None:
continue
broker_tags = ['broker_id:{}'.format(broker_info['BrokerId'])]
broker_tags.extend(global_tags)

Expand Down

0 comments on commit 9870517

Please sign in to comment.