|
1 | 1 | # (C) Datadog, Inc. 2019-present |
2 | 2 | # All rights reserved |
3 | 3 | # Licensed under a 3-clause BSD style license (see LICENSE) |
| 4 | +import os |
4 | 5 | from copy import deepcopy |
5 | 6 |
|
6 | 7 | import pytest |
7 | 8 |
|
8 | 9 | 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 |
10 | 11 | from datadog_checks.dev.docker import CheckDockerLogs, docker_run |
11 | 12 |
|
12 | 13 | from .common import COMPOSE_FILE, HOST, INSTANCE, OPENMETRICS_V2_INSTANCE, PORT |
@@ -52,11 +53,36 @@ def init_db(): |
52 | 53 | client.close() |
53 | 54 |
|
54 | 55 |
|
| 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 | + |
55 | 81 | @pytest.fixture(scope='session') |
56 | 82 | def dd_environment(): |
57 | 83 | with docker_run( |
58 | 84 | COMPOSE_FILE, |
59 | | - conditions=[CheckDockerLogs(COMPOSE_FILE, ['service ready: soon there will be cake!']), WaitFor(init_db)], |
| 85 | + conditions=_get_conditions(), |
60 | 86 | attempts=2, |
61 | 87 | ): |
62 | 88 | yield OPENMETRICS_V2_INSTANCE |
|
0 commit comments