def test_check(aggregator): gitlab_runner = GitlabRunnerCheck('gitlab_runner', CONFIG['init_config'], instances=CONFIG['instances']) gitlab_runner.check(CONFIG['instances'][0]) gitlab_runner.check(CONFIG['instances'][0]) assert_check(aggregator)
def test_connection_failure(aggregator): """ Make sure we're failing when the URL isn't right """ gitlab_runner = GitlabRunnerCheck('gitlab', BAD_CONFIG['init_config'], instances=BAD_CONFIG['instances']) with pytest.raises(ConnectionError): gitlab_runner.check(BAD_CONFIG['instances'][0]) # We should get two failed service checks aggregator.assert_service_check( GitlabRunnerCheck.MASTER_SERVICE_CHECK_NAME, status=GitlabRunnerCheck.CRITICAL, tags=['gitlab_host:{}'.format(HOST), 'gitlab_port:1234'] + CUSTOM_TAGS, count=1, ) aggregator.assert_service_check( GitlabRunnerCheck.PROMETHEUS_SERVICE_CHECK_NAME, status=GitlabRunnerCheck.CRITICAL, tags=CUSTOM_TAGS, count=1)
def test_check(aggregator): """ Basic Test for gitlab integration. """ gitlab_runner = GitlabRunnerCheck('gitlab_runner', CONFIG['init_config'], {}, instances=CONFIG['instances']) gitlab_runner.check(CONFIG['instances'][0]) aggregator.assert_service_check( GitlabRunnerCheck.MASTER_SERVICE_CHECK_NAME, status=GitlabRunnerCheck.OK, tags=GITLAB_RUNNER_TAGS + CUSTOM_TAGS, count=1, ) aggregator.assert_service_check( GitlabRunnerCheck.PROMETHEUS_SERVICE_CHECK_NAME, status=GitlabRunnerCheck.OK, tags=CUSTOM_TAGS, count=1) for metric in ALLOWED_METRICS: if metric.startswith('ci_runner'): aggregator.assert_metric("gitlab_runner.{}".format(metric)) else: aggregator.assert_metric("gitlab_runner.{}".format(metric), tags=CUSTOM_TAGS, count=1)
def test_connection_failure(aggregator): """ Make sure we're failing when the URL isn't right """ gitlab_runner = GitlabRunnerCheck('gitlab', BAD_CONFIG['init_config'], {}) try: gitlab_runner.check(BAD_CONFIG['instances'][0]) except Exception: pass else: assert False, "Gitlab Check should not be able to connect to this URL" # We should get two failed service checks aggregator.assert_service_check( GitlabRunnerCheck.MASTER_SERVICE_CHECK_NAME, status=GitlabRunnerCheck.CRITICAL, tags=['gitlab_host:{}'.format(HOST), 'gitlab_port:1234'] + CUSTOM_TAGS, count=1, ) aggregator.assert_service_check( GitlabRunnerCheck.PROMETHEUS_SERVICE_CHECK_NAME, status=GitlabRunnerCheck.CRITICAL, tags=CUSTOM_TAGS, count=1, )
def test_version_metadata(aggregator, datadog_agent): check_instance = GitlabRunnerCheck('gitlab_runner', CONFIG['init_config'], instances=CONFIG['instances']) check_instance.check_id = 'test:123' check_instance.check(CONFIG['instances'][0]) raw_version = GITLAB_RUNNER_VERSION major, minor, patch = raw_version.split('.') version_metadata = { 'version.scheme': 'semver', 'version.major': major, 'version.minor': minor, 'version.patch': patch, 'version.raw': raw_version, } datadog_agent.assert_metadata('test:123', version_metadata)
def test_check(aggregator, dd_run_check): instance = CONFIG['instances'][0] init_config = copy.deepcopy(CONFIG['init_config']) gitlab_runner = GitlabRunnerCheck('gitlab_runner', init_config, instances=[instance]) dd_run_check(gitlab_runner) dd_run_check(gitlab_runner) assert_check(aggregator) aggregator.assert_all_metrics_covered()
def test_timeout(test_case, timeout_config, expected_timeout): config = deepcopy(common.CONFIG) config['instances'][0].update(timeout_config) gitlab_runner = GitlabRunnerCheck('gitlab_runner', common.CONFIG['init_config'], instances=config['instances']) with mock.patch('datadog_checks.base.utils.http.requests') as r: r.get.return_value = mock.MagicMock(status_code=200) gitlab_runner.check(config['instances'][0]) r.get.assert_called_with( 'http://localhost:8085/ci', auth=mock.ANY, cert=mock.ANY, headers=mock.ANY, proxies=mock.ANY, timeout=expected_timeout, verify=mock.ANY, )