def test_bad_globbing():
    with run_container("zookeeper:3.4") as zk_cont:
        zkhost = container_ip(zk_cont)
        assert wait_for(p(tcp_socket_open, zkhost, 2181), 30)
        create_znode(zk_cont, "/env", "prod")

        final_conf = BAD_GLOB_CONFIG.substitute(zk_endpoint="%s:2181" % zkhost)
        with Agent.run(final_conf) as agent:
            assert wait_for(
                lambda: "zookeeper only supports globs" in agent.output)
def test_ecs_container_image_filtering():
    with run_service("ecsmeta") as ecsmeta, run_container(
            "redis:4-alpine") as redis:
        ecsmeta_ip = container_ip(ecsmeta)
        redis_ip = container_ip(redis)
        with Agent.run("""
    monitors:
      - type: ecs-metadata
        metadataEndpoint: http://%s/metadata_single?redis_ip=%s
        statsEndpoint: http://%s/stats
        excludedImages:
          - redis:latest

    """ % (ecsmeta_ip, redis_ip, ecsmeta_ip)) as agent:
            assert ensure_always(lambda: not has_datapoint_with_dim(
                agent.fake_services,
                "container_id",
                "c42fa5a73634bcb6e301dfb7b13ac7ead2af473210be6a15da75a290c283b66c",
            ))
Beispiel #3
0
 def is_running(self):
     if not self.container:
         filters = {"name": self.container_name, "status": "running"}
         if self.host_client and self.container_name and self.host_client.containers.list(filters=filters):
             self.container = self.host_client.containers.get(self.container_name)
     if self.container:
         self.container.reload()
         self.container_ip = container_ip(self.container)
         return self.container.status == "running" and self.container_ip
     return False
Beispiel #4
0
def test_with_default_config_2_4_5():
    with run_service("elasticsearch/2.4.5") as es_container:
        host = container_ip(es_container)
        check_service_status(host)
        agent_config = AGENT_CONFIG_TEMPLATE.format(host=host, flag="")
        with Agent.run(agent_config) as agent:
            assert wait_for(
                p(any_metric_has_any_dim_key, agent.fake_services, METADATA.default_metrics, METADATA.dims)
            ), "Didn't get all default dimensions"
            assert not has_log_message(agent.output.lower(), "error"), "error found in agent output!"
Beispiel #5
0
def run_consumer(image, kafka_host, **kwargs):
    with run_container(
        image,
        name=f"kafka-consumer-{random_hex()}",
        environment={"JMX_PORT": "9099", "START_AS": "consumer", "KAFKA_BROKER": f"{kafka_host}:9092"},
        **kwargs,
    ) as kafka_consumer:
        host = container_ip(kafka_consumer)
        assert wait_for(p(tcp_socket_open, host, 9099), 60), "kafka consumer jmx didn't start"
        yield host
Beispiel #6
0
def run_redis(image="redis:4-alpine"):
    with run_container(image) as redis_container:
        host = container_ip(redis_container)
        assert wait_for(p(tcp_socket_open, host, 6379),
                        60), "service not listening on port"

        redis_client = redis.StrictRedis(host=host, port=6379, db=0)
        assert wait_for(redis_client.ping, 60), "service didn't start"

        yield [host, redis_client]
def test_ecs_observer_dim_label():
    with run_service("ecsmeta") as ecsmeta:
        with run_container("redis:4-alpine") as redis:
            with run_agent(
                CONFIG.substitute(
                    host=container_ip(ecsmeta),
                    redis_ip=container_ip(redis),
                    mongo_ip="not_used",
                    case="metadata_single",
                )
            ) as [backend, _, _]:
                assert wait_for(
                    p(has_datapoint_with_dim, backend, "container_spec_name", "redis")
                ), "Didn't get redis datapoints"

            # Let redis be removed by docker observer and collectd restart
            time.sleep(5)
            backend.datapoints.clear()
            assert ensure_always(lambda: not has_datapoint_with_dim(backend, "ClusterName", "seon-fargate-test"), 10)
