Beispiel #1
0
def test_connection_failure(aggregator, check):
    with pytest.raises(Exception):
        check.check(BAD_CONFIG)
    aggregator.assert_service_check('kong.can_connect', status=Kong.CRITICAL,
                                    tags=['kong_host:localhost', 'kong_port:1111'], count=1)

    aggregator.all_metrics_asserted()
Beispiel #2
0
def test_check(aggregator, check):
    for stub in CONFIG_STUBS:
        check.check(stub)
        expected_tags = stub['tags']

        for mname in GAUGES:
            aggregator.assert_metric(mname, tags=expected_tags, count=1)

        aggregator.assert_metric('kong.table.count', len(DATABASES), tags=expected_tags, count=1)

        for name in DATABASES:
            tags = expected_tags + ['table:{}'.format(name)]
            aggregator.assert_metric('kong.table.items', tags=tags, count=1)

        aggregator.assert_service_check('kong.can_connect', status=Kong.OK,
                                        tags=['kong_host:localhost', 'kong_port:8001'] + expected_tags, count=1)

        aggregator.all_metrics_asserted()
Beispiel #3
0
def test_tags(aggregator, spin_up_powerdns):
    version = _get_pdns_version()

    pdns_check = PowerDNSRecursorCheck(CHECK_NAME, {}, {})
    tags = ['foo:bar']
    if version == 3:
        config = common.CONFIG.copy()
        config['tags'] = ['foo:bar']
        pdns_check.check(config)

        # Assert metrics v3
        for metric in metrics.GAUGE_METRICS:
            aggregator.assert_metric(metrics.METRIC_FORMAT.format(metric),
                                     tags=tags,
                                     count=1)

        for metric in metrics.RATE_METRICS:
            aggregator.assert_metric(metrics.METRIC_FORMAT.format(metric),
                                     tags=tags,
                                     count=1)

    elif version == 4:
        config = common.CONFIG_V4.copy()
        config['tags'] = ['foo:bar']
        pdns_check.check(config)

        # Assert metrics v3
        for metric in metrics.GAUGE_METRICS + metrics.GAUGE_METRICS_V4:
            aggregator.assert_metric(metrics.METRIC_FORMAT.format(metric),
                                     tags=tags,
                                     count=1)

        for metric in metrics.RATE_METRICS + metrics.RATE_METRICS_V4:
            aggregator.assert_metric(metrics.METRIC_FORMAT.format(metric),
                                     tags=tags,
                                     count=1)

    service_check_tags = common._config_sc_tags(common.CONFIG)
    aggregator.assert_service_check('powerdns.recursor.can_connect',
                                    status=PowerDNSRecursorCheck.OK,
                                    tags=service_check_tags)

    aggregator.all_metrics_asserted()
Beispiel #4
0
def test_check(aggregator, spin_up_riak):
    riak_check = Riak(CHECK_NAME, {}, {})
    config = {"url": "{0}/stats".format(BASE_URL), "tags": ["my_tag"]}
    riak_check.check(config)
    riak_check.check(config)
    tags = ['my_tag']
    sc_tags = tags + ['url:' + config['url']]

    for gauge in CHECK_GAUGES + CHECK_GAUGES_STATS:
        aggregator.assert_metric(gauge, tags=tags, count=2)

    for sc in aggregator.service_checks(SERVICE_CHECK_NAME):
        assert sc.status == Riak.OK
        for tag in sc.tags:
            assert tag in sc_tags

    for gauge in GAUGE_OTHER:
        aggregator.assert_metric(gauge, count=1)

    aggregator.all_metrics_asserted()