Ejemplo n.º 1
0
def test_check_namespaced_metrics():
    out = []

    def fake_process_metric(message, **kwargs):
        out.append((message, kwargs))

    check = Neo4jCheck('neo4j', {}, {})
    check.process_metric = fake_process_metric

    config = Config(host='localhost',
                    port=9000,
                    neo4j_version='4.0',
                    neo4j_dbs=[],
                    exclude_labels=['kube_service'],
                    instance_tags=['key:value'])

    check._check_metrics([
        FakeMetric("neo4j_dbms_some_global_metric"),
        FakeMetric("neo4j_database_mydb_some_local_metric"),
    ],
                         config=config)

    assert out == [
        (FakeMetric("some_global_metric"), {
            'custom_tags': ['db_name:global', 'key:value']
        }),
        (FakeMetric("some_local_metric"), {
            'custom_tags': ['db_name:mydb', 'key:value']
        }),
    ]
Ejemplo n.º 2
0
def test_service_check(aggregator, instance):
    check = Neo4jCheck('neo4j', {}, {})

    instance['neo4j_dbs'] = ['neo4j', 'system']

    check.check(instance)

    print(aggregator.metric_names)

    if instance.get('neo4j_version') == '3.5':
        aggregator.assert_metric(
            name='{}.page_cache.hits'.format(NAMESPACE),
            tags=['db_name:{}'.format(GLOBAL_DB_NAME)],
        )
        aggregator.assert_metric(
            name='{}.check_point.events'.format(NAMESPACE),
            tags=['db_name:{}'.format(GLOBAL_DB_NAME)],
        )
    elif instance.get('neo4j_version') == '4.0':
        aggregator.assert_metric(
            name='{}.page_cache.hits'.format(NAMESPACE),
            tags=['db_name:{}'.format(GLOBAL_DB_NAME)],
        )
        aggregator.assert_metric(
            name='{}.check_point.events'.format(NAMESPACE),
            tags=['db_name:neo4j'])
        aggregator.assert_metric(
            name='{}.check_point.events'.format(NAMESPACE),
            tags=['db_name:system'])
    else:
        raise Exception('unknown neo4j_version: {}'.format(
            instance.get('neo4j_version')))
Ejemplo n.º 3
0
def test_get_value():
    check = Neo4jCheck('neo4j', {}, {})

    with pytest.raises(ConfigurationError):
        check._get_value({}, 'neo4j_version', required=True)

    assert check._get_value({}, 'neo4j_dbs', False, ['neo4j']) == ['neo4j']
    assert check._get_value({'neo4j_version': '3.5'}, 'neo4j_version', True)
Ejemplo n.º 4
0
def test_get_db_for_metric():
    check = Neo4jCheck('neo4j', {}, {})

    assert check._get_db_for_metric(dbs=['neo4j', 'system'],
                                    metric_name='neo4j_metric_1') == 'neo4j'
    assert check._get_db_for_metric(dbs=['neo4j', 'system'],
                                    metric_name='system_metric_1') == 'system'
    assert check._get_db_for_metric(dbs=['neo4j', 'system'],
                                    metric_name='metric_1') is None
def test_connection_failure(aggregator):
    """
    Service check reports connection failure
    """
    c = Neo4jCheck(CHECK_NAME, {}, {})

    with pytest.raises(CheckException):
        c.check(CONNECTION_FAILURE)

    aggregator.assert_service_check('neo4j.can_connect',
                                    status=Neo4jCheck.CRITICAL)
def test_minimal_config(aggregator):
    c = Neo4jCheck(CHECK_NAME, {}, {})
    c.check(NEO4J_MINIMAL_CONFIG)

    # Test service check
    aggregator.assert_service_check('neo4j.can_connect', status=Neo4jCheck.OK)

    # Test metrics
    testable_metrics = NEO4J_VARS

    for mname in testable_metrics:
        aggregator.assert_metric('neo4j.{}'.format(mname), tags=[])

    aggregator.assert_all_metrics_covered()