Beispiel #8
0
def test_nginx():
    with run_service("nginx") as nginx_container:
        host = container_ip(nginx_container)
        config = NGINX_CONFIG.substitute(host=host)
        assert wait_for(p(tcp_socket_open, host, 80), 60), "service didn't start"

        with Agent.run(config) as agent:
            assert wait_for(
                p(has_datapoint_with_dim, agent.fake_services, "plugin", "nginx")
            ), "Didn't get nginx datapoints"
Beispiel #9
0
def test_kong(kong_version):  # pylint: disable=redefined-outer-name
    pg_env = dict(POSTGRES_USER="******", POSTGRES_PASSWORD="******", POSTGRES_DB="kong")
    kong_env = dict(
        KONG_ADMIN_LISTEN="0.0.0.0:8001",
        KONG_LOG_LEVEL="warn",
        KONG_DATABASE="postgres",
        KONG_PG_DATABASE=pg_env["POSTGRES_DB"],
        KONG_PG_PASSWORD=pg_env["POSTGRES_PASSWORD"],
    )

    with run_container("postgres:9.5", environment=pg_env) as db:
        db_ip = container_ip(db)
        kong_env["KONG_PG_HOST"] = db_ip

        assert wait_for(p(tcp_socket_open, db_ip, 5432))

        with run_service(
            "kong", buildargs={"KONG_VERSION": kong_version}, environment=kong_env, command="sleep inf"
        ) as migrations:
            if kong_version in ["0.15-centos", "1.0.0-centos"]:
                assert container_cmd_exit_0(migrations, "kong migrations bootstrap")
            else:
                assert container_cmd_exit_0(migrations, "kong migrations up")

        with run_service("kong", buildargs={"KONG_VERSION": kong_version}, environment=kong_env) as kong:
            kong_ip = container_ip(kong)
            assert wait_for(p(http_status, url=f"http://{kong_ip}:8001/signalfx", status=[200]))
            config = dedent(
                f"""
            monitors:
              - type: collectd/kong
                host: {kong_ip}
                port: 8001
                metrics:
                  - metric: connections_handled
                    report: true
            """
            )
            with Agent.run(config) as agent:
                assert wait_for(
                    p(has_datapoint_with_dim, agent.fake_services, "plugin", "kong")
                ), "Didn't get Kong data point"
Beispiel #10
0
def test_redis(image):
    with run_container(image) as test_container:
        host = container_ip(test_container)
        config = monitor_config.substitute(host=host)
        assert wait_for(p(tcp_socket_open, host, 6379), 60), "service not listening on port"

        redis_client = redis.StrictRedis(host=host, port=6379, db=0)
        assert wait_for(redis_client.ping, 60), "service didn't start"

        with run_agent(config) as [backend, _, _]:
            assert wait_for(p(has_datapoint_with_dim, backend, "plugin", "redis_info")), "didn't get datapoints"
Beispiel #11
0
def test_etcd_monitor():
    with run_etcd() as etcd_cont:
        host = container_ip(etcd_cont)
        config = ETCD_CONFIG.format(host=host)

        with Agent.run(config) as agent:
            assert wait_for(
                p(has_datapoint,
                  agent.fake_services,
                  metric_name="process_cpu_seconds_total")
            ), "Didn't get etcd datapoints"
def test_consul():
    with run_container("consul:0.9.3") as consul_cont:
        host = container_ip(consul_cont)
        config = CONSUL_CONFIG.substitute(host=host)

        assert wait_for(p(tcp_socket_open, host, 8500), 60), "consul service didn't start"

        with Agent.run(config) as agent:
            assert wait_for(
                p(has_datapoint_with_metric_name, agent.fake_services, "gauge.consul.catalog.services.total"), 60
            ), "Didn't get consul datapoints"
def test_haproxy(version):
    with run_service("haproxy", buildargs={"HAPROXY_VERSION":
                                           version}) as service_container:
        host = container_ip(service_container)
        config = MONITOR_CONFIG.substitute(host=host)
        assert wait_for(p(tcp_socket_open, host, 9000),
                        120), "haproxy not listening on port"
        with Agent.run(config) as agent:
            assert wait_for(
                p(has_datapoint_with_dim, agent.fake_services, "plugin",
                  "haproxy")), "didn't get datapoints"
