def test_basic_case_integration(aggregator): instance = copy.deepcopy(INSTANCE_WITH_PLUGIN) check = Fluentd(CHECK_NAME, {}, [instance]) check.check(instance) check.check(instance) assert_basic_case(aggregator)
def test_instance_timeout(instance): # test instance timeout instance['timeout'] = 15 check = Fluentd(CHECK_NAME, {}, [instance]) check.check(instance) assert check.http.options['timeout'] == (15, 15)
def test_instance_old_timeout(instance): # test instance default_timeout instance['default_timeout'] = 13 check = Fluentd(CHECK_NAME, {'default_timeout': 9}, [instance]) check.check(instance) assert check.http.options['timeout'] == (13, 13)
def test_collect_metadata_invalid_binary(datadog_agent, instance): instance['fluentd'] = '/bin/does_not_exist' check = Fluentd(CHECK_NAME, {}, [instance]) check.check_id = CHECK_ID check.check(instance) datadog_agent.assert_metadata(CHECK_ID, {}) datadog_agent.assert_metadata_count(0)
def test_collect_metadata_missing_version(aggregator, datadog_agent, dd_run_check, instance): instance["fluentd"] = "python {} 'fluentd not.a.version'".format(VERSION_MOCK_SCRIPT) check = Fluentd(CHECK_NAME, {}, [instance]) check.check_id = CHECK_ID dd_run_check(check) datadog_agent.assert_metadata(CHECK_ID, {}) datadog_agent.assert_metadata_count(0)
def test_fluentd_exception(aggregator): instance = {"monitor_agent_url": BAD_URL, "plugin_ids": ["plg2"], "tags": ["test"]} check = Fluentd(CHECK_NAME, {}, [instance]) with pytest.raises(Exception): check.check(instance) sc_tags = ['fluentd_host:{}'.format(HOST), 'fluentd_port:{}'.format(BAD_PORT), 'test'] aggregator.assert_service_check(check.SERVICE_CHECK_NAME, status=Fluentd.CRITICAL, tags=sc_tags, count=1) aggregator.assert_all_metrics_covered()
def test_fluentd_with_tag_by_plugin_id(aggregator): instance = copy.deepcopy(DEFAULT_INSTANCE) instance["tag_by"] = "plugin_id" check = Fluentd(CHECK_NAME, {}, [instance]) check.check(instance) for m in EXPECTED_GAUGES: metric_name = '{0}.{1}'.format(CHECK_NAME, m) aggregator.assert_metric(metric_name, tags=['plugin_id:plg1']) aggregator.assert_metric(metric_name, tags=['plugin_id:plg2']) sc_tags = ['fluentd_host:{}'.format(HOST), 'fluentd_port:24220'] aggregator.assert_service_check(check.SERVICE_CHECK_NAME, status=Fluentd.OK, tags=sc_tags, count=1) aggregator.assert_all_metrics_covered()
def test_fluentd_with_tag_by_type(aggregator): instance = copy.deepcopy(DEFAULT_INSTANCE) instance["tag_by"] = "type" check = Fluentd(CHECK_NAME, {}, [instance]) check.check(None) for m in _get_metrics_by_version(): metric_name = '{0}.{1}'.format(CHECK_NAME, m) aggregator.assert_metric(metric_name) aggregator.assert_metric_has_tag_prefix(metric_name, 'type') sc_tags = ['fluentd_host:{}'.format(HOST), 'fluentd_port:24220'] aggregator.assert_service_check(check.SERVICE_CHECK_NAME, status=Fluentd.OK, tags=sc_tags, count=1) aggregator.assert_all_metrics_covered()
def test_fluentd_with_custom_tags(aggregator): instance = copy.deepcopy(DEFAULT_INSTANCE) custom_tags = ['test', 'tast:tast'] instance["tags"] = custom_tags check = Fluentd(CHECK_NAME, {}, [instance]) check.check(None) for m in _get_metrics_by_version(): metric_name = '{0}.{1}'.format(CHECK_NAME, m) aggregator.assert_metric(metric_name, tags=['plugin_id:plg1'] + custom_tags) aggregator.assert_metric(metric_name, tags=['plugin_id:plg2'] + custom_tags) sc_tags = ['fluentd_host:{}'.format(HOST), 'fluentd_port:24220'] + custom_tags aggregator.assert_service_check(check.SERVICE_CHECK_NAME, status=Fluentd.OK, tags=sc_tags, count=1) aggregator.assert_all_metrics_covered()
def test_collect_metadata_invalid_binary_with_endpoint(datadog_agent, instance): instance['fluentd'] = '/bin/does_not_exist' check = Fluentd(CHECK_NAME, {}, [instance]) check.check_id = CHECK_ID check.check(None) major, minor, patch = FLUENTD_VERSION.split('.') version_metadata = { 'version.raw': FLUENTD_VERSION, 'version.scheme': 'semver', 'version.major': major, 'version.minor': minor, 'version.patch': patch, } datadog_agent.assert_metadata(CHECK_ID, version_metadata) datadog_agent.assert_metadata_count(5)
def test_collect_metadata_instance(aggregator, datadog_agent, instance, dd_run_check): instance['fluentd'] = 'docker exec {} fluentd'.format(FLUENTD_CONTAINER_NAME) check = Fluentd(CHECK_NAME, {}, [instance]) check.check_id = CHECK_ID dd_run_check(check) major, minor, patch = FLUENTD_VERSION.split('.') version_metadata = { 'version.raw': FLUENTD_VERSION, 'version.scheme': 'semver', 'version.major': major, 'version.minor': minor, 'version.patch': patch, } datadog_agent.assert_metadata(CHECK_ID, version_metadata) datadog_agent.assert_metadata_count(5)
def check(): return Fluentd(CHECK_NAME, {}, {})
def test_default_timeout(instance): # test default timeout check = Fluentd(CHECK_NAME, {}, [instance]) check.check(instance) assert check.http.options['timeout'] == (5, 5)
def test_init_config_timeout(instance): # test init_config timeout check = Fluentd(CHECK_NAME, {'timeout': 7}, [instance]) check.check(instance) assert check.http.options['timeout'] == (7, 7)
def test_init_config_old_timeout(instance): # test init_config timeout check = Fluentd(CHECK_NAME, {'default_timeout': 2}, [instance]) check.check(instance) assert check.http.options['timeout'] == (2, 2)
def check(): return Fluentd(CHECK_NAME, {}, [DEFAULT_INSTANCE])