Example #1
0
def test_service_check(bad_instance, aggregator):
    check = MesosMaster('mesos_master', {}, [bad_instance])

    with pytest.raises(CheckException):
        check.check(bad_instance)

    aggregator.assert_service_check('mesos_master.can_connect', count=1, status=AgentCheck.CRITICAL)
Example #2
0
def mock(init_config, instance):
    check = MesosMaster(common.CHECK_NAME, init_config, [instance])
    check._get_master_roles = lambda v, x: json.loads(
        read_fixture('roles.json'))
    check._get_master_stats = lambda v, x: json.loads(
        read_fixture('stats.json'))
    check._get_master_state = lambda v, x: json.loads(
        read_fixture('state.json'))
    return check
def check():
    check = MesosMaster(CHECK_NAME, {}, {})
    check._get_master_roles = lambda v, x, y, z: json.loads(
        read_fixture('roles.json'))
    check._get_master_stats = lambda v, x, y, z: json.loads(
        read_fixture('stats.json'))
    check._get_master_state = lambda v, x, y, z: json.loads(
        read_fixture('state.json'))

    return check
def test_metadata(instance, datadog_agent):
    check = MesosMaster('mesos_master', {}, [instance])
    check.check_id = 'test:123'

    check.check(instance)

    raw_version = MESOS_MASTER_VERSION.split('-')[0]
    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)
    datadog_agent.assert_metadata_count(len(version_metadata))
def test_can_connect_service_check(instance, aggregator, test_case_name,
                                   request_mock_side_effects, expected_status,
                                   expected_tags, expect_exception):
    check = MesosMaster('mesos_master', {}, [instance])

    with mock.patch('datadog_checks.base.utils.http.requests') as r:
        r.get.side_effect = request_mock_side_effects

        try:
            check._get_master_state('http://hello.com', ['my:tag'])
            exception_raised = False
        except CheckException:
            exception_raised = True

        assert expect_exception == exception_raised

    aggregator.assert_service_check('mesos_master.can_connect',
                                    count=1,
                                    status=expected_status,
                                    tags=expected_tags)
Example #6
0
def assert_metric_coverage(aggregator):
    check = MesosMaster(CHECK_NAME, {}, {})
    metrics = BASIC_METRICS
    for d in (
        check.ROLE_RESOURCES_METRICS,
        check.CLUSTER_TASKS_METRICS,
        check.CLUSTER_SLAVES_METRICS,
        check.CLUSTER_RESOURCES_METRICS,
        check.CLUSTER_FRAMEWORK_METRICS,
        check.STATS_METRICS,
    ):
        for _, m in iteritems(d):
            metrics.append(m[0])

    for m in metrics:
        aggregator.assert_metric(m)

    aggregator.assert_all_metrics_covered()

    aggregator.assert_service_check('mesos_master.can_connect', status=check.OK)
Example #7
0
def check():
    return MesosMaster(common.CHECK_NAME, {}, {})
def test_check_integration(instance, aggregator):
    check = MesosMaster('mesos_master', {}, [instance])
    check.check(instance)

    assert_metric_coverage(aggregator)