def test_gunicorn_instance(aggregator, setup_gunicorn): instance = INSTANCE.copy() instance['gunicorn'] = setup_gunicorn['gunicorn_bin_path'] check = GUnicornCheck(CHECK_NAME, {}, [instance]) check.check(instance) _assert_metrics(aggregator)
def test_collect_metadata_docker(aggregator, datadog_agent, setup_gunicorn): instance = INSTANCE.copy() instance['gunicorn'] = 'docker exec {} gunicorn'.format(CONTAINER_NAME) check = GUnicornCheck(CHECK_NAME, {}, [instance]) check.check_id = CHECK_ID check.check(instance) _assert_metadata(datadog_agent)
def test_collect_metadata_count(aggregator, datadog_agent, setup_gunicorn): instance = INSTANCE.copy() instance['gunicorn'] = setup_gunicorn['gunicorn_bin_path'] check = GUnicornCheck(CHECK_NAME, {}, [instance]) check.check_id = 'test:123' check.check(instance) datadog_agent.assert_metadata_count(5)
def test_collect_metadata_init_config(aggregator, datadog_agent, setup_gunicorn): init_config = {'gunicorn': setup_gunicorn['gunicorn_bin_path']} check = GUnicornCheck(CHECK_NAME, init_config, [INSTANCE]) check.check_id = CHECK_ID check.check(INSTANCE) _assert_metadata(datadog_agent)
def test_collect_metadata_instance(aggregator, datadog_agent, setup_gunicorn): instance = INSTANCE.copy() instance['gunicorn'] = setup_gunicorn['gunicorn_bin_path'] check = GUnicornCheck(CHECK_NAME, {}, [instance]) check.check_id = CHECK_ID check.check(instance) _assert_metadata(datadog_agent)
def test_collect_metadata_parsing_matching(aggregator, datadog_agent, stdout, stderr, expect_metadata_count): """ Test all metadata collection code paths """ check = GUnicornCheck(CHECK_NAME, {}, [INSTANCE]) check.check_id = 'test:123' with mock.patch('datadog_checks.gunicorn.gunicorn.get_subprocess_output', return_value=(stdout, stderr, 0)): check.check(INSTANCE) datadog_agent.assert_metadata_count(expect_metadata_count)
def test_gunicorn(aggregator, setup_gunicorn): check = GUnicornCheck(CHECK_NAME, {}, {}) check.check(INSTANCE) aggregator.assert_metric("gunicorn.workers", tags=['app:dd-test-gunicorn', 'state:idle'], value=4, count=1) aggregator.assert_metric("gunicorn.workers", tags=['app:dd-test-gunicorn', 'state:working'], value=0, count=1) aggregator.assert_service_check("gunicorn.is_running", count=1) aggregator.assert_all_metrics_covered()
def test_collect_metadata_invalid_binary(aggregator, datadog_agent, setup_gunicorn): instance = INSTANCE.copy() instance['gunicorn'] = '/bin/not_exist' check = GUnicornCheck(CHECK_NAME, {}, [instance]) check.check_id = CHECK_ID check.check(instance) datadog_agent.assert_metadata_count(0)
def test_no_master_proc(aggregator, setup_gunicorn): instance = {'proc_name': 'no_master_proc'} check = GUnicornCheck(CHECK_NAME, {}, [instance]) check.check(instance) aggregator.assert_service_check("gunicorn.is_running", check.CRITICAL)
def test_gunicorn(aggregator, setup_gunicorn): check = GUnicornCheck(CHECK_NAME, {}, {}) check.check(INSTANCE) _assert_metrics(aggregator)