Exemplo n.º 1
0
def load_jmx_config():
    # Only called in tests of a check, so just go back one frame
    root = find_check_root(depth=1)

    check = basepath(root)
    example_config_path = path_join(root, 'datadog_checks', check, 'data',
                                    'conf.yaml.example')
    metrics_config_path = path_join(root, 'datadog_checks', check, 'data',
                                    'metrics.yaml')

    example_config = yaml.safe_load(read_file(example_config_path))
    metrics_config = yaml.safe_load(read_file(metrics_config_path))

    # Avoid having to potentially mount multiple files by putting the default metrics
    # in the user-defined metric location.
    example_config['init_config']['conf'] = metrics_config['jmx_metrics']

    return example_config
Exemplo n.º 2
0
    def test_custom_path_precedence(self):
        with TempDir() as d:
            template_file = path_join(d, 'init_config', 'tags.yaml')
            ensure_parent_dir_exists(template_file)
            write_file(template_file, 'test:\n- foo\n- bar')

            templates = ConfigTemplates([d])

            assert templates.load('init_config/tags') == {
                'test': ['foo', 'bar']
            }
Exemplo n.º 3
0
    def test_parse_error(self):
        with TempDir() as d:
            template_file = path_join(d, 'invalid.yaml')
            ensure_parent_dir_exists(template_file)
            write_file(template_file, '> invalid')

            templates = ConfigTemplates([d])

            with pytest.raises(ValueError,
                               match='^Unable to parse template `{}`'.format(
                                   re.escape(template_file))):
                templates.load('invalid')
Exemplo n.º 4
0
def dd_environment():
    use_openmetrics = CILIUM_LEGACY == 'false'
    kind_config = os.path.join(HERE, 'kind', 'kind-config.yaml')
    with TempDir('helm_dir') as helm_dir:
        with kind_run(
                conditions=[setup_cilium],
                kind_config=kind_config,
                env_vars={
                    "HELM_CACHE_HOME": path_join(helm_dir, 'Caches'),
                    "HELM_CONFIG_HOME": path_join(helm_dir, 'Preferences'),
                },
        ) as kubeconfig:
            with ExitStack() as stack:
                ip_ports = [
                    stack.enter_context(
                        port_forward(kubeconfig, 'cilium', port, 'deployment',
                                     'cilium-operator')) for port in PORTS
                ]

                instances = get_instances(ip_ports[0][0], ip_ports[0][1],
                                          ip_ports[1][0], ip_ports[1][1],
                                          use_openmetrics)

            yield instances
Exemplo n.º 5
0
def find_check_root(depth=0):
    # Account for this call
    depth += 1

    frame = inspect.currentframe()
    for _ in range(depth):
        frame = frame.f_back

    root = get_parent_dir(frame.f_code.co_filename)
    while True:
        if file_exists(path_join(root, 'setup.py')):
            break

        new_root = os.path.dirname(root)
        if new_root == root:
            raise OSError('No check found')

        root = new_root

    return root