Skip to content

Commit

Permalink
Don't skip last index during iteration. (DataDog#18996)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
voyvodov authored Nov 29, 2024
1 parent 8feef77 commit c08fd42
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 2 deletions.
1 change: 1 addition & 0 deletions aerospike/changelog.d/18996.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Don't skip last index in each namespace
2 changes: 1 addition & 1 deletion aerospike/datadog_checks/aerospike/aerospike.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
52 changes: 52 additions & 0 deletions aerospike/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions aerospike/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 4 additions & 1 deletion aerospike/tests/test_aerospike.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from .common import (
EXPECTED_PROMETHEUS_METRICS,
EXPECTED_PROMETHEUS_METRICS_5_6,
INDEXES_METRICS,
LATENCIES_METRICS,
LAZY_METRICS,
LEGACY_SET_METRICS,
Expand All @@ -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'

Expand Down Expand Up @@ -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)
Expand Down
30 changes: 30 additions & 0 deletions aerospike/tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit c08fd42

Please sign in to comment.