def test_bad_status(aggregator): instance = { 'status_url': 'http://foo:9001/status', 'tags': ['expectedbroken'] } check = PHPFPMCheck('php_fpm', {}, [instance]) check.check(instance) assert len(aggregator.metric_names) == 0
def test_bad_ping(aggregator): instance = {'ping_url': 'http://foo:9001/ping', 'tags': ['some_tag']} check = PHPFPMCheck('php_fpm', {}, [instance]) check.check(instance) aggregator.assert_service_check( 'php_fpm.can_ping', status=check.CRITICAL, tags=['ping_url:http://foo:9001/ping', 'some_tag'] ) aggregator.all_metrics_asserted()
def test_config(test_case, extra_config, expected_http_kwargs): instance = {'ping_url': 'http://foo:9001/ping'} instance.update(extra_config) check = PHPFPMCheck('php_fpm', {}, instances=[instance]) with mock.patch('datadog_checks.base.utils.http.requests') as r: r.get.return_value = mock.MagicMock(status_code=200) check.check(instance) http_kwargs = dict( auth=mock.ANY, cert=mock.ANY, headers=mock.ANY, proxies=mock.ANY, timeout=mock.ANY, verify=mock.ANY ) http_kwargs.update(expected_http_kwargs) r.get.assert_called_with('http://foo:9001/ping', **http_kwargs)
def test_bad_ping_reply(instance, aggregator, ping_url_tag, dd_run_check): instance['status_url'] = None instance['ping_reply'] = 'foo' instance['tags'] = ['expectedbroken'] expected_tags = [ping_url_tag, 'expectedbroken'] check = PHPFPMCheck('php_fpm', {}, instances=[instance]) dd_run_check(check) aggregator.assert_service_check('php_fpm.can_ping', status=check.CRITICAL, tags=expected_tags) aggregator.all_metrics_asserted()
def test_status(instance, aggregator, ping_url_tag, dd_run_check): instance['tags'] = ['fpm_cluster:forums'] check = PHPFPMCheck('php_fpm', {}, instances=[instance]) dd_run_check(check) metrics = [ 'php_fpm.listen_queue.size', 'php_fpm.processes.idle', 'php_fpm.processes.active', 'php_fpm.processes.total', 'php_fpm.requests.slow', 'php_fpm.requests.accepted', 'php_fpm.processes.max_reached', ] expected_tags = ['fpm_cluster:forums', 'pool:www'] for metric in metrics: aggregator.assert_metric(metric, tags=expected_tags) expected_tags = [ping_url_tag, 'fpm_cluster:forums'] aggregator.assert_service_check('php_fpm.can_ping', status=check.OK, tags=expected_tags)