Beispiel #14
0
def test_apache():
    with run_service("apache") as apache_container:
        host = container_ip(apache_container)
        config = apache_config.substitute(host=host)
        assert wait_for(p(tcp_socket_open, host, 80),
                        60), "service didn't start"

        with run_agent(config) as [backend, _, _]:
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin",
                  "apache")), "Didn't get apache datapoints"
Beispiel #15
0
def test_apache():
    with run_service("apache") as apache_container:
        host = container_ip(apache_container)
        config = APACHE_CONFIG.substitute(host=host)
        assert wait_for(p(tcp_socket_open, host, 80),
                        60), "service didn't start"

        with Agent.run(config) as agent:
            assert wait_for(
                p(has_datapoint_with_dim, agent.fake_services, "plugin",
                  "apache")), "Didn't get apache datapoints"
Beispiel #16
0
def test_mongo():
    with run_container("mongo:3.6") as mongo_cont:
        host = container_ip(mongo_cont)
        config = mongo_config.substitute(host=host)
        assert wait_for(p(tcp_socket_open, host, 27017),
                        60), "service didn't start"

        with run_agent(config) as [backend, _, _]:
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin",
                  "mongo")), "Didn't get mongo datapoints"
def test_couchbase():
    with run_service("couchbase",
                     hostname="node1.cluster") as couchbase_container:
        host = container_ip(couchbase_container)
        config = couchbase_config.substitute(host=host)
        assert wait_for(p(tcp_socket_open, host, 8091),
                        60), "service didn't start"

        with run_agent(config) as [backend, _, _]:
            assert wait_for(p(has_datapoint_with_dim, backend, "plugin", "couchbase")), \
                   "Didn't get couchbase datapoints"
Beispiel #18
0
def test_haproxy_default_metrics_from_stats_page(version):
    with run_service("haproxy", buildargs={"HAPROXY_VERSION":
                                           version}) as service_container:
        host = container_ip(service_container)
        with Agent.run(f"""
           monitors:
           - type: haproxy
             url: http://{host}:8080/stats?stats;csv
           """) as agent:
            verify(agent, EXPECTED_DEFAULTS - EXPECTED_DEFAULTS_FROM_SOCKET,
                   10)
Beispiel #19
0
def test_postgresql():
    with run_container("postgres:10", environment=ENV) as cont:
        host = container_ip(cont)
        config = CONFIG_TEMP.substitute(host=host)
        assert wait_for(p(tcp_socket_open, host, 5432), 60), "service didn't start"

        with Agent.run(config) as agent:
            assert wait_for(
                p(has_datapoint_with_dim, agent.fake_services, "plugin", "postgresql")
            ), "Didn't get postgresql datapoints"
            assert wait_for(p(has_datapoint_with_metric_name, agent.fake_services, "pg_blks.toast_hit"))
Beispiel #20
0
def run_kong(kong_version):
    pg_env = dict(POSTGRES_USER="******", POSTGRES_PASSWORD="******", POSTGRES_DB="kong")
    kong_env = dict(
        KONG_ADMIN_LISTEN="0.0.0.0:8001",
        KONG_LOG_LEVEL="warn",
        KONG_DATABASE="postgres",
        KONG_PG_DATABASE=pg_env["POSTGRES_DB"],
        KONG_PG_PASSWORD=pg_env["POSTGRES_PASSWORD"],
    )

    with run_container("postgres:9.5", environment=pg_env) as db:
        db_ip = container_ip(db)
        kong_env["KONG_PG_HOST"] = db_ip

        assert wait_for(p(tcp_socket_open, db_ip, 5432))

        with run_service(
            "kong",
            name="kong-boot",
            buildargs={"KONG_VERSION": kong_version},
            environment=kong_env,
            command="sleep inf",
        ) as migrations:
            if kong_version in ["0.15-centos", "1.0.0-centos"]:
                assert container_cmd_exit_0(migrations, "kong migrations bootstrap")
            else:
                assert container_cmd_exit_0(migrations, "kong migrations up")

        with run_service(
            "kong", name="kong", buildargs={"KONG_VERSION": kong_version}, environment=kong_env
        ) as kong, run_container(
            "openresty/openresty:centos", files=[(SCRIPT_DIR / "echo.conf", "/etc/nginx/conf.d/echo.conf")]
        ) as echo:
            kong_ip = container_ip(kong)
            kong_admin = f"http://{kong_ip}:8001"
            assert wait_for(p(http_status, url=f"{kong_admin}/signalfx", status=[200]))

            paths, _ = configure_kong(kong_admin, kong_version, container_ip(echo))
            # Needs time to settle after creating routes.
            retry(lambda: run_traffic(paths, f"http://{kong_ip}:8000"), AssertionError, interval_seconds=2)
            yield kong_ip