Ejemplo n.º 7
0
def test_get_config():
    check = Neo4jCheck('neo4j', {}, {})

    instance = {
        'host': 'localhost',
        'port': 9000,
        'neo4j_version': '4.0',
        'neo4j_dbs': ['neo4j', 'system'],
        'exclude_labels': ['kube_service'],
        'tags': ['key:value'],
    }
    assert check._get_config(instance) == Config(
        host='localhost',
        port=9000,
        neo4j_version='4.0',
        neo4j_dbs=['neo4j', 'system'],
        exclude_labels=['kube_service'],
        instance_tags=['key:value'],
    )

    instance = {
        'host': 'localhost',
        'neo4j_version': '3.5',
    }
    assert check._get_config(instance) == Config(
        host='localhost',
        port=2004,
        neo4j_version='3.5',
        neo4j_dbs=[],
        exclude_labels=[],
        instance_tags=[],
    )

    instance = {}
    with pytest.raises(ConfigurationError):
        check._get_config(instance)

    instance = {'host': 'localhost'}
    with pytest.raises(ConfigurationError):
        check._get_config(instance)
Ejemplo n.º 8
0
def test(aggregator, dd_run_check, instance):
    check = Neo4jCheck('neo4j', {}, [instance])
    dd_run_check(check)

    aggregator.assert_service_check('neo4j.openmetrics.health',
                                    ServiceCheck.OK)

    if NEO4J_VERSION.startswith('3.5'):
        aggregator.assert_metric(
            'neo4j.page_cache.hits.count',
            tags=['db_name:global', f'endpoint:{METRICS_URL}'])
    elif NEO4J_VERSION.startswith('4.0'):
        aggregator.assert_metric(
            'neo4j.page_cache.hits.count',
            tags=['db_name:global', f'endpoint:{METRICS_URL}'])
        aggregator.assert_metric(
            'neo4j.check_point.duration',
            tags=['db_name:neo4j', f'endpoint:{METRICS_URL}'])
        aggregator.assert_metric(
            'neo4j.check_point.duration',
            tags=['db_name:system', f'endpoint:{METRICS_URL}'])
    elif NEO4J_VERSION.startswith('4.1'):
        aggregator.assert_metric(
            'neo4j.page_cache.hits.count',
            tags=['db_name:global', f'endpoint:{METRICS_URL}'])
        aggregator.assert_metric(
            'neo4j.check_point.duration',
            tags=['db_name:neo4j', f'endpoint:{METRICS_URL}'])
        aggregator.assert_metric(
            'neo4j.check_point.duration',
            tags=['db_name:system', f'endpoint:{METRICS_URL}'])
    elif NEO4J_VERSION.startswith('4.2'):
        aggregator.assert_metric(
            'neo4j.page_cache.hits.count',
            tags=['db_name:global', f'endpoint:{METRICS_URL}'])
        aggregator.assert_metric(
            'neo4j.check_point.duration',
            tags=['db_name:neo4j', f'endpoint:{METRICS_URL}'])
        aggregator.assert_metric(
            'neo4j.check_point.duration',
            tags=['db_name:system', f'endpoint:{METRICS_URL}'])
    elif NEO4J_VERSION.startswith('4.3'):
        aggregator.assert_metric(
            'neo4j.page_cache.hits.count',
            tags=['db_name:global', f'endpoint:{METRICS_URL}'])
        aggregator.assert_metric(
            'neo4j.check_point.duration',
            tags=['db_name:neo4j', f'endpoint:{METRICS_URL}'])
        aggregator.assert_metric(
            'neo4j.check_point.duration',
            tags=['db_name:system', f'endpoint:{METRICS_URL}'])
    elif NEO4J_VERSION.startswith('4.4'):
        aggregator.assert_metric(
            'neo4j.page_cache.hits.count',
            tags=['db_name:global', f'endpoint:{METRICS_URL}'])
        aggregator.assert_metric(
            'neo4j.check_point.duration',
            tags=['db_name:neo4j', f'endpoint:{METRICS_URL}'])
        aggregator.assert_metric(
            'neo4j.check_point.duration',
            tags=['db_name:system', f'endpoint:{METRICS_URL}'])
    else:
        raise Exception(f'unknown neo4j_version: {NEO4J_VERSION}')