From c08fd423affb8f7257d8fcb8e9a5afd869681415 Mon Sep 17 00:00:00 2001 From: Hristo Voyvodov <5427512+voyvodov@users.noreply.github.com> Date: Fri, 29 Nov 2024 15:21:34 +0200 Subject: [PATCH] Don't skip last index during iteration. (#18996) * Don't skip last index during iteration. Last empty element is removed on line 358 in `get_info` func * Update aerospike tests to include indixes metrics --- aerospike/changelog.d/18996.fixed | 1 + .../datadog_checks/aerospike/aerospike.py | 2 +- aerospike/tests/common.py | 52 +++++++++++++++++++ aerospike/tests/conftest.py | 2 + aerospike/tests/test_aerospike.py | 5 +- aerospike/tests/test_unit.py | 30 +++++++++++ 6 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 aerospike/changelog.d/18996.fixed diff --git a/aerospike/changelog.d/18996.fixed b/aerospike/changelog.d/18996.fixed new file mode 100644 index 0000000000000..f46ba036b3612 --- /dev/null +++ b/aerospike/changelog.d/18996.fixed @@ -0,0 +1 @@ +Don't skip last index in each namespace diff --git a/aerospike/datadog_checks/aerospike/aerospike.py b/aerospike/datadog_checks/aerospike/aerospike.py index f52814865f090..cec0c918ffdd8 100644 --- a/aerospike/datadog_checks/aerospike/aerospike.py +++ b/aerospike/datadog_checks/aerospike/aerospike.py @@ -152,7 +152,7 @@ def check(self, _): # https://www.aerospike.com/docs/reference/info/#sindex sindex = self.get_info('sindex/{}'.format(ns)) - for idx in parse_namespace(sindex[:-1], ns, 'indexname'): + for idx in parse_namespace(sindex, ns, 'indexname'): sindex_tags = ['sindex:{}'.format(idx)] sindex_tags.extend(namespace_tags) self.collect_info('sindex/{}/{}'.format(ns, idx), SINDEX_METRIC_TYPE, tags=sindex_tags) diff --git a/aerospike/tests/common.py b/aerospike/tests/common.py index c0dd957dbabda..a42f9db0b18cd 100644 --- a/aerospike/tests/common.py +++ b/aerospike/tests/common.py @@ -104,6 +104,32 @@ ALL_METRICS = NAMESPACE_METRICS + LEGACY_SET_METRICS +INDEXES_METRICS = [ + "aerospike.sindex.delete_error", + "aerospike.sindex.delete_success", + "aerospike.sindex.entries", + "aerospike.sindex.histogram", + "aerospike.sindex.ibtr_memory_used", + "aerospike.sindex.keys", + "aerospike.sindex.load_pct", + "aerospike.sindex.loadtime", + "aerospike.sindex.nbtr_memory_used", + "aerospike.sindex.query_agg", + "aerospike.sindex.query_agg_avg_rec_count", + "aerospike.sindex.query_agg_avg_record_size", + "aerospike.sindex.query_avg_rec_count", + "aerospike.sindex.query_avg_record_size", + "aerospike.sindex.query_lookup_avg_rec_count", + "aerospike.sindex.query_lookup_avg_record_size", + "aerospike.sindex.query_lookups", + "aerospike.sindex.query_reqs", + "aerospike.sindex.si_accounted_memory", + "aerospike.sindex.stat_gc_recs", + "aerospike.sindex.stat_gc_time", + "aerospike.sindex.write_error", + "aerospike.sindex.write_success", +] + STATS_METRICS = [ 'cluster_size', 'batch_index_initiate', @@ -155,6 +181,32 @@ 'tags': ['tag:value'], } +MOCK_INDEXES_METRICS = [ + "keys=1", + "entries=1", + "ibtr_memory_used=18688", + "nbtr_memory_used=31", + "si_accounted_memory=18719", + "load_pct=100", + "loadtime=7", + "write_success=1", + "write_error=0", + "delete_success=0", + "delete_error=0", + "stat_gc_recs=0", + "stat_gc_time=0", + "query_reqs=0", + "query_avg_rec_count=0", + "query_avg_record_size=0", + "query_agg=0", + "query_agg_avg_rec_count=0", + "query_agg_avg_record_size=0", + "query_lookups=0", + "query_lookup_avg_rec_count=0", + "query_lookup_avg_record_size=0", + "histogram=false", +] + MOCK_DATACENTER_METRICS = [ 'dc_state=CLUSTER_UP', 'dc_timelag=0', diff --git a/aerospike/tests/conftest.py b/aerospike/tests/conftest.py index 01e5448a97da3..0f3b9c170191a 100644 --- a/aerospike/tests/conftest.py +++ b/aerospike/tests/conftest.py @@ -39,6 +39,8 @@ def init_db(): 'quote_cnt': 47, } client.put(key, bins) + # Create at an index + client.index_string_create('test', 'characters', 'name', 'idx_characters_name') batch_keys = [] for i in range(10): diff --git a/aerospike/tests/test_aerospike.py b/aerospike/tests/test_aerospike.py index 4914b3396a577..66646789ad770 100644 --- a/aerospike/tests/test_aerospike.py +++ b/aerospike/tests/test_aerospike.py @@ -13,6 +13,7 @@ from .common import ( EXPECTED_PROMETHEUS_METRICS, EXPECTED_PROMETHEUS_METRICS_5_6, + INDEXES_METRICS, LATENCIES_METRICS, LAZY_METRICS, LEGACY_SET_METRICS, @@ -38,7 +39,6 @@ def test_check(aggregator, instance, dd_run_check): @pytest.mark.integration def test_version_metadata(aggregator, instance, datadog_agent, dd_run_check): - check = AerospikeCheck('aerospike', {}, [instance]) check.check_id = 'test:123' @@ -129,6 +129,9 @@ def _test_check(aggregator): for metric in LEGACY_SET_METRICS: aggregator.assert_metric("aerospike.set.{}".format(metric)) + for metric in INDEXES_METRICS: + aggregator.assert_metric(metric) + aggregator.assert_all_metrics_covered() aggregator.assert_service_check('aerospike.can_connect', AerospikeCheck.OK) diff --git a/aerospike/tests/test_unit.py b/aerospike/tests/test_unit.py index e7339566dc03f..681e9b8e0b0a1 100644 --- a/aerospike/tests/test_unit.py +++ b/aerospike/tests/test_unit.py @@ -52,6 +52,36 @@ def test_xdr_metrics(aggregator): aggregator.assert_metric(metric, tags=['datacenter:test']) +def test_sindex_metrics(aggregator, dd_run_check): + check = AerospikeCheck('aerospike', {}, [common.INSTANCE]) + original_get_info = check.get_info + + def mock_get_info(command, separator=";"): + if command == "sindex/test": + return [ + "ns=test:indexname=idx_characters_name:set=characters:bin=name:type=string:indextype=default:context=null:state=RW" + ] + elif command == "sindex/test/idx_characters_name": + return common.MOCK_INDEXES_METRICS + elif command.startswith("sets/"): + return [] + return original_get_info(command, separator) + + check.get_info = mock_get_info + check._tags = [] + check._client = mock.MagicMock() + check._client.get_node_names = mock.MagicMock( + return_value={'address': common.HOST, 'port': common.PORT, 'node_name': 'test'} + ) + check.get_namespaces = mock.MagicMock(return_value=['test']) + check.collect_throughput = mock.MagicMock() + check.collect_latency = mock.MagicMock() + dd_run_check(check) + + for metric in common.INDEXES_METRICS: + aggregator.assert_metric(metric, tags=['namespace:test', 'sindex:idx_characters_name']) + + def test_multiple_xdr_metrics(aggregator): check = AerospikeCheck('aerospike', {}, [common.INSTANCE]) check.get_info = mock.MagicMock(