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"
def kubeconfig_exists(): try: return container_cmd_exit_0( self.container, "test -f %s" % MINIKUBE_KUBECONFIG_PATH) except requests.exceptions.RequestException as e: print("requests.exceptions.RequestException:\n%s" % str(e)) return False
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", 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, run_container( "openresty/openresty:1.15.8.1-4-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_signalfx_forwarder_app(splunk_version): with run_splunk(splunk_version) as [cont, backend]: splunk_host = container_ip(cont) assert wait_for(p(http_status, url=f"http://{splunk_host}:8000", status=[200]), 120), "service didn't start" time.sleep(5) # add certs for fake backend to splunk python cert_path = cont.exec_run("splunk cmd python -m requests.certs", stderr=False).output.decode("utf-8") assert cert_path, "failed to get cert path for splunk python" assert container_cmd_exit_0(cont, f"sh -c 'cat /*.cert >> {cert_path}'") assert container_cmd_exit_0(cont, "/test/install-app.sh", user="******"), "failed to install app" assert wait_for(p(http_status, url=f"http://{splunk_host}:8000", status=[200]), 120), "service didn't start" assert wait_for( p(has_series_data, cont), timeout_seconds=60, interval_seconds=2 ), "timed out waiting for series data" try: # test tosfx query with time cmd = ( "search 'index=_internal series=* | table _time kb ev max_age | `gauge(kb)` " "| `counter(ev)` | `cumulative_counter(max_age)` | tosfx'" ) code, output = run_splunk_cmd(cont, cmd) assert code == 0, output.decode("utf-8") assert wait_for(p(has_datapoint, backend, metric="kb", metric_type="gauge", has_timestamp=True)) assert wait_for(p(has_datapoint, backend, metric="ev", metric_type="counter", has_timestamp=True)) assert wait_for( p(has_datapoint, backend, metric="max_age", metric_type="cumulative_counter", has_timestamp=True) ) # check that datapoints are not streaming num_datapoints = len(backend.datapoints) assert ensure_always(lambda: len(backend.datapoints) == num_datapoints, timeout_seconds=60) # test tosfx query without time backend.reset_datapoints() cmd = ( "search 'index=_internal series=* | table kb ev max_age | `gauge(kb)` " "| `counter(ev)` | `cumulative_counter(max_age)` | tosfx'" ) code, output = run_splunk_cmd(cont, cmd) assert code == 0, output.decode("utf-8") assert wait_for(p(has_datapoint, backend, metric="kb", metric_type="gauge", has_timestamp=False)) assert wait_for(p(has_datapoint, backend, metric="ev", metric_type="counter", has_timestamp=False)) assert wait_for( p(has_datapoint, backend, metric="max_age", metric_type="cumulative_counter", has_timestamp=False) ) finally: print_datapoints(backend) code, output = cont.exec_run("cat /opt/splunk/var/log/splunk/python.log") if code == 0 and output: print("/opt/splunk/var/log/splunk/python.log:") print(output.decode("utf-8")) code, output = cont.exec_run("cat /opt/splunk/var/log/splunk/signalfx-forwarder-app.log") if code == 0 and output: print("/opt/splunk/var/log/splunk/signalfx-forwarder-app.log") print(output.decode("utf-8"))