Exemplo n.º 1
0
def test_check(aggregator):
    check = Varnish(common.CHECK_NAME, {}, {})
    config = common.get_config_by_version()

    check.check(config)
    for mname in common.COMMON_METRICS:
        aggregator.assert_metric(mname, count=1, tags=['cluster:webs', 'varnish_name:default'])
Exemplo n.º 2
0
def test_exclusion_filter(aggregator):
    check = Varnish(common.CHECK_NAME, {}, {})
    config = common.get_config_by_version()
    config['metrics_filter'] = ['^SMA.Transient.c_req']

    check.check(config)
    for mname in common.COMMON_METRICS:
        if 'SMA.Transient.c_req' in mname:
            aggregator.assert_metric(mname, count=0, tags=['cluster:webs', 'varnish_name:default'])
        elif 'varnish.uptime' not in mname:
            aggregator.assert_metric(mname, count=1, tags=['cluster:webs', 'varnish_name:default'])
Exemplo n.º 3
0
def test_inclusion_filter(aggregator, spin_up_varnish):
    check = Varnish(common.CHECK_NAME, {}, {})
    config = common.get_config_by_version()
    config['metrics_filter'] = ['SMA.*']

    check.check(config)
    for mname in common.COMMON_METRICS:
        if 'SMA.' in mname:
            aggregator.assert_metric(
                mname, count=1, tags=['cluster:webs', 'varnish_name:default'])
        else:
            aggregator.assert_metric(
                mname, count=0, tags=['cluster:webs', 'varnish_name:default'])
Exemplo n.º 4
0
def test_version_metadata(aggregator, instance, datadog_agent):
    check = Varnish(common.CHECK_NAME, {}, [instance])
    check.check_id = 'test:123'
    check.check(instance)

    raw_version = common.VARNISH_VERSION.replace('_', '.')
    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)
Exemplo n.º 5
0
def test_check_invalid_varnishadm(aggregator, instance, dd_run_check):
    # Note: this test may prompt you to enter a password when locally, if so, enter anything and it will pass
    instance['varnishadm'] = 'invalid-thing'
    check = Varnish(common.CHECK_NAME, {}, [instance])
    dd_run_check(check)

    aggregator.assert_service_check(Varnish.SERVICE_CHECK_NAME, count=0)
Exemplo n.º 6
0
def test_exclusion_filter(aggregator, instance, dd_run_check):
    instance['metrics_filter'] = ['^SMA.Transient.c_req']

    check = Varnish(common.CHECK_NAME, {}, [instance])
    dd_run_check(check)
    for mname in common.COMMON_METRICS:
        if 'SMA.Transient.c_req' in mname:
            aggregator.assert_metric(mname, count=0, tags=['varnish_cluster:webs', 'varnish_name:default'])
        elif 'varnish.uptime' not in mname:
            aggregator.assert_metric(mname, count=1, tags=['varnish_cluster:webs', 'varnish_name:default'])
Exemplo n.º 7
0
def test_command_line_manually_unhealthy(mock_subprocess, mock_version,
                                         mock_geteuid, aggregator):
    """
    Test the varnishadm output for version >= 4.x with manually set health
    """
    mock_version.return_value = LooseVersion('4.0.0'), 'xml'
    mock_geteuid.return_value = 0

    check = Varnish(common.CHECK_NAME, {}, {})

    config = common.get_config_by_version()
    config['varnishadm'] = common.VARNISHADM_PATH
    config['secretfile'] = common.SECRETFILE_PATH

    check.check(config)
    args, _ = mock_subprocess.call_args
    assert args[0] == [
        common.VARNISHADM_PATH, '-S', common.SECRETFILE_PATH, 'debug.health'
    ]
    aggregator.assert_service_check("varnish.backend_healthy",
                                    status=Varnish.CRITICAL,
                                    tags=['backend:default', 'cluster:webs'],
                                    count=1)

    mock_version.return_value = LooseVersion('4.1.0'), 'xml'
    mock_geteuid.return_value = 1

    check.check(config)
    args, _ = mock_subprocess.call_args
    assert args[0] == [
        'sudo', common.VARNISHADM_PATH, '-T', common.DAEMON_ADDRESS, '-S',
        common.SECRETFILE_PATH, 'backend.list', '-p'
    ]
