Skip to content

Commit c08fd42

Browse files
authored
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
1 parent 8feef77 commit c08fd42

File tree

6 files changed

+90
-2
lines changed

6 files changed

+90
-2
lines changed

aerospike/changelog.d/18996.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Don't skip last index in each namespace

aerospike/datadog_checks/aerospike/aerospike.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def check(self, _):
152152

153153
# https://www.aerospike.com/docs/reference/info/#sindex
154154
sindex = self.get_info('sindex/{}'.format(ns))
155-
for idx in parse_namespace(sindex[:-1], ns, 'indexname'):
155+
for idx in parse_namespace(sindex, ns, 'indexname'):
156156
sindex_tags = ['sindex:{}'.format(idx)]
157157
sindex_tags.extend(namespace_tags)
158158
self.collect_info('sindex/{}/{}'.format(ns, idx), SINDEX_METRIC_TYPE, tags=sindex_tags)

aerospike/tests/common.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,32 @@
104104

105105
ALL_METRICS = NAMESPACE_METRICS + LEGACY_SET_METRICS
106106

107+
INDEXES_METRICS = [
108+
"aerospike.sindex.delete_error",
109+
"aerospike.sindex.delete_success",
110+
"aerospike.sindex.entries",
111+
"aerospike.sindex.histogram",
112+
"aerospike.sindex.ibtr_memory_used",
113+
"aerospike.sindex.keys",
114+
"aerospike.sindex.load_pct",
115+
"aerospike.sindex.loadtime",
116+
"aerospike.sindex.nbtr_memory_used",
117+
"aerospike.sindex.query_agg",
118+
"aerospike.sindex.query_agg_avg_rec_count",
119+
"aerospike.sindex.query_agg_avg_record_size",
120+
"aerospike.sindex.query_avg_rec_count",
121+
"aerospike.sindex.query_avg_record_size",
122+
"aerospike.sindex.query_lookup_avg_rec_count",
123+
"aerospike.sindex.query_lookup_avg_record_size",
124+
"aerospike.sindex.query_lookups",
125+
"aerospike.sindex.query_reqs",
126+
"aerospike.sindex.si_accounted_memory",
127+
"aerospike.sindex.stat_gc_recs",
128+
"aerospike.sindex.stat_gc_time",
129+
"aerospike.sindex.write_error",
130+
"aerospike.sindex.write_success",
131+
]
132+
107133
STATS_METRICS = [
108134
'cluster_size',
109135
'batch_index_initiate',
@@ -155,6 +181,32 @@
155181
'tags': ['tag:value'],
156182
}
157183

184+
MOCK_INDEXES_METRICS = [
185+
"keys=1",
186+
"entries=1",
187+
"ibtr_memory_used=18688",
188+
"nbtr_memory_used=31",
189+
"si_accounted_memory=18719",
190+
"load_pct=100",
191+
"loadtime=7",
192+
"write_success=1",
193+
"write_error=0",
194+
"delete_success=0",
195+
"delete_error=0",
196+
"stat_gc_recs=0",
197+
"stat_gc_time=0",
198+
"query_reqs=0",
199+
"query_avg_rec_count=0",
200+
"query_avg_record_size=0",
201+
"query_agg=0",
202+
"query_agg_avg_rec_count=0",
203+
"query_agg_avg_record_size=0",
204+
"query_lookups=0",
205+
"query_lookup_avg_rec_count=0",
206+
"query_lookup_avg_record_size=0",
207+
"histogram=false",
208+
]
209+
158210
MOCK_DATACENTER_METRICS = [
159211
'dc_state=CLUSTER_UP',
160212
'dc_timelag=0',

aerospike/tests/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ def init_db():
3939
'quote_cnt': 47,
4040
}
4141
client.put(key, bins)
42+
# Create at an index
43+
client.index_string_create('test', 'characters', 'name', 'idx_characters_name')
4244

4345
batch_keys = []
4446
for i in range(10):

aerospike/tests/test_aerospike.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from .common import (
1414
EXPECTED_PROMETHEUS_METRICS,
1515
EXPECTED_PROMETHEUS_METRICS_5_6,
16+
INDEXES_METRICS,
1617
LATENCIES_METRICS,
1718
LAZY_METRICS,
1819
LEGACY_SET_METRICS,
@@ -38,7 +39,6 @@ def test_check(aggregator, instance, dd_run_check):
3839

3940
@pytest.mark.integration
4041
def test_version_metadata(aggregator, instance, datadog_agent, dd_run_check):
41-
4242
check = AerospikeCheck('aerospike', {}, [instance])
4343
check.check_id = 'test:123'
4444

@@ -129,6 +129,9 @@ def _test_check(aggregator):
129129
for metric in LEGACY_SET_METRICS:
130130
aggregator.assert_metric("aerospike.set.{}".format(metric))
131131

132+
for metric in INDEXES_METRICS:
133+
aggregator.assert_metric(metric)
134+
132135
aggregator.assert_all_metrics_covered()
133136

134137
aggregator.assert_service_check('aerospike.can_connect', AerospikeCheck.OK)

aerospike/tests/test_unit.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,36 @@ def test_xdr_metrics(aggregator):
5252
aggregator.assert_metric(metric, tags=['datacenter:test'])
5353

5454

55+
def test_sindex_metrics(aggregator, dd_run_check):
56+
check = AerospikeCheck('aerospike', {}, [common.INSTANCE])
57+
original_get_info = check.get_info
58+
59+
def mock_get_info(command, separator=";"):
60+
if command == "sindex/test":
61+
return [
62+
"ns=test:indexname=idx_characters_name:set=characters:bin=name:type=string:indextype=default:context=null:state=RW"
63+
]
64+
elif command == "sindex/test/idx_characters_name":
65+
return common.MOCK_INDEXES_METRICS
66+
elif command.startswith("sets/"):
67+
return []
68+
return original_get_info(command, separator)
69+
70+
check.get_info = mock_get_info
71+
check._tags = []
72+
check._client = mock.MagicMock()
73+
check._client.get_node_names = mock.MagicMock(
74+
return_value={'address': common.HOST, 'port': common.PORT, 'node_name': 'test'}
75+
)
76+
check.get_namespaces = mock.MagicMock(return_value=['test'])
77+
check.collect_throughput = mock.MagicMock()
78+
check.collect_latency = mock.MagicMock()
79+
dd_run_check(check)
80+
81+
for metric in common.INDEXES_METRICS:
82+
aggregator.assert_metric(metric, tags=['namespace:test', 'sindex:idx_characters_name'])
83+
84+
5585
def test_multiple_xdr_metrics(aggregator):
5686
check = AerospikeCheck('aerospike', {}, [common.INSTANCE])
5787
check.get_info = mock.MagicMock(

0 commit comments

Comments
 (0)