Skip to content

Commit

Permalink
Merge branch 'master' into vivek/AGENT-9736
Browse files Browse the repository at this point in the history
  • Loading branch information
vivek-datadog authored Jun 5, 2023
2 parents 50c2451 + 07e3746 commit 0cdf7d8
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 9 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions istio/metadata.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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,,
Expand Down
2 changes: 2 additions & 0 deletions network/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
(
Expand Down
16 changes: 16 additions & 0 deletions network/tests/tools/README.md
Original file line number Diff line number Diff line change
@@ -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',
```
87 changes: 87 additions & 0 deletions network/tests/tools/get_ethtool.py
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 6 additions & 0 deletions redisdb/tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
4 changes: 4 additions & 0 deletions redisdb/tests/test_replication.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
3 changes: 3 additions & 0 deletions redisdb/tests/test_slowlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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):
Expand Down
6 changes: 6 additions & 0 deletions redisdb/tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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())

0 comments on commit 0cdf7d8

Please sign in to comment.