Exemplo n.º 8
0
def test_command_line_post_varnish5(mock_subprocess, mock_version,
                                    mock_geteuid, aggregator):
    """
    Test the Varnishadm output for version >= 5.x
    """
    mock_version.return_value = LooseVersion('5.0.0'), 'json'
    mock_geteuid.return_value = 0

    check = Varnish(common.CHECK_NAME, {}, {})

    config = common.get_config_by_version()
    config['varnishadm'] = common.VARNISHADM_PATH
    config['secretfile'] = common.SECRETFILE_PATH

    check.check(config)
    args, _ = mock_subprocess.call_args
    assert args[0] == [
        common.VARNISHADM_PATH, '-T', common.DAEMON_ADDRESS, '-S',
        common.SECRETFILE_PATH, 'backend.list', '-p'
    ]
    aggregator.assert_service_check("varnish.backend_healthy",
                                    status=Varnish.OK,
                                    tags=['backend:backend2', 'cluster:webs'],
                                    count=1)

    mock_version.return_value = LooseVersion('5.0.0'), 'json'
    mock_geteuid.return_value = 1

    check.check(config)
    args, _ = mock_subprocess.call_args
    assert args[0] == [
        'sudo', common.VARNISHADM_PATH, '-T', common.DAEMON_ADDRESS, '-S',
        common.SECRETFILE_PATH, 'backend.list', '-p'
    ]
Exemplo n.º 9
0
def test_command_line(mock_subprocess, mock_version, mock_geteuid, aggregator,
                      instance):
    """
    Test the varnishadm output for Varnish < 4.x
    """
    mock_version.return_value = LooseVersion("3.9.0"), 'xml'
    mock_geteuid.return_value = 0

    instance['varnishadm'] = common.VARNISHADM_PATH
    instance['secretfile'] = common.SECRETFILE_PATH
    check = Varnish(common.CHECK_NAME, {}, [instance])

    check.check(instance)
    args, _ = mock_subprocess.call_args
    assert args[0] == [
        common.VARNISHADM_PATH, '-S', common.SECRETFILE_PATH, 'debug.health'
    ]
    aggregator.assert_service_check(
        "varnish.backend_healthy",
        status=check.OK,
        tags=['backend:default', 'varnish_cluster:webs'],
        count=1)
Exemplo n.º 10
0
def test_check(aggregator, instance, dd_run_check):
    check = Varnish(common.CHECK_NAME, {}, [instance])
    dd_run_check(check)

    if common.VARNISH_VERSION.startswith("5"):
        metrics_to_check = common.COMMON_METRICS + common.METRICS_5
    else:
        metrics_to_check = common.COMMON_METRICS + common.METRICS_6

    for mname in metrics_to_check:
        aggregator.assert_metric(mname, count=1, tags=['varnish_cluster:webs', 'varnish_name:default'])

    aggregator.assert_all_metrics_covered()
    metadata_metrics = get_metadata_metrics()
    aggregator.assert_metrics_using_metadata(metadata_metrics, check_submission_type=True)
Exemplo n.º 11
0
def test_command_line_post_varnish6_5(mock_subprocess, mock_version,
                                      mock_geteuid, aggregator, instance):
    """
    Test the Varnishadm output for version >= 6.5
    """
    mock_version.return_value = LooseVersion('6.5.0'), 'json'
    mock_geteuid.return_value = 0

    instance['varnishadm'] = common.VARNISHADM_PATH
    instance['secretfile'] = common.SECRETFILE_PATH
    check = Varnish(common.CHECK_NAME, {}, [instance])

    check.check(instance)
    args, _ = mock_subprocess.call_args
    assert args[0] == [
        common.VARNISHADM_PATH,
        '-T',
        common.DAEMON_ADDRESS,
        '-S',
        common.SECRETFILE_PATH,
        'backend.list',
        '-p',
    ]
    aggregator.assert_service_check(
        "varnish.backend_healthy",
        status=check.OK,
        tags=['backend:backend2', 'varnish_cluster:webs'],
        count=1)

    mock_version.return_value = LooseVersion('6.5.0'), 'json'
    mock_geteuid.return_value = 1

    check.check(instance)
    args, _ = mock_subprocess.call_args
    assert args[0] == [
        'sudo',
        common.VARNISHADM_PATH,
        '-T',
        common.DAEMON_ADDRESS,
        '-S',
        common.SECRETFILE_PATH,
        'backend.list',
        '-p',
    ]
Exemplo n.º 12
0
def check():
    return Varnish(common.CHECK_NAME, {}, {})