def test_ecs_container_stats_without_container_metadata():
    with run_service("ecsmeta") as ecsmeta, run_container(
            "redis:4-alpine") as redis:
        ecsmeta_ip = container_ip(ecsmeta)
        redis_ip = container_ip(redis)
        with run_agent("""
    monitors:
      - type: ecs-metadata
        metadataEndpoint: http://%s/metadata_single?redis_ip=%s&mask_redis=true
        statsEndpoint: http://%s/stats

    """ % (ecsmeta_ip, redis_ip, ecsmeta_ip)) as [backend, _, _]:
            assert wait_for(
                # container_id is included in stats.json file in ecsmeta app
                # because stats data don't come directly from the docker container but from ecs metadata api
                p(
                    has_datapoint_with_dim,
                    backend,
                    "container_id",
                    "c42fa5a73634bcb6e301dfb7b13ac7ead2af473210be6a15da75a290c283b66c",
                )), "Didn't get redis datapoints"
Beispiel #22
0
def test_memcached_included(version):
    with run_container(version) as container:
        host = container_ip(container)
        run_agent_verify_included_metrics(
            f"""
            monitors:
            - type: collectd/memcached
              host: {host}
              port: 11211
            """,
            METADATA,
        )
Beispiel #23
0
def test_etcd_monitor():
    with run_container("quay.io/coreos/etcd:v2.3.8",
                       command=ETCD_COMMAND) as etcd_cont:
        host = container_ip(etcd_cont)
        config = etcd_config.substitute(host=host)
        assert wait_for(p(tcp_socket_open, host, 2379),
                        60), "service didn't start"

        with run_agent(config) as [backend, _, _]:
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin",
                  "etcd")), "Didn't get etcd datapoints"
Beispiel #24
0
def run(config, metrics):
    with run_service("apache") as apache_container:
        host = container_ip(apache_container)
        config = config.format(host=host)
        assert wait_for(p(tcp_socket_open, host, 80),
                        60), "service didn't start"

        with Agent.run(config) as agent:
            verify(agent, metrics)
            assert has_datapoint_with_dim(
                agent.fake_services, "plugin",
                "apache"), "Didn't get apache datapoints"
def test_basic_zk_config():
    with run_container("zookeeper:3.4") as zk:
        assert wait_for(p(container_cmd_exit_0, zk, "nc -z localhost 2181"), 5)
        create_znode(zk, "/env", "prod")
        create_znode(zk, "/monitors", "")
        create_znode(zk, "/monitors/cpu", "- type: collectd/cpu")
        create_znode(zk, "/monitors/signalfx-metadata", "- type: collectd/signalfx-metadata")

        final_conf = config.substitute(zk_endpoint="%s:2181" % container_ip(zk))
        with run_agent(final_conf) as [backend, get_output, _]:
            assert wait_for(p(has_datapoint_with_dim, backend, "plugin", "signalfx-metadata"))
            assert wait_for(p(has_datapoint_with_dim, backend, "env", "prod"))
