Skip to content

Commit 0cdf7d8

Browse files
Merge branch 'master' into vivek/AGENT-9736
2 parents 50c2451 + 07e3746 commit 0cdf7d8

12 files changed

Lines changed: 135 additions & 9 deletions

File tree

.github/workflows/pr.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ name: PR
22

33
on:
44
pull_request:
5-
branches:
6-
- master
75
paths-ignore:
86
- datadog_checks_base/datadog_checks/**
97
- datadog_checks_dev/datadog_checks/dev/*.py

datadog_checks_base/tests/base/checks/openmetrics/test_legacy/test_openmetrics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2678,7 +2678,7 @@ def test_ssl_verify_not_raise_warning(caplog, mocked_openmetrics_check_factory,
26782678
check = mocked_openmetrics_check_factory(instance)
26792679
scraper_config = check.get_scraper_config(instance)
26802680

2681-
with caplog.at_level(logging.DEBUG):
2681+
with caplog.at_level(logging.DEBUG), mock.patch('requests.get', return_value=MockResponse('httpbin.org')):
26822682
resp = check.send_request('https://httpbin.org/get', scraper_config)
26832683

26842684
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
27032703
# `prometheus_url` changed just before calling `send_request`
27042704
scraper_config['prometheus_url'] = 'https://www.example.com/foo/bar'
27052705

2706-
with caplog.at_level(logging.DEBUG):
2706+
with caplog.at_level(logging.DEBUG), mock.patch('requests.get', return_value=MockResponse('httpbin.org')):
27072707
resp = check.send_request('https://httpbin.org/get', scraper_config)
27082708

27092709
assert "httpbin.org" in resp.content.decode('utf-8')

datadog_checks_base/tests/base/checks/prometheus/test_prometheus.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,9 +1964,11 @@ def test_text_filter_input():
19641964

19651965

19661966
def test_ssl_verify_not_raise_warning(caplog, mocked_prometheus_check, text_data):
1967+
from datadog_checks.dev.http import MockResponse
1968+
19671969
check = mocked_prometheus_check
19681970

1969-
with caplog.at_level(logging.DEBUG):
1971+
with caplog.at_level(logging.DEBUG), mock.patch('requests.get', return_value=MockResponse('httpbin.org')):
19701972
resp = check.poll('https://httpbin.org/get')
19711973

19721974
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
19771979

19781980

19791981
def test_ssl_verify_not_raise_warning_cert_false(caplog, mocked_prometheus_check, text_data):
1982+
from datadog_checks.dev.http import MockResponse
1983+
19801984
check = mocked_prometheus_check
19811985
check.ssl_ca_cert = False
19821986

1983-
with caplog.at_level(logging.DEBUG):
1987+
with caplog.at_level(logging.DEBUG), mock.patch('requests.get', return_value=MockResponse('httpbin.org')):
19841988
resp = check.poll('https://httpbin.org/get')
19851989

19861990
assert 'httpbin.org' in resp.content.decode('utf-8')

datadog_checks_dev/datadog_checks/dev/tooling/commands/meta/snmp/generate_profile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def _compile_mib_to_json(mib, source_mib_directories, destination_directory, sou
298298
AnyFileBorrower(borrower_reader, genTexts=True).setOptions(exts=['.json'])
299299
for borrower_reader in getReadersFromUrls(*[compiled_mibs_path], **{'lowcaseMatching': False})
300300
]
301-
mib_compiler.addBorrowers(borrowers)
301+
mib_compiler.addBorrowers(*borrowers)
302302

303303
processed = mib_compiler.compile(
304304
mib,

istio/metadata.csv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ istio.mesh.request.count,count,,request,,"[OpenMetrics V1 and V2] The number of
33
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,
44
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,
55
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,
6-
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,
6+
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,
77
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,
8-
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,
8+
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,
99
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,
1010
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,,
1111
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,,

network/tests/common.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373
'system.net.conntrack.timestamp',
7474
]
7575

76+
77+
# See the `tools/get_ethtool.py` script to update this mock if needed
7678
ETHTOOL_IOCTL_INPUTS_OUTPUTS = {
7779
# these are for the case where ENA values are present
7880
(

network/tests/tools/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
The `get_ethtool.py` script is used to dump ethtool driver info and metrics as hexadecimal dump.
2+
Used to generate test for network integration (see https://github.com/DataDog/integrations-core/blob/master/network/tests/common.py#L76C1-L157)
3+
4+
```
5+
python get_ethtool.py 'eth0'
6+
7+
("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'):
8+
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',
9+
10+
("eth0", b'7\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'):
11+
b'7\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\n\x00\x00\x00',
12+
("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'):
13+
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',
14+
("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'):
15+
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',
16+
```

network/tests/tools/get_ethtool.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# (C) Datadog, Inc. 2023-present
2+
# All rights reserved
3+
# Licensed under a 3-clause BSD style license (see LICENSE)
4+
5+
import array
6+
import fcntl
7+
import socket
8+
import struct
9+
import sys
10+
11+
SIOCETHTOOL = 0x8946
12+
ETHTOOL_GSTRINGS = 0x0000001B
13+
ETHTOOL_GSSET_INFO = 0x00000037
14+
ETHTOOL_GSTATS = 0x0000001D
15+
ETHTOOL_GDRVINFO = 0x00000003
16+
ETH_SS_STATS = 0x1
17+
ETH_GSTRING_LEN = 32
18+
19+
20+
def _send_ethtool_ioctl(iface, sckt, data):
21+
"""
22+
Send an ioctl SIOCETHTOOL call for given interface with given data.
23+
"""
24+
print('("{}", {}):'.format(iface, data.tobytes()))
25+
ifr = struct.pack('16sP', iface.encode('utf-8'), data.buffer_info()[0])
26+
fcntl.ioctl(sckt.fileno(), SIOCETHTOOL, ifr)
27+
print('{},'.format(data.tobytes()))
28+
29+
30+
def _get_ethtool_gstringset(iface, sckt):
31+
"""
32+
Retrieve names of all ethtool stats for given interface.
33+
"""
34+
sset_info = array.array('B', struct.pack('IIQI', ETHTOOL_GSSET_INFO, 0, 1 << ETH_SS_STATS, 0))
35+
_send_ethtool_ioctl(iface, sckt, sset_info)
36+
sset_mask, sset_len = struct.unpack('8xQI', sset_info)
37+
if sset_mask == 0:
38+
sset_len = 0
39+
strings = array.array('B', struct.pack('III', ETHTOOL_GSTRINGS, ETH_SS_STATS, sset_len))
40+
strings.extend([0] * sset_len * ETH_GSTRING_LEN)
41+
_send_ethtool_ioctl(iface, sckt, strings)
42+
43+
all_names = []
44+
for i in range(sset_len):
45+
offset = 12 + ETH_GSTRING_LEN * i
46+
name = strings[offset : offset + ETH_GSTRING_LEN]
47+
name = name.tobytes()
48+
name = name.partition(b'\x00')[0].decode('utf-8')
49+
all_names.append(name)
50+
return all_names
51+
52+
53+
def get_ethtool_drvinfo(iface, sckt):
54+
drvinfo = array.array('B', struct.pack('I', ETHTOOL_GDRVINFO))
55+
drvinfo.extend([0] * (4 + 32 + 32 + 32 + 32 + 32 + 12 + 5 * 4))
56+
_send_ethtool_ioctl(iface, sckt, drvinfo)
57+
driver_version = drvinfo[4 + 32 : 32 + 32]
58+
driver_version = driver_version.tobytes()
59+
driver_version = driver_version.partition(b'\x00')[0].decode('utf-8')
60+
driver_name = drvinfo[4 : 4 + 32]
61+
driver_name = driver_name.tobytes()
62+
driver_name = driver_name.partition(b'\x00')[0].decode('utf-8')
63+
64+
65+
def get_metric(iface, sckt):
66+
"""
67+
Get all ENA metrics specified in ENA_METRICS_NAMES list and their values from ethtool.
68+
"""
69+
stats_names = list(_get_ethtool_gstringset(iface, sckt))
70+
stats_count = len(stats_names)
71+
72+
stats = array.array('B', struct.pack('II', ETHTOOL_GSTATS, stats_count))
73+
# we need `stats_count * (length of uint64)` for the result
74+
stats.extend([0] * len(struct.pack('Q', 0)) * stats_count)
75+
_send_ethtool_ioctl(iface, sckt, stats)
76+
77+
78+
if len(sys.argv) != 1:
79+
print('Provide a single network interface name as parameter (eth0, ens5...)')
80+
sys.exit(1)
81+
82+
83+
iface = sys.argv[1]
84+
ethtool_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0)
85+
get_ethtool_drvinfo(iface, ethtool_socket)
86+
print()
87+
get_metric(iface, ethtool_socket)

redisdb/tests/test_default.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import redis
1111
from packaging.version import Version
1212

13+
from datadog_checks.dev.utils import get_metadata_metrics
1314
from datadog_checks.redisdb import Redis
1415

1516
from .common import HOST, PASSWORD, PORT, REDIS_VERSION
@@ -56,6 +57,7 @@ def test_aof_loading_metrics(aggregator, redis_instance):
5657
aggregator.assert_metric('redis.aof.loading_loaded_perc', 44)
5758
aggregator.assert_metric('redis.aof.loading_eta_seconds', 45)
5859
aggregator.assert_all_metrics_covered()
60+
aggregator.assert_metrics_using_metadata(get_metadata_metrics(), check_submission_type=True)
5961

6062

6163
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
104106
assert 'redis.net.instantaneous_ops_per_sec' in aggregator.metric_names
105107
db.flushdb()
106108

109+
aggregator.assert_metrics_using_metadata(get_metadata_metrics(), check_submission_type=True)
110+
107111

108112
def test_service_check(aggregator, dd_run_check, check, redis_auth, redis_instance):
109113
redis_check = check(redis_instance)
@@ -221,6 +225,7 @@ def test__check_key_lengths_single_db(aggregator, redis_instance):
221225

222226
# that single metric should have value=2
223227
aggregator.assert_metric('redis.key.length', value=2)
228+
aggregator.assert_metrics_using_metadata(get_metadata_metrics(), check_submission_type=True)
224229

225230

226231
def test__check_key_lengths_multi_db(aggregator, redis_instance):
@@ -255,3 +260,4 @@ def test__check_key_lengths_multi_db(aggregator, redis_instance):
255260
aggregator.assert_metric('redis.key.length', value=2, tags=['key:test_foo', 'key_type:list', 'redis_db:db3'])
256261
aggregator.assert_metric('redis.key.length', value=1, tags=['key:test_bar', 'key_type:list', 'redis_db:db0'])
257262
aggregator.assert_metric('redis.key.length', value=0, tags=['key:missing_key'])
263+
aggregator.assert_metrics_using_metadata(get_metadata_metrics(), check_submission_type=True)

redisdb/tests/test_replication.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pytest
77
import redis
88

9+
from datadog_checks.dev.utils import get_metadata_metrics
910
from datadog_checks.redisdb import Redis
1011

1112
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
3334
metrics = aggregator.metrics(metric_name)
3435
assert len(metrics) == 1
3536
assert metrics[0].value != 0
37+
aggregator.assert_metrics_using_metadata(get_metadata_metrics(), check_submission_type=True)
3638

3739

3840
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):
6668

6769
for name in REPLICA_METRICS:
6870
aggregator.assert_metric(name)
71+
72+
aggregator.assert_metrics_using_metadata(get_metadata_metrics(), check_submission_type=True)

0 commit comments

Comments
 (0)