From d048d4ee28cfe91d121ebcbdaf562a3163e40c9d Mon Sep 17 00:00:00 2001 From: Florent Clarret Date: Mon, 5 Jun 2023 14:58:46 +0200 Subject: [PATCH 1/6] Assert metrics using metadata in some tests (#14652) --- redisdb/tests/test_default.py | 6 ++++++ redisdb/tests/test_replication.py | 4 ++++ redisdb/tests/test_slowlog.py | 3 +++ redisdb/tests/test_unit.py | 6 ++++++ 4 files changed, 19 insertions(+) diff --git a/redisdb/tests/test_default.py b/redisdb/tests/test_default.py index 1e5ce1461d4c4..d2a23536e39ab 100644 --- a/redisdb/tests/test_default.py +++ b/redisdb/tests/test_default.py @@ -10,6 +10,7 @@ import redis from packaging.version import Version +from datadog_checks.dev.utils import get_metadata_metrics from datadog_checks.redisdb import Redis from .common import HOST, PASSWORD, PORT, REDIS_VERSION @@ -56,6 +57,7 @@ def test_aof_loading_metrics(aggregator, redis_instance): aggregator.assert_metric('redis.aof.loading_loaded_perc', 44) aggregator.assert_metric('redis.aof.loading_eta_seconds', 45) aggregator.assert_all_metrics_covered() + aggregator.assert_metrics_using_metadata(get_metadata_metrics(), check_submission_type=True) def test_redis_default(aggregator, dd_run_check, check, redis_auth, redis_instance): @@ -104,6 +106,8 @@ def test_redis_default(aggregator, dd_run_check, check, redis_auth, redis_instan assert 'redis.net.instantaneous_ops_per_sec' in aggregator.metric_names db.flushdb() + aggregator.assert_metrics_using_metadata(get_metadata_metrics(), check_submission_type=True) + def test_service_check(aggregator, dd_run_check, check, redis_auth, redis_instance): redis_check = check(redis_instance) @@ -221,6 +225,7 @@ def test__check_key_lengths_single_db(aggregator, redis_instance): # that single metric should have value=2 aggregator.assert_metric('redis.key.length', value=2) + aggregator.assert_metrics_using_metadata(get_metadata_metrics(), check_submission_type=True) def test__check_key_lengths_multi_db(aggregator, redis_instance): @@ -255,3 +260,4 @@ def test__check_key_lengths_multi_db(aggregator, redis_instance): aggregator.assert_metric('redis.key.length', value=2, tags=['key:test_foo', 'key_type:list', 'redis_db:db3']) aggregator.assert_metric('redis.key.length', value=1, tags=['key:test_bar', 'key_type:list', 'redis_db:db0']) aggregator.assert_metric('redis.key.length', value=0, tags=['key:missing_key']) + aggregator.assert_metrics_using_metadata(get_metadata_metrics(), check_submission_type=True) diff --git a/redisdb/tests/test_replication.py b/redisdb/tests/test_replication.py index 91330ba9d44e9..63df76b02596a 100644 --- a/redisdb/tests/test_replication.py +++ b/redisdb/tests/test_replication.py @@ -6,6 +6,7 @@ import pytest import redis +from datadog_checks.dev.utils import get_metadata_metrics from datadog_checks.redisdb import Redis from .common import HOST, MASTER_PORT, REPLICA_PORT, UNHEALTHY_REPLICA_PORT @@ -33,6 +34,7 @@ def test_redis_replication_link_metric(aggregator, replica_instance, dd_run_chec metrics = aggregator.metrics(metric_name) assert len(metrics) == 1 assert metrics[0].value != 0 + aggregator.assert_metrics_using_metadata(get_metadata_metrics(), check_submission_type=True) def test_redis_replication_service_check(aggregator, replica_instance, dd_run_check, check): @@ -66,3 +68,5 @@ def test_redis_repl(aggregator, dd_run_check, check, master_instance): for name in REPLICA_METRICS: aggregator.assert_metric(name) + + aggregator.assert_metrics_using_metadata(get_metadata_metrics(), check_submission_type=True) diff --git a/redisdb/tests/test_slowlog.py b/redisdb/tests/test_slowlog.py index a0d08d97b9d15..985c41220d55f 100644 --- a/redisdb/tests/test_slowlog.py +++ b/redisdb/tests/test_slowlog.py @@ -8,6 +8,8 @@ import pytest import redis +from datadog_checks.dev.utils import get_metadata_metrics + from .common import HOST, PASSWORD, PORT TEST_KEY = "testkey" @@ -34,6 +36,7 @@ def test_slowlog(aggregator, dd_run_check, check, redis_instance): expected_tags = ['foo:bar', 'redis_host:{}'.format(HOST), 'redis_port:6379', 'command:LPUSH'] aggregator.assert_metric('redis.slowlog.micros', tags=expected_tags) + aggregator.assert_metrics_using_metadata(get_metadata_metrics(), check_submission_type=True) def test_custom_slowlog(aggregator, dd_run_check, check, redis_instance): diff --git a/redisdb/tests/test_unit.py b/redisdb/tests/test_unit.py index 79fd4d659a825..1a85e3d8b96e2 100644 --- a/redisdb/tests/test_unit.py +++ b/redisdb/tests/test_unit.py @@ -2,8 +2,13 @@ # All rights reserved # Licensed under a 3-clause BSD style license (see LICENSE) import mock +import pytest from six import iteritems +from datadog_checks.dev.utils import get_metadata_metrics + +pytestmark = pytest.mark.unit + def test_init(check, redis_instance): check = check(redis_instance) @@ -57,3 +62,4 @@ def test__check_command_stats_host(check, aggregator, redis_instance): expected_tags = ['foo:bar', 'command:lpush'] aggregator.assert_metric('redis.command.calls', value=4, count=1, tags=expected_tags) aggregator.assert_metric('redis.command.usec_per_call', value=14.00, count=1, tags=expected_tags) + aggregator.assert_metrics_using_metadata(get_metadata_metrics()) From fb7fd34f45742e66983516613a49dd66671e2820 Mon Sep 17 00:00:00 2001 From: NouhaManai Date: Mon, 5 Jun 2023 15:03:22 +0200 Subject: [PATCH 2/6] fix generate-profile (#14676) --- .../dev/tooling/commands/meta/snmp/generate_profile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datadog_checks_dev/datadog_checks/dev/tooling/commands/meta/snmp/generate_profile.py b/datadog_checks_dev/datadog_checks/dev/tooling/commands/meta/snmp/generate_profile.py index 64d46b49d785b..2ff772fce8910 100644 --- a/datadog_checks_dev/datadog_checks/dev/tooling/commands/meta/snmp/generate_profile.py +++ b/datadog_checks_dev/datadog_checks/dev/tooling/commands/meta/snmp/generate_profile.py @@ -298,7 +298,7 @@ def _compile_mib_to_json(mib, source_mib_directories, destination_directory, sou AnyFileBorrower(borrower_reader, genTexts=True).setOptions(exts=['.json']) for borrower_reader in getReadersFromUrls(*[compiled_mibs_path], **{'lowcaseMatching': False}) ] - mib_compiler.addBorrowers(borrowers) + mib_compiler.addBorrowers(*borrowers) processed = mib_compiler.compile( mib, From a236851e745c2b19f2adab0a6e9dc0f83f63ddd8 Mon Sep 17 00:00:00 2001 From: Florent Clarret Date: Mon, 5 Jun 2023 15:05:37 +0200 Subject: [PATCH 3/6] Add a script to update the ethtool ioctl mock values (#14651) * Add a script to update the ethtool ioctl mock values * license headers * license headers --- network/tests/common.py | 2 + network/tests/tools/README.md | 16 ++++++ network/tests/tools/get_ethtool.py | 87 ++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 network/tests/tools/README.md create mode 100644 network/tests/tools/get_ethtool.py diff --git a/network/tests/common.py b/network/tests/common.py index e9b59f1b1640d..745651f380e9c 100644 --- a/network/tests/common.py +++ b/network/tests/common.py @@ -73,6 +73,8 @@ 'system.net.conntrack.timestamp', ] + +# See the `tools/get_ethtool.py` script to update this mock if needed ETHTOOL_IOCTL_INPUTS_OUTPUTS = { # these are for the case where ENA values are present ( diff --git a/network/tests/tools/README.md b/network/tests/tools/README.md new file mode 100644 index 0000000000000..9e58cb9b036a4 --- /dev/null +++ b/network/tests/tools/README.md @@ -0,0 +1,16 @@ +The `get_ethtool.py` script is used to dump ethtool driver info and metrics as hexadecimal dump. +Used to generate test for network integration (see https://github.com/DataDog/integrations-core/blob/master/network/tests/common.py#L76C1-L157) + +``` +python get_ethtool.py 'eth0' + +("eth0", b'\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'): +b'\x03\x00\x00\x00veth\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x001.0\x00.0-1034-aws\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\n\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', + +("eth0", b'7\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'): +b'7\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\n\x00\x00\x00', +("eth0", b'\x1b\x00\x00\x00\x01\x00\x00\x00\n\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'): +b'\x1b\x00\x00\x00\x01\x00\x00\x00\n\x00\x00\x00peer_ifindex\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00rx_queue_0_xdp_packets\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00rx_queue_0_xdp_bytes\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00rx_queue_0_drops\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00rx_queue_0_xdp_redirect\x00\x00\x00\x00\x00\x00\x00\x00\x00rx_queue_0_xdp_drops\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00rx_queue_0_xdp_tx\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00rx_queue_0_xdp_tx_errors\x00\x00\x00\x00\x00\x00\x00\x00tx_queue_0_xdp_xmit\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00tx_queue_0_xdp_xmit_errors\x00\x00\x00\x00\x00\x00', +("eth0", b'\x1d\x00\x00\x00\n\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'): +b'\x1d\x00\x00\x00\n\x00\x00\x00\xe5\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', +``` \ No newline at end of file diff --git a/network/tests/tools/get_ethtool.py b/network/tests/tools/get_ethtool.py new file mode 100644 index 0000000000000..fdba0f0f0a8d3 --- /dev/null +++ b/network/tests/tools/get_ethtool.py @@ -0,0 +1,87 @@ +# (C) Datadog, Inc. 2023-present +# All rights reserved +# Licensed under a 3-clause BSD style license (see LICENSE) + +import array +import fcntl +import socket +import struct +import sys + +SIOCETHTOOL = 0x8946 +ETHTOOL_GSTRINGS = 0x0000001B +ETHTOOL_GSSET_INFO = 0x00000037 +ETHTOOL_GSTATS = 0x0000001D +ETHTOOL_GDRVINFO = 0x00000003 +ETH_SS_STATS = 0x1 +ETH_GSTRING_LEN = 32 + + +def _send_ethtool_ioctl(iface, sckt, data): + """ + Send an ioctl SIOCETHTOOL call for given interface with given data. + """ + print('("{}", {}):'.format(iface, data.tobytes())) + ifr = struct.pack('16sP', iface.encode('utf-8'), data.buffer_info()[0]) + fcntl.ioctl(sckt.fileno(), SIOCETHTOOL, ifr) + print('{},'.format(data.tobytes())) + + +def _get_ethtool_gstringset(iface, sckt): + """ + Retrieve names of all ethtool stats for given interface. + """ + sset_info = array.array('B', struct.pack('IIQI', ETHTOOL_GSSET_INFO, 0, 1 << ETH_SS_STATS, 0)) + _send_ethtool_ioctl(iface, sckt, sset_info) + sset_mask, sset_len = struct.unpack('8xQI', sset_info) + if sset_mask == 0: + sset_len = 0 + strings = array.array('B', struct.pack('III', ETHTOOL_GSTRINGS, ETH_SS_STATS, sset_len)) + strings.extend([0] * sset_len * ETH_GSTRING_LEN) + _send_ethtool_ioctl(iface, sckt, strings) + + all_names = [] + for i in range(sset_len): + offset = 12 + ETH_GSTRING_LEN * i + name = strings[offset : offset + ETH_GSTRING_LEN] + name = name.tobytes() + name = name.partition(b'\x00')[0].decode('utf-8') + all_names.append(name) + return all_names + + +def get_ethtool_drvinfo(iface, sckt): + drvinfo = array.array('B', struct.pack('I', ETHTOOL_GDRVINFO)) + drvinfo.extend([0] * (4 + 32 + 32 + 32 + 32 + 32 + 12 + 5 * 4)) + _send_ethtool_ioctl(iface, sckt, drvinfo) + driver_version = drvinfo[4 + 32 : 32 + 32] + driver_version = driver_version.tobytes() + driver_version = driver_version.partition(b'\x00')[0].decode('utf-8') + driver_name = drvinfo[4 : 4 + 32] + driver_name = driver_name.tobytes() + driver_name = driver_name.partition(b'\x00')[0].decode('utf-8') + + +def get_metric(iface, sckt): + """ + Get all ENA metrics specified in ENA_METRICS_NAMES list and their values from ethtool. + """ + stats_names = list(_get_ethtool_gstringset(iface, sckt)) + stats_count = len(stats_names) + + stats = array.array('B', struct.pack('II', ETHTOOL_GSTATS, stats_count)) + # we need `stats_count * (length of uint64)` for the result + stats.extend([0] * len(struct.pack('Q', 0)) * stats_count) + _send_ethtool_ioctl(iface, sckt, stats) + + +if len(sys.argv) != 1: + print('Provide a single network interface name as parameter (eth0, ens5...)') + sys.exit(1) + + +iface = sys.argv[1] +ethtool_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0) +get_ethtool_drvinfo(iface, ethtool_socket) +print() +get_metric(iface, ethtool_socket) From 4b59df8b2866d4e58b392fba9345ae6f9efdad60 Mon Sep 17 00:00:00 2001 From: Florent Clarret Date: Mon, 5 Jun 2023 15:15:18 +0200 Subject: [PATCH 4/6] Run CI tests on PRs that do not target master (#14631) --- .github/workflows/pr.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index ad65340d90d80..1cb884e04b2ca 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -2,8 +2,6 @@ name: PR on: pull_request: - branches: - - master paths-ignore: - datadog_checks_base/datadog_checks/** - datadog_checks_dev/datadog_checks/dev/*.py From 949e2626d0a61027058c05d482f1465118a2194e Mon Sep 17 00:00:00 2001 From: Florent Clarret Date: Mon, 5 Jun 2023 15:16:58 +0200 Subject: [PATCH 5/6] Update some unit names (#14666) --- istio/metadata.csv | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/istio/metadata.csv b/istio/metadata.csv index 61b57966b3794..82d1972bec065 100644 --- a/istio/metadata.csv +++ b/istio/metadata.csv @@ -3,9 +3,9 @@ istio.mesh.request.count,count,,request,,"[OpenMetrics V1 and V2] The number of istio.mesh.request.duration.count,count,,request,,"[OpenMetrics V1 and V2] Count of request durations. This metric is as gauge by default in OpenMetrics V1.",0,istio,request durations count, istio.mesh.request.duration.sum,count,,millisecond,,"[OpenMetrics V1 and V2] Sum of request durations. This metric is sent as gauge by default in OpenMetrics V1.",0,istio,request durations sum, istio.mesh.request.size.count,count,,request,,[OpenMetrics V1 and V2] Count of request sizes. This metric is sent as gauge by default in OpenMetrics V1.,0,istio,request sizes count, -istio.mesh.request.size.sum,count,,request,,"[OpenMetrics V1 and V2] Sum of request sizes. This metric is sent as gauge by default in OpenMetrics V1.",0,istio,request sizes sum, +istio.mesh.request.size.sum,count,,byte,,"[OpenMetrics V1 and V2] Sum of request sizes. This metric is sent as gauge by default in OpenMetrics V1.",0,istio,request sizes sum, istio.mesh.response.size.count,count,,response,,"[OpenMetrics V1 and V2] Count of response sizes. This metric is sent as gauge by default in OpenMetrics V1.",0,istio,response sizes count, -istio.mesh.response.size.sum,count,,response,,"[OpenMetrics V1 and V2] Sum of response sizes. This metric is sent as gauge by default in OpenMetrics V1.",0,istio,response sizes sum, +istio.mesh.response.size.sum,count,,byte,,"[OpenMetrics V1 and V2] Sum of response sizes. This metric is sent as gauge by default in OpenMetrics V1.",0,istio,response sizes sum, istio.mixer.adapter.dispatch_count,gauge,,operation,,"[OpenMetrics V1 and V2] Total number of adapter dispatches handled by Mixer",0,istio,number of adapter dispatches, istio.mixer.adapter.dispatch_duration.count,count,,operation,,"[OpenMetrics V1 and V2] Count of durations for adapter dispatches handled by Mixer. This metric is sent as gauge by default in OpenMetrics V1.",0,istio,, istio.mixer.adapter.dispatch_duration.sum,count,,operation,,"[OpenMetrics V1 and V2] Sum of durations for adapter dispatches handled by Mixer. This metric is sent as gauge by default in OpenMetrics V1.",0,istio,, From 07e37469637fb42fc0a8e8c35e6f63b188c4d137 Mon Sep 17 00:00:00 2001 From: Alex Lopez Date: Mon, 5 Jun 2023 15:33:41 +0200 Subject: [PATCH 6/6] Mock out httpbin.org responses to fix flaky tests (#14630) --- .../checks/openmetrics/test_legacy/test_openmetrics.py | 4 ++-- .../tests/base/checks/prometheus/test_prometheus.py | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/datadog_checks_base/tests/base/checks/openmetrics/test_legacy/test_openmetrics.py b/datadog_checks_base/tests/base/checks/openmetrics/test_legacy/test_openmetrics.py index 16d02d7e5e2cc..51b20a1339124 100644 --- a/datadog_checks_base/tests/base/checks/openmetrics/test_legacy/test_openmetrics.py +++ b/datadog_checks_base/tests/base/checks/openmetrics/test_legacy/test_openmetrics.py @@ -2678,7 +2678,7 @@ def test_ssl_verify_not_raise_warning(caplog, mocked_openmetrics_check_factory, check = mocked_openmetrics_check_factory(instance) scraper_config = check.get_scraper_config(instance) - with caplog.at_level(logging.DEBUG): + with caplog.at_level(logging.DEBUG), mock.patch('requests.get', return_value=MockResponse('httpbin.org')): resp = check.send_request('https://httpbin.org/get', scraper_config) assert "httpbin.org" in resp.content.decode('utf-8') @@ -2703,7 +2703,7 @@ def test_send_request_with_dynamic_prometheus_url(caplog, mocked_openmetrics_che # `prometheus_url` changed just before calling `send_request` scraper_config['prometheus_url'] = 'https://www.example.com/foo/bar' - with caplog.at_level(logging.DEBUG): + with caplog.at_level(logging.DEBUG), mock.patch('requests.get', return_value=MockResponse('httpbin.org')): resp = check.send_request('https://httpbin.org/get', scraper_config) assert "httpbin.org" in resp.content.decode('utf-8') diff --git a/datadog_checks_base/tests/base/checks/prometheus/test_prometheus.py b/datadog_checks_base/tests/base/checks/prometheus/test_prometheus.py index a27950bb0643b..5634e0e27cf0a 100644 --- a/datadog_checks_base/tests/base/checks/prometheus/test_prometheus.py +++ b/datadog_checks_base/tests/base/checks/prometheus/test_prometheus.py @@ -1964,9 +1964,11 @@ def test_text_filter_input(): def test_ssl_verify_not_raise_warning(caplog, mocked_prometheus_check, text_data): + from datadog_checks.dev.http import MockResponse + check = mocked_prometheus_check - with caplog.at_level(logging.DEBUG): + with caplog.at_level(logging.DEBUG), mock.patch('requests.get', return_value=MockResponse('httpbin.org')): resp = check.poll('https://httpbin.org/get') assert 'httpbin.org' in resp.content.decode('utf-8') @@ -1977,10 +1979,12 @@ def test_ssl_verify_not_raise_warning(caplog, mocked_prometheus_check, text_data def test_ssl_verify_not_raise_warning_cert_false(caplog, mocked_prometheus_check, text_data): + from datadog_checks.dev.http import MockResponse + check = mocked_prometheus_check check.ssl_ca_cert = False - with caplog.at_level(logging.DEBUG): + with caplog.at_level(logging.DEBUG), mock.patch('requests.get', return_value=MockResponse('httpbin.org')): resp = check.poll('https://httpbin.org/get') assert 'httpbin.org' in resp.content.decode('utf-8')