def write_agent_config(cont, activemq_container):
    agent = Agent(
        host="127.0.0.1",
        fake_services=None,
        run_dir="/tmp/signalfx",
        config=dedent(f"""
        signalFxRealm: us0
        observers:
          - type: host

        monitors:
          - type: host-metadata
          - type: cpu
          - type: filesystems
          - type: disk-io
          - type: net-io
          - type: load
          - type: memory
          - type: vmem
          # This is a GenericJMX Java plugin, so we test the bundled Java runtime
          - type: collectd/activemq
            host: {container_ip(activemq_container)}
            port: 1099
            username: testuser
            password: testing123
    """),
    )
    copy_file_content_into_container(agent.get_final_config_yaml(), cont,
                                     "/etc/signalfx/agent.yaml")
Example #2
0
def test_bundle(request, base_image):
    # Get bundle path from command line flag to pytest
    bundle_path = request.config.getoption("--test-bundle-path")
    if not bundle_path:
        raise ValueError(
            "You must specify the --test-bundle-path flag to run bundle tests")

    with run_service("activemq") as activemq_container:
        with run_init_system_image(base_image,
                                   command="/usr/bin/tail -f /dev/null") as [
                                       cont, backend
                                   ]:
            copy_file_into_container(bundle_path, cont, "/opt/bundle.tar.gz")

            code, output = cont.exec_run(f"tar -xf /opt/bundle.tar.gz -C /opt")
            assert code == 0, f"Could not untar bundle: {output}"

            code, output = cont.exec_run(
                f"/opt/signalfx-agent/bin/patch-interpreter /opt/signalfx-agent"
            )
            assert code == 0, f"Could not patch interpreter: {output}"

            agent = Agent(
                host="127.0.0.1",
                fake_services=None,
                run_dir="/tmp/signalfx",
                config=dedent(f"""
                signalFxRealm: us0
                observers:
                  - type: host

                monitors:
                  - type: host-metadata
                  - type: cpu
                  - type: filesystems
                  - type: disk-io
                  - type: net-io
                  - type: load
                  - type: memory
                  - type: vmem
                  # This is a GenericJMX Java plugin, so we test the bundled Java runtime
                  - type: collectd/activemq
                    host: {container_ip(activemq_container)}
                    port: 1099
                    username: testuser
                    password: testing123
            """),
            )
            copy_file_content_into_container(agent.get_final_config_yaml(),
                                             cont, "/etc/signalfx/agent.yaml")

            _, output = cont.exec_run(
                [
                    "/bin/sh", "-c",
                    "exec /opt/signalfx-agent/bin/signalfx-agent > /var/log/signalfx-agent.log"
                ],
                detach=True,
                stream=True,
            )

            try:
                assert wait_for(
                    p(has_datapoint, backend, metric_name="cpu.utilization"),
                    timeout_seconds=10
                ), "Python metadata datapoint didn't come through"
                assert wait_for(
                    p(has_datapoint,
                      backend,
                      metric_name="gauge.amq.queue.QueueSize")
                ), "Didn't get activemq queue size datapoint"
            finally:
                print("Agent log:")
                _, output = cont.exec_run("cat /var/log/signalfx-agent.log")
                print_lines(output)