Skip to content

Commit

Permalink
Regression: handle missing index fields in payload (#19249)
Browse files Browse the repository at this point in the history
* Regression: handle missing index fields in payload

* add changelog
  • Loading branch information
iliakur authored Dec 11, 2024
1 parent bdf67e4 commit 76b7835
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions elastic/changelog.d/19249.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Regression fix: handle missing index fields in payload.
2 changes: 1 addition & 1 deletion elastic/datadog_checks/elastic/elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def _get_index_metrics(self, admin_forwarder, version, base_tags):
index_data['health_reverse'] = dd_health.reverse_status

# Ensure that index_data does not contain None values
for key, value in index_data.items():
for key, value in list(index_data.items()):
if value is None:
del index_data[key]
self.log.debug("The index %s has no metric data for %s", idx['index'], key)
Expand Down
32 changes: 31 additions & 1 deletion elastic/tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from datadog_checks.dev.http import MockResponse
from datadog_checks.elastic import ESCheck
from datadog_checks.elastic.elastic import AuthenticationError, get_value_from_path
from datadog_checks.elastic.metrics import stats_for_version
from datadog_checks.elastic.metrics import INDEX_STATS_METRICS, stats_for_version

from .common import URL, get_fixture_path

Expand Down Expand Up @@ -242,3 +242,33 @@ def test_v8_process_stats_data(aggregator, instance):
aggregator.assert_metric(
"elasticsearch.breakers.inflight_requests.estimated_size_in_bytes", metric_type=aggregator.GAUGE
)


def test__get_index_metrics_empty_key(aggregator, instance, mock_http_response):
mock_http_response(
json_data=[
{
# 'docs.count' is missing
'docs.deleted': '0',
'health': 'yellow',
'index': 'testindex',
'pri': '1',
'pri.store.size': '225',
'rep': '1',
'status': 'open',
'store.size': '225',
'uuid': 'AHSf1ILbSHucwl2X6og55g',
},
]
)
check = ESCheck('elastic', {}, instances=[instance])
# Focus only on index metrics, so mock out index search stats.
check._get_index_search_stats = mock.MagicMock()

check._get_index_metrics(admin_forwarder=False, version=[8, 8, 2], base_tags=[])

for m in INDEX_STATS_METRICS:
if m == 'elasticsearch.index.docs.count':
aggregator.assert_metric(m, count=0)
else:
aggregator.assert_metric(m)

0 comments on commit 76b7835

Please sign in to comment.