Skip to content

Commit b8d7eb1

Browse files
Add a check and retry for throughput metrics in tests (#22176)
* add a delay for latency metrics * change it to check for the output rather than wait * add conditional * small fix * comments and fine grain regex * Update aerospike/tests/conftest.py Co-authored-by: NouemanKHAL <[email protected]> --------- Co-authored-by: NouemanKHAL <[email protected]>
1 parent 60b28eb commit b8d7eb1

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

aerospike/tests/conftest.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# (C) Datadog, Inc. 2019-present
22
# All rights reserved
33
# Licensed under a 3-clause BSD style license (see LICENSE)
4+
import os
45
from copy import deepcopy
56

67
import pytest
78

89
from datadog_checks.base.utils.platform import Platform
9-
from datadog_checks.dev.conditions import WaitFor
10+
from datadog_checks.dev.conditions import CheckCommandOutput, WaitFor
1011
from datadog_checks.dev.docker import CheckDockerLogs, docker_run
1112

1213
from .common import COMPOSE_FILE, HOST, INSTANCE, OPENMETRICS_V2_INSTANCE, PORT
@@ -52,11 +53,36 @@ def init_db():
5253
client.close()
5354

5455

56+
def _get_conditions():
57+
conditions = [
58+
CheckDockerLogs(COMPOSE_FILE, ['service ready: soon there will be cake!']),
59+
WaitFor(init_db),
60+
]
61+
62+
# Wait for Aerospike to calculate latency/throughput metrics (only needed for versions <= 5.0)
63+
# We use the output of this docker exec command line for checking instead with the client,
64+
# because this is the command used to retrieve the metric and we know its output format.
65+
version = os.environ.get('AEROSPIKE_VERSION', '0.0')
66+
major, minor = map(int, version.split('.')[:2])
67+
68+
if (major, minor) <= (5, 0):
69+
conditions.append(
70+
CheckCommandOutput(
71+
['docker', 'exec', 'aerospike', 'asinfo', '-v', 'throughput:'],
72+
patterns=[r'\{test\}-(read|write)'],
73+
attempts=30,
74+
wait=1,
75+
)
76+
)
77+
78+
return conditions
79+
80+
5581
@pytest.fixture(scope='session')
5682
def dd_environment():
5783
with docker_run(
5884
COMPOSE_FILE,
59-
conditions=[CheckDockerLogs(COMPOSE_FILE, ['service ready: soon there will be cake!']), WaitFor(init_db)],
85+
conditions=_get_conditions(),
6086
attempts=2,
6187
):
6288
yield OPENMETRICS_V2_INSTANCE

0 commit comments

Comments
 (0)