Esempio n. 1
0
def test_check(aggregator):
    """
    Basic Test for gitlab integration.
    """

    gitlab = GitlabCheck('gitlab',
                         CONFIG['init_config'], {},
                         instances=CONFIG['instances'])

    gitlab.check(CONFIG['instances'][0])

    # Make sure we're receiving gitlab service checks
    for service_check in GitlabCheck.ALLOWED_SERVICE_CHECKS:
        aggregator.assert_service_check('gitlab.{}'.format(service_check),
                                        status=GitlabCheck.OK,
                                        tags=GITLAB_TAGS + CUSTOM_TAGS,
                                        count=1)

    # Make sure we're receiving prometheus service checks
    aggregator.assert_service_check(GitlabCheck.PROMETHEUS_SERVICE_CHECK_NAME,
                                    status=GitlabCheck.OK,
                                    tags=CUSTOM_TAGS,
                                    count=1)

    for metric in ALLOWED_METRICS:
        aggregator.assert_metric("gitlab.{}".format(metric),
                                 tags=CUSTOM_TAGS,
                                 count=1)
Esempio n. 2
0
def test_run(benchmark):
    instance = CONFIG['instances'][0]
    c = GitlabCheck('gitlab', CONFIG['init_config'], {})

    # Run once to get any initialization out of the way.
    c.check(instance)

    benchmark(c.check, instance)
Esempio n. 3
0
def test_check_integration(aggregator, mock_data):
    instance = CONFIG['instances'][0]
    init_config = CONFIG['init_config']

    gitlab = GitlabCheck('gitlab', init_config, instances=[instance])
    gitlab.check(instance)
    gitlab.check(instance)

    assert_check(aggregator, METRICS)
Esempio n. 4
0
def test_legacy_run(benchmark):
    instance = LEGACY_CONFIG['instances'][0]
    c = GitlabCheck('gitlab',
                    LEGACY_CONFIG['init_config'],
                    instances=LEGACY_CONFIG['instances'])

    # Run once to get any initialization out of the way.
    c.check(instance)

    benchmark(c.check, instance)
Esempio n. 5
0
def test_check_submit_metadata(aggregator, datadog_agent, raw_version, version_metadata, count):
    with mock.patch('datadog_checks.base.utils.http.requests.Response.json') as g:
        # mock the api call so that it returns the given version
        g.return_value = {"version": raw_version}

        datadog_agent.reset()

        instance = AUTH_CONFIG['instances'][0]
        init_config = AUTH_CONFIG['init_config']

        gitlab = GitlabCheck('gitlab', init_config, instances=[instance])
        gitlab.check_id = 'test:123'

        gitlab.check(instance)
        datadog_agent.assert_metadata('test:123', version_metadata)
        datadog_agent.assert_metadata_count(count)
def test_connection_failure(aggregator):
    """
    Make sure we're failing when the URL isn't right
    """

    gitlab = GitlabCheck('gitlab', BAD_CONFIG['init_config'], instances=BAD_CONFIG['instances'])

    with pytest.raises(ConnectionError):
        gitlab.check(BAD_CONFIG['instances'][0])

    # We should get only one failed service check, the first
    aggregator.assert_service_check(
        'gitlab.{}'.format(GitlabCheck.ALLOWED_SERVICE_CHECKS[0]),
        status=GitlabCheck.CRITICAL,
        tags=['gitlab_host:{}'.format(HOST), 'gitlab_port:1234'] + CUSTOM_TAGS,
        count=1,
    )
Esempio n. 7
0
def test_connection_failure(aggregator):
    """
    Make sure we're failing when the URL isn't right
    """

    gitlab = GitlabCheck('gitlab', BAD_CONFIG['init_config'], {})

    try:
        gitlab.check(BAD_CONFIG['instances'][0])
    except Exception:
        pass
    else:
        assert False, "Gitlab should not be able to connect to this URL"

    # We should get only one failed service check, the first
    aggregator.assert_service_check(
        'gitlab.{}'.format(GitlabCheck.ALLOWED_SERVICE_CHECKS[0]),
        status=GitlabCheck.CRITICAL,
        tags=['gitlab_host:{}'.format(HOST), 'gitlab_port:1234'] + CUSTOM_TAGS,
        count=1,
    )