Skip to content

Commit

Permalink
add skip for distribution event (#19052)
Browse files Browse the repository at this point in the history
* add skip for distribution event

* Rename 19051.added to 19052.added

* tests

* lint
  • Loading branch information
steveny91 authored Nov 28, 2024
1 parent 3e1f734 commit f3e57bd
Show file tree
Hide file tree
Showing 5 changed files with 259 additions and 0 deletions.
1 change: 1 addition & 0 deletions couch/changelog.d/19052.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for Couch version 3.4.0
3 changes: 3 additions & 0 deletions couch/datadog_checks/couch/couch.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ def _build_system_metrics(self, data, tags, prefix='couchdb.erlang'):
dist_tags = list(tags)
dist_tags.append("node:{0}".format(node))
self._build_system_metrics(metrics, dist_tags, "{0}.{1}".format(prefix, key))
elif key == "distribution_events":
self.agent_check.log.debug("Skipping distribution events")
continue
elif isinstance(value, dict):
self._build_system_metrics(value, tags, "{0}.{1}".format(prefix, key))
else:
Expand Down
9 changes: 9 additions & 0 deletions couch/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ def active_tasks():
return json.loads(f.read())


@pytest.fixture
def load_test_data():
"""
Returns a raw response from `/_3.4_system.json`
"""
with open(os.path.join(common.HERE, 'fixtures', '_3.4_system.json')) as f:
return json.load(f)


@pytest.fixture(scope="session")
def dd_environment():
"""
Expand Down
223 changes: 223 additions & 0 deletions couch/tests/fixtures/_3.4_system.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
{
"uptime": 87,
"memory": {
"other": 19225722,
"atom": 553593,
"atom_used": 526962,
"processes": 12616384,
"processes_used": 12607040,
"binary": 558120,
"code": 12149997,
"ets": 1847536
},
"run_queue": 0,
"ets_table_count": 124,
"context_switches": 83763,
"reductions": 29838712,
"garbage_collection_count": 25531,
"words_reclaimed": 27456219,
"io_input": 11354834,
"io_output": 2849837,
"os_proc_count": 0,
"stale_proc_count": 0,
"process_count": 470,
"process_limit": 262144,
"message_queues": {
"couch_file": {
"count": 34,
"min": 0,
"max": 0,
"50": 0,
"90": 0,
"99": 0
},
"couch_db_updater": {
"count": 22,
"min": 0,
"max": 0,
"50": 0,
"90": 0,
"99": 0
},
"httpc_manager": 0,
"httpc_handler_sup": 0,
"ken_sup": 0,
"ken_server": 0,
"couch_replication": 0,
"chttpd_auth_cache_lru": 0,
"couch_index_sup": 0,
"ioq_sup": 0,
"couch_index_server": 0,
"mem3_events": 0,
"jwtf_sup": 0,
"[email protected]": 0,
"jwtf_keystore": 0,
"[email protected]": 0,
"ioq": 0,
"couch_uuids": 0,
"ftp_sup": 0,
"rexi_buffer_mon": 0,
"ibrowse_sup": 0,
"couch_secondary_services": 0,
"rexi_buffer_sup": 0,
"couch_primary_services": 0,
"couch_task_status": 0,
"couch_sup": 0,
"global_changes_sup": 0,
"global_changes_server": 0,
"couch_server": 0,
"ibrowse": 0,
"config_event": 0,
"chttpd_sup": 0,
"couch_proc_manager": 0,
"release_handler": 0,
"sasl_sup": 0,
"dreyfus_sup": 0,
"standard_error_sup": 0,
"couch_event_sup2": 0,
"alarm_handler": 0,
"couch_event_server": 0,
"couch_epi_functions_gen_couch_index": 0,
"dreyfus_index_manager": 0,
"couch_epi_functions_gen_chttpd_auth": 0,
"timer_server": 0,
"couch_epi_functions_gen_couch_db": 0,
"runtime_tools_sup": 0,
"couch_epi_data_gen_flags_config": 0,
"couch_httpd_vhost": 0,
"couch_epi_functions_gen_global_changes": 0,
"couch_epi_functions_gen_chttpd_handlers": 0,
"chttpd_auth_cache": 0,
"couch_epi_functions_gen_feature_flags": 0,
"couch_stats_sup": 0,
"couch_epi_functions_gen_chttpd": 0,
"couch_plugin": 0,
"couch_stats_process_tracker": 0,
"chttpd": 0,
"kernel_safe_sup": 0,
"tftp_sup": 0,
"couch_stats_aggregator": 0,
"[email protected]": 0,
"rex": 0,
"[email protected]": 0,
"net_sup": 0,
"folsom_sup": 0,
"inet_gethost_native_sup": 0,
"kernel_sup": 0,
"ddoc_cache_sup": 0,
"global_name_server": 0,
"ddoc_cache_opener": 0,
"folsom_sample_slide_sup": 0,
"ddoc_cache_lru": 0,
"file_server_2": 0,
"standard_error": 0,
"couch_drv": 0,
"couch_peruser_sup": 0,
"tls_connection_sup": 0,
"couch_peruser": 0,
"folsom_metrics_histogram_ets": 0,
"couch_replicator_sup": 0,
"ssl_sup": 0,
"couch_replicator_scheduler_sup": 0,
"smoosh_sup": 0,
"folsom_meter_timer_server": 0,
"smoosh_server": 0,
"couch_replicator_scheduler": 0,
"[email protected]": 0,
"[email protected]": 0,
"mem3_sync_nodes": 0,
"couch_replicator_rate_limiter": 0,
"inet_gethost_native": 0,
"inets_sup": 0,
"setup_sup": 0,
"inet_db": 0,
"ssl_pem_cache": 0,
"mem3_sync": 0,
"ssl_manager": 0,
"mem3_sup": 0,
"ssl_listen_tracker_sup": 0,
"mem3_shards": 0,
"mem3_seeds": 0,
"httpd_sup": 0,
"couch_log_sup": 0,
"mem3_reshard_sup": 0,
"mango_sup": 0,
"couch_log_server": 0,
"couch_epi_data_gen_dreyfus_black_list": 0,
"mem3_reshard_job_sup": 0,
"erts_code_purger": 0,
"global_group": 0,
"error_logger": 0,
"couch_replicator_doc_processor": 0,
"ssl_connection_sup": 0,
"init": 0,
"mem3_reshard_dbdoc": 0,
"couch_replicator_connection": 0,
"erl_signal_server": 0,
"net_kernel": 0,
"couch_replicator_clustering": 0,
"sasl_safe_sup": 0,
"config": 0,
"mem3_reshard": 0,
"user": 0,
"couch_epi_sup": 0,
"erl_epmd": 0,
"mem3_nodes": 0,
"ssl_admin_sup": 0,
"mochiweb_clock": 0,
"dtls_udp_sup": 0,
"erl_prim_loader": 0,
"code_server": 0,
"httpc_sup": 0,
"rexi_sup": 0,
"dtls_connection_sup": 0,
"rexi_server_sup": 0,
"rexi_server_mon": 0,
"auth": 0,
"application_controller": 0,
"httpc_profile_sup": 0,
"config_sup": 0,
"rexi_server": 0
},
"internal_replication_jobs": 0,
"distribution": {
"[email protected]": {
"recv_oct": 546816,
"recv_cnt": 1865,
"recv_max": 20295,
"recv_avg": 293,
"recv_dvi": 11,
"send_oct": 326373,
"send_cnt": 2989,
"send_max": 1257,
"send_avg": 109,
"send_pend": 0
},
"[email protected]": {
"recv_oct": 495964,
"recv_cnt": 1663,
"recv_max": 20295,
"recv_avg": 298,
"recv_dvi": 20,
"send_oct": 322019,
"send_cnt": 2934,
"send_max": 2514,
"send_avg": 109,
"send_pend": 0
}
},
"distribution_events": {
"[email protected]": [
[
"2024-11-13T19:57:04Z",
"nodeup"
]
],
"[email protected]": [
[
"2024-11-13T19:57:04Z",
"nodeup"
]
]
}
}
23 changes: 23 additions & 0 deletions couch/tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
from copy import deepcopy
from unittest.mock import MagicMock

import mock
import pytest

from datadog_checks.couch import CouchDb
from datadog_checks.couch.couch import CouchDB2

from . import common

Expand Down Expand Up @@ -45,3 +47,24 @@ def test_config(test_case, extra_config, expected_http_kwargs):
http_wargs.update(expected_http_kwargs)

r.get.assert_called_with('http://{}:5984/_all_dbs/'.format(common.HOST), **http_wargs)


def test_new_version_system_metrics(load_test_data):
# Testing the _build_system_metrics method I'm feeding it a json that has a the updated
# keys that was added in version 3.4 that was causing the check to break. The idea here
# is that I'm going to give the method the json then assert that it's able to go through
# it thhorougly by the number of function calls and debug log calls.

# Mock everything needed for the function to run
mock_agent_check = MagicMock()
mock_agent_check.gauge = MagicMock()
mock_agent_check.log = MagicMock()

couchdb_check = CouchDB2(mock_agent_check)
tags = ["test:tag"]

# The fixture file json is loaded as a fixture in the confest.py file
couchdb_check._build_system_metrics(load_test_data, tags)

assert mock_agent_check.gauge.call_count >= 183
mock_agent_check.log.debug.assert_any_call("Skipping distribution events")

0 comments on commit f3e57bd

Please sign in to comment.