Beispiel #26
0
def test_cassandra():
    with run_service("cassandra") as cassandra_cont:
        host = container_ip(cassandra_cont)
        config = CASSANDRA_CONFIG.substitute(host=host)

        # Wait for the JMX port to be open in the container
        assert wait_for(p(tcp_socket_open, host, 7199), 60), "Cassandra JMX didn't start"

        with run_agent(config) as [backend, _, _]:
            assert wait_for(
                p(has_datapoint_with_metric_name, backend, "counter.cassandra.ClientRequest.Read.Latency.Count"), 60
            ), "Didn't get Cassandra datapoints"
Beispiel #27
0
def test_ecs_container_label_dimension():
    with run_service("ecsmeta") as ecsmeta, run_container("redis:4-alpine") as redis:
        ecsmeta_ip = container_ip(ecsmeta)
        redis_ip = container_ip(redis)
        with Agent.run(
            """
    monitors:
      - type: ecs-metadata
        metadataEndpoint: http://%s/metadata_single?redis_ip=%s
        statsEndpoint: http://%s/stats
        labelsToDimensions:
          container_name: container_title

    """
            % (ecsmeta_ip, redis_ip, ecsmeta_ip)
        ) as agent:
            assert ensure_always(
                lambda: not has_datapoint_with_dim(
                    agent.fake_services, "container_title", "ecs-seon-fargate-test-3-redis-baf2cfda88f8d8ee4900"
                )
            )
Beispiel #28
0
def test_snmp():
    # snmp-simulator source is available at: https://github.com/xeemetric/snmp-simulator
    # the hard coded uptime OID used in this test was fetched using the following command
    # $ snmpget -On -v2c -c public <snmp simulator host>:161 system.sysUpTime.0
    with run_container("xeemetric/snmp-simulator") as test_container:
        host = container_ip(test_container)
        config = monitor_config.substitute(host=host)

        with run_agent(config) as [backend, _, _]:
            assert wait_for(
                p(has_datapoint_with_dim, backend, "plugin", "telegraf-snmp")
            ), "didn't get database io datapoints"
Beispiel #29
0
def test_openstack_default(devstack):
    host = container_ip(devstack)
    run_agent_verify(
        f"""
            monitors:
            - type: collectd/openstack
              authURL: http://{host}/identity/v3
              username: admin
              password: testing123
        """,
        DEFAULT_METRICS,
    )
def run_vault_iam_test(iam_config):
    """
    Test that Vault will authenticate a user with IAM crednetials and provide a
    token
    """
    with run_vault() as [vault_client, _], run_service("awsapi") as aws_cont:
        aws_ip = container_ip(aws_cont)
        assert wait_for(p(tcp_socket_open, aws_ip, 8080), 30)
        vault_client.sys.enable_auth_method("aws")

        vault_client.write(
            "auth/aws/config/client",
            **{
                "iam_endpoint": f"http://{aws_ip}:8080/iam",
                "sts_endpoint": f"http://{aws_ip}:8080/sts",
                "ec2_endpoint": f"http://{aws_ip}:8080/ec2",
                "secret_key": "MY_SECRET_KEY",
                "access_key": "MY_ACCESS_KEY",
            },
        )

        vault_client.sys.create_or_update_policy(
            name="dev", policy=READ_ALL_SECRETS_POLICY)

        vault_client.write(
            "auth/aws/role/dev-role-iam",
            **{
                "auth_type": "iam",
                "policies": "dev",
                "bound_iam_principal_arn": "arn:aws:iam::0123456789:*"
            },
        )

        vault_client.write("secret/data/app", data={"env": "dev"})

        with Agent.run(
                dedent(f"""
            intervalSeconds: 1
            globalDimensions:
               env: {{"#from": "vault:secret/data/app[data.env]"}}
            configSources:
              vault:
                vaultAddr: {vault_client.url}
                authMethod: iam
                iam: {json.dumps(iam_config)}
            monitors:
             - type: collectd/uptime
        """)) as agent:
            assert wait_for(p(has_datapoint,
                              agent.fake_services,
                              dimensions={"env": "dev"}),
                            timeout_seconds=10)