diff --git a/libbeat/tests/system/beat/compose.py b/libbeat/tests/system/beat/compose.py index 54387f006df7..b32880639154 100644 --- a/libbeat/tests/system/beat/compose.py +++ b/libbeat/tests/system/beat/compose.py @@ -1,10 +1,14 @@ from __future__ import absolute_import import os +import sys import time INTEGRATION_TESTS = os.environ.get('INTEGRATION_TESTS', False) +# TODO: To be removed when env files are removed from docker compose +OVERRIDE_HOST = os.environ.get('OVERRIDE_HOST', False) + if INTEGRATION_TESTS: from compose.cli.command import get_project @@ -89,21 +93,67 @@ def compose_down(cls): """ Stop all running containers """ + if os.environ.get('NO_COMPOSE'): + return + if INTEGRATION_TESTS and cls.COMPOSE_SERVICES: cls.compose_project().kill(service_names=cls.COMPOSE_SERVICES) @classmethod - def compose_hosts(cls): + def get_hosts(cls): + return [cls.compose_host()] + + @classmethod + def _private_host(cls, info, port): + """ + Return the address of the container, it should be reachable from the + host if docker is being run natively. To be used when the tests are + run from another container in the same network. It also works when + running from the host network if the docker daemon runs natively. + """ + networks = info['NetworkSettings']['Networks'].values() + port = port.split("/")[0] + for network in networks: + ip = network['IPAddress'] + if ip: + return "%s:%s" % (ip, port) + + @classmethod + def _exposed_host(cls, info, port): + """ + Return the exposed address in the host, can be used when the test is + run from the host network. Recommended when using docker machines. + """ + hostPort = info['NetworkSettings']['Ports'][port][0]['HostPort'] + return "localhost:%s" % hostPort + + @classmethod + def compose_host(cls, service=None, port=None): if not INTEGRATION_TESTS or not cls.COMPOSE_SERVICES: return [] - hosts = [] - for container in cls.compose_project().containers(service_names=cls.COMPOSE_SERVICES): - network_settings = container.inspect()['NetworkSettings'] - for network in network_settings['Networks'].values(): - if network['IPAddress']: - hosts.append(network['IPAddress']) - return hosts + if service is None: + service = cls.COMPOSE_SERVICES[0] + + # TODO: Remove condition when env files are removed from docker compose + if OVERRIDE_HOST: + host_env = os.environ.get(service.upper() + "_HOST") + if host_env: + return host_env + + container = cls.compose_project().containers(service_names=[service])[0] + info = container.inspect() + portsConfig = info['HostConfig']['PortBindings'] + if len(portsConfig) == 0: + raise Exception("No exposed ports for service %s" % service) + if port is None: + port = portsConfig.keys()[0] + + # We can use _exposed_host for all platforms when we can use host network + # in the metricbeat container + if sys.platform.startswith('linux'): + return cls._private_host(info, port) + return cls._exposed_host(info, port) @classmethod def compose_project(cls): diff --git a/metricbeat/docker-compose.yml b/metricbeat/docker-compose.yml index 32d60e37dd40..c4b3c1a47727 100644 --- a/metricbeat/docker-compose.yml +++ b/metricbeat/docker-compose.yml @@ -49,29 +49,45 @@ services: # Modules aerospike: build: ./module/aerospike/_meta + ports: + - 3000 apache: build: ./module/apache/_meta + ports: + - 80 apache_2_4_12: build: context: ./module/apache/_meta dockerfile: Dockerfile.2.4.12 + ports: + - 80 ceph: build: ./module/ceph/_meta + ports: + - 5000 consul: build: ./module/consul/_meta + ports: + - 8500 coredns: build: ./module/coredns/_meta + ports: + - 9153 couchbase: build: ./module/couchbase/_meta + ports: + - 8091 couchdb: build: ./module/couchdb/_meta + ports: + - 5984 # Dummy container for docker tests, so there is a container with # healthcheck generating events @@ -84,6 +100,8 @@ services: dropwizard: build: ./module/dropwizard/_meta + ports: + - 8080 elasticsearch: build: ./module/elasticsearch/_meta @@ -93,61 +111,97 @@ services: - "transport.host=127.0.0.1" - "http.host=0.0.0.0" - "xpack.security.enabled=false" + ports: + - 9200 envoyproxy: build: ./module/envoyproxy/_meta + ports: + - 9901 etcd: build: ./module/etcd/_meta + ports: + - 2379 etcd_3_2: build: context: ./module/etcd/_meta args: ETCD_VERSION: v3.2.25 + ports: + - 2379 golang: build: ./module/golang/_meta + ports: + - 6060 haproxy: build: ./module/haproxy/_meta + ports: + - 14567 + - 14568 + - 14569 haproxy_1_6: build: context: ./module/haproxy/_meta dockerfile: Dockerfile.1.6 + ports: + - 14567 + - 14568 + - 14569 haproxy_1_7: build: context: ./module/haproxy/_meta dockerfile: Dockerfile.1.7 + ports: + - 14567 + - 14568 + - 14569 http: build: ./module/http/_meta + ports: + - 8080 jolokia: build: ./module/jolokia/_meta + ports: + - 8778 kafka: build: context: ./module/kafka/_meta args: KAFKA_VERSION: 2.1.1 + ports: + - 9092 kafka_1_1_0: build: context: ./module/kafka/_meta args: KAFKA_VERSION: 1.1.0 + ports: + - 9092 kafka_0_10_2: build: context: ./module/kafka/_meta args: - KAFKA_VERSION: 0.10.2.1 + KAFKA_VERSION: 0.10.2.2 + ports: + - 9092 kibana: build: ./module/kibana/_meta + depends_on: + - elasticsearch + ports: + - 5601 #kubernetes: # build: ./module/kubernetes/_meta @@ -159,6 +213,8 @@ services: # - /sys:/sys # - /var/lib/docker:/var/lib/docker # - /var/run:/var/run + # ports: + # - 10255 #kubestate: # build: @@ -166,55 +222,77 @@ services: # dockerfile: Dockerfile.kube-state # depends_on: # - kubernetes + # ports: + # - 18080 logstash: build: ./module/logstash/_meta + ports: + - 9600 memcached: build: ./module/memcached/_meta + ports: + - 11211 mongodb: build: ./module/mongodb/_meta command: mongod --replSet beats + ports: + - 27017 munin: build: ./module/munin/_meta + ports: + - 4949 mysql: build: context: ./module/mysql/_meta args: MYSQL_IMAGE: mysql:5.7.24 + ports: + - 3306 mysql_8_0: build: context: ./module/mysql/_meta args: MYSQL_IMAGE: mysql:8.0.13 + ports: + - 3306 percona_5_7: build: context: ./module/mysql/_meta args: MYSQL_IMAGE: percona:5.7.24 + ports: + - 3306 percona_8_0: build: context: ./module/mysql/_meta args: MYSQL_IMAGE: percona:8.0.13-4 + ports: + - 3306 mariadb_10_2: build: context: ./module/mysql/_meta args: MYSQL_IMAGE: mariadb:10.2.23 + ports: + - 3306 mariadb_10_3: build: context: ./module/mysql/_meta args: MYSQL_IMAGE: mariadb:10.3.14 + ports: + - 3306 mariadb_10_4: build: @@ -226,47 +304,73 @@ services: nats: build: ./module/nats/_meta + ports: + - 8222 nginx: build: ./module/nginx/_meta + ports: + - 80 phpfpm: build: ./module/php_fpm/_meta + ports: + - 81 postgresql: build: ./module/postgresql/_meta + ports: + - 5432 prometheus: build: ./module/prometheus/_meta + ports: + - 9090 rabbitmq: build: ./module/rabbitmq/_meta + ports: + - 15672 redis: build: ./module/redis/_meta + ports: + - 6379 redis_4: build: context: ./module/redis/_meta args: REDIS_VERSION: 4.0.11 + ports: + - 6379 redis_5: build: context: ./module/redis/_meta args: REDIS_VERSION: 5.0-rc4 + ports: + - 6379 traefik: build: ./module/traefik/_meta + ports: + - 8080 uwsgi_tcp: build: ./module/uwsgi/_meta command: uwsgi --http :8080 --master --processes 1 --threads 2 --stats 0.0.0.0:9191 --memory-report --wsgi-file app.py + ports: + - 9191 uwsgi_http: build: ./module/uwsgi/_meta command: uwsgi --http :8080 --master --processes 1 --threads 2 --stats 0.0.0.0:9192 --memory-report --stats-http --wsgi-file app.py + ports: + - 9192 zookeeper: build: ./module/zookeeper/_meta + ports: + - 2181 diff --git a/metricbeat/module/elasticsearch/test_elasticsearch.py b/metricbeat/module/elasticsearch/test_elasticsearch.py index 2a4ea48195ba..50c337ae91cd 100644 --- a/metricbeat/module/elasticsearch/test_elasticsearch.py +++ b/metricbeat/module/elasticsearch/test_elasticsearch.py @@ -47,10 +47,6 @@ def test_metricsets(self, metricset): self.check_metricset("elasticsearch", metricset, self.get_hosts(), self.FIELDS + ["service"], extras={"index_recovery.active_only": "false"}) - def get_hosts(self): - return [os.getenv('ES_HOST', 'localhost') + ':' + - os.getenv('ES_PORT', '9200')] - def create_ml_job(self, es): es_version = self.get_version(es) if es_version["major"] < 7: diff --git a/metricbeat/module/etcd/test_etcd.py b/metricbeat/module/etcd/test_etcd.py index f1bbc2ff4ff5..33c5420e0a25 100644 --- a/metricbeat/module/etcd/test_etcd.py +++ b/metricbeat/module/etcd/test_etcd.py @@ -25,10 +25,6 @@ def test_metricset(self, metricset): """ self.check_metricset("etcd", metricset, self.get_hosts(), ['etcd.' + metricset]) - def get_hosts(self): - return [self.compose_hosts()[0] + ':' + - os.getenv('ETCD_PORT', '2379')] - class Test_3_2(Test): COMPOSE_SERVICES = ['etcd_3_2'] diff --git a/metricbeat/module/kafka/_meta/Dockerfile b/metricbeat/module/kafka/_meta/Dockerfile index 13ef0839187a..6e91a79d6145 100644 --- a/metricbeat/module/kafka/_meta/Dockerfile +++ b/metricbeat/module/kafka/_meta/Dockerfile @@ -3,7 +3,7 @@ FROM debian:stretch ARG KAFKA_VERSION=2.1.1 ENV KAFKA_HOME /kafka -# The advertised host is kafka. This means it will not work if container is started locally and connected from localhost to it + ENV KAFKA_LOGS_DIR="/kafka-logs" ENV _JAVA_OPTIONS "-Djava.net.preferIPv4Stack=true" ENV TERM=linux diff --git a/metricbeat/module/kafka/_meta/run.sh b/metricbeat/module/kafka/_meta/run.sh index 36b42a6a0d5d..c6fd44deb0f0 100755 --- a/metricbeat/module/kafka/_meta/run.sh +++ b/metricbeat/module/kafka/_meta/run.sh @@ -1,6 +1,6 @@ #!/bin/bash -KAFKA_ADVERTISED_HOST=$(dig +short $HOSTNAME) +KAFKA_ADVERTISED_HOST=$(dig +short $HOSTNAME):9092 wait_for_port() { count=20 @@ -21,8 +21,11 @@ wait_for_port 2181 echo "Starting Kafka broker" mkdir -p ${KAFKA_LOGS_DIR} ${KAFKA_HOME}/bin/kafka-server-start.sh ${KAFKA_HOME}/config/server.properties \ - --override delete.topic.enable=true --override advertised.host.name=${KAFKA_ADVERTISED_HOST} \ - --override listeners=PLAINTEXT://0.0.0.0:9092 \ + --override delete.topic.enable=true \ + --override listeners=INSIDE://localhost:9091,OUTSIDE://0.0.0.0:9092 \ + --override advertised.listeners=INSIDE://localhost:9091,OUTSIDE://$KAFKA_ADVERTISED_HOST \ + --override listener.security.protocol.map=INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT \ + --override inter.broker.listener.name=INSIDE \ --override logs.dir=${KAFKA_LOGS_DIR} & wait_for_port 9092 diff --git a/metricbeat/module/traefik/test_traefik.py b/metricbeat/module/traefik/test_traefik.py index de8de5f8b847..cc2cfe667d44 100644 --- a/metricbeat/module/traefik/test_traefik.py +++ b/metricbeat/module/traefik/test_traefik.py @@ -23,7 +23,3 @@ def test_health(self, metricset): traefik metricset tests """ self.check_metricset("traefik", metricset, self.get_hosts(), self.FIELDS + ["service.name"]) - - def get_hosts(self): - return [os.getenv('TRAEFIK_HOST', 'localhost') + ':' + - os.getenv('TRAEFIK_API_PORT', '8080')] diff --git a/metricbeat/tests/system/test_aerospike.py b/metricbeat/tests/system/test_aerospike.py index 3f957e15885c..201755e11b5c 100644 --- a/metricbeat/tests/system/test_aerospike.py +++ b/metricbeat/tests/system/test_aerospike.py @@ -14,7 +14,3 @@ def test_namespace(self): aerospike namespace metricset test """ self.check_metricset("aerospike", "namespace", self.get_hosts(), self.FIELDS) - - def get_hosts(self): - return [os.getenv('AEROSPIKE_HOST', 'localhost') + ':' + - os.getenv('AEROSPIKE_PORT', '3000')] diff --git a/metricbeat/tests/system/test_apache.py b/metricbeat/tests/system/test_apache.py index fd1645181201..41fa7b313003 100644 --- a/metricbeat/tests/system/test_apache.py +++ b/metricbeat/tests/system/test_apache.py @@ -78,8 +78,7 @@ def verify_fields(self, evt): # There are more fields that could be checked. def get_hosts(self): - return ['http://' + os.getenv('APACHE_HOST', 'localhost') + ':' + - os.getenv('APACHE_PORT', '80')] + return ['http://' + self.compose_host()] class ApacheOldStatusTest(ApacheStatusTest): @@ -91,7 +90,3 @@ def verify_fields(self, evt): apache_status = evt["apache"]["status"] self.assertItemsEqual( self.de_dot(APACHE_OLD_STATUS_FIELDS), apache_status.keys()) - - def get_hosts(self): - return ['http://' + os.getenv('APACHE_OLD_HOST', 'localhost') + ':' + - os.getenv('APACHE_PORT', '80')] diff --git a/metricbeat/tests/system/test_base.py b/metricbeat/tests/system/test_base.py index be48ff074a46..51ce487acbec 100644 --- a/metricbeat/tests/system/test_base.py +++ b/metricbeat/tests/system/test_base.py @@ -97,3 +97,12 @@ def test_migration(self): assert exit_code == 0 assert self.log_contains('Loaded index template') assert len(es.cat.templates(name='metricbeat-*', h='name')) > 0 + + def get_elasticsearch_url(self): + return "http://" + self.compose_host("elasticsearch") + + def get_kibana_url(self): + """ + Returns kibana host URL + """ + return "http://" + self.compose_host("kibana") diff --git a/metricbeat/tests/system/test_ceph.py b/metricbeat/tests/system/test_ceph.py index 2e5d91c2e273..3ae9076f492e 100644 --- a/metricbeat/tests/system/test_ceph.py +++ b/metricbeat/tests/system/test_ceph.py @@ -22,7 +22,3 @@ def test_ceph(self, metricset): ceph metricsets tests """ self.check_metricset("ceph", metricset, self.get_hosts(), self.FIELDS) - - def get_hosts(self): - return [os.getenv('CEPH_HOST', 'localhost') + ':' + - os.getenv('CEPH_PORT', '5000')] diff --git a/metricbeat/tests/system/test_consul.py b/metricbeat/tests/system/test_consul.py index 374ec6b8fe1e..025aefb054e3 100644 --- a/metricbeat/tests/system/test_consul.py +++ b/metricbeat/tests/system/test_consul.py @@ -55,7 +55,3 @@ def test_output(self): assert(consul_agent["runtime"]["heap_objects"] > 0) self.assert_fields_are_documented(evt) - - def get_hosts(self): - return [os.getenv('CONSUL_HOST', 'localhost') + ':' + - os.getenv('CONSUL_PORT', '8500')] diff --git a/metricbeat/tests/system/test_coredns.py b/metricbeat/tests/system/test_coredns.py index ac3a03d4328a..8a71c1c72b3e 100644 --- a/metricbeat/tests/system/test_coredns.py +++ b/metricbeat/tests/system/test_coredns.py @@ -31,9 +31,3 @@ def test_stats(self): for evt in output: self.assert_fields_are_documented(evt) self.assertItemsEqual(self.de_dot(COREDNS_FIELDS), evt.keys(), evt) - - def get_hosts(self): - return ["{}:{}".format( - os.getenv('COREDNS_HOST', 'localhost'), - os.getenv('COREDNS_PORT', '9153') - )] diff --git a/metricbeat/tests/system/test_couchbase.py b/metricbeat/tests/system/test_couchbase.py index f0d757803590..ad1326eef234 100644 --- a/metricbeat/tests/system/test_couchbase.py +++ b/metricbeat/tests/system/test_couchbase.py @@ -20,7 +20,3 @@ def test_couchbase(self, metricset): couchbase metricsets tests """ self.check_metricset("couchbase", metricset, self.get_hosts(), self.FIELDS) - - def get_hosts(self): - return [os.getenv('COUCHBASE_HOST', 'localhost') + ':' + - os.getenv('COUCHBASE_PORT', '8091')] diff --git a/metricbeat/tests/system/test_couchdb.py b/metricbeat/tests/system/test_couchdb.py index ddf6b459307f..2e5f817924a8 100644 --- a/metricbeat/tests/system/test_couchdb.py +++ b/metricbeat/tests/system/test_couchdb.py @@ -31,7 +31,3 @@ def test_stats(self): self.assertNotIn("error", event) self.assert_fields_are_documented(event) - - def get_hosts(self): - return [os.getenv('COUCHDB_HOST', 'localhost') + ':' + - os.getenv('COUCHDB_PORT', '5984')] diff --git a/metricbeat/tests/system/test_dropwizard.py b/metricbeat/tests/system/test_dropwizard.py index a9ab7dbbe8de..763231b054d2 100644 --- a/metricbeat/tests/system/test_dropwizard.py +++ b/metricbeat/tests/system/test_dropwizard.py @@ -28,7 +28,3 @@ def test_dropwizard(self): output = self.read_output_json() self.assertTrue(len(output) >= 1) - - def get_hosts(self): - return [os.getenv('DROPWIZARD_HOST', 'localhost') + ':' + - os.getenv('DROPWIZARD_PORT', '8080')] diff --git a/metricbeat/tests/system/test_envoyproxy.py b/metricbeat/tests/system/test_envoyproxy.py index 40b7bce1a139..f979e1f2f216 100644 --- a/metricbeat/tests/system/test_envoyproxy.py +++ b/metricbeat/tests/system/test_envoyproxy.py @@ -29,7 +29,3 @@ def test_stats(self): print(evt) self.assert_fields_are_documented(evt) - - def get_hosts(self): - return [os.getenv('ENVOYPROXY_HOST', 'localhost') + ':' + - os.getenv('ENVOYPROXY_PORT', '9901')] diff --git a/metricbeat/tests/system/test_haproxy.py b/metricbeat/tests/system/test_haproxy.py index cf3510db71cb..1618982959ab 100644 --- a/metricbeat/tests/system/test_haproxy.py +++ b/metricbeat/tests/system/test_haproxy.py @@ -32,7 +32,7 @@ def test_info_socket(self): self.render_config_template(modules=[{ "name": "haproxy", "metricsets": ["info"], - "hosts": ["tcp://%s:%d" % (self.compose_hosts()[0], 14567)], + "hosts": ["tcp://%s" % (self.compose_host(port="14567/tcp"))], "period": "5s" }]) self._test_info() @@ -59,7 +59,7 @@ def test_stat_socket(self): self.render_config_template(modules=[{ "name": "haproxy", "metricsets": ["stat"], - "hosts": ["tcp://%s:%d" % (self.compose_hosts()[0], 14567)], + "hosts": ["tcp://%s" % (self.compose_host(port="14567/tcp"))], "period": "5s" }]) self._test_stat() @@ -72,7 +72,7 @@ def test_stat_http(self): self.render_config_template(modules=[{ "name": "haproxy", "metricsets": ["stat"], - "hosts": ["http://%s:%d/stats" % (self.compose_hosts()[0], 14568)], + "hosts": ["http://%s/stats" % (self.compose_host(port="14568/tcp"))], "period": "5s" }]) self._test_stat() @@ -87,7 +87,7 @@ def test_stat_http_auth(self): "metricsets": ["stat"], "username": "admin", "password": "admin", - "hosts": ["http://%s:%d/stats" % (self.compose_hosts()[0], 14569)], + "hosts": ["http://%s/stats" % (self.compose_host(port="14569/tcp"))], "period": "5s" }]) self._test_stat() diff --git a/metricbeat/tests/system/test_http.py b/metricbeat/tests/system/test_http.py index 1fd645733b7c..51a4bf2cc707 100644 --- a/metricbeat/tests/system/test_http.py +++ b/metricbeat/tests/system/test_http.py @@ -75,4 +75,4 @@ def test_server(self): self.assert_fields_are_documented(evt) def get_host(self): - return "http://" + os.getenv('HTTP_HOST', 'localhost') + ':' + os.getenv('HTTP_PORT', '8080') + return "http://" + self.compose_host() diff --git a/metricbeat/tests/system/test_jolokia.py b/metricbeat/tests/system/test_jolokia.py index 921ee5aef254..a1e1c530d227 100644 --- a/metricbeat/tests/system/test_jolokia.py +++ b/metricbeat/tests/system/test_jolokia.py @@ -48,7 +48,3 @@ def test_jmx(self, mbean): print(evt) assert evt["jolokia"]["test"]["gc"]["collection_count"] >= 0 - - def get_hosts(self): - return [os.getenv('JOLOKIA_HOST', 'localhost') + ':' + - os.getenv('JOLOKIA_PORT', '8778')] diff --git a/metricbeat/tests/system/test_kafka.py b/metricbeat/tests/system/test_kafka.py index a7ba2d26e288..a5f0bfacbb10 100644 --- a/metricbeat/tests/system/test_kafka.py +++ b/metricbeat/tests/system/test_kafka.py @@ -42,10 +42,6 @@ def create_topic(self): retries=20, retry_backoff_ms=500) producer.send('foobar', b'some_message_bytes') - def get_hosts(self): - return [self.compose_hosts()[0] + ':' + - os.getenv('KAFKA_PORT', '9092')] - class Kafka_1_1_0_Test(KafkaTest): COMPOSE_SERVICES = ['kafka_1_1_0'] diff --git a/metricbeat/tests/system/test_kibana.py b/metricbeat/tests/system/test_kibana.py index fbb7a5736d27..33f6f376c1be 100644 --- a/metricbeat/tests/system/test_kibana.py +++ b/metricbeat/tests/system/test_kibana.py @@ -48,8 +48,7 @@ def test_status(self): self.assert_fields_are_documented(evt) def get_hosts(self): - return [os.getenv('KIBANA_HOST', 'localhost') + ':' + - os.getenv('KIBANA_PORT', '5601')] + return [self.compose_host("kibana")] def get_version(self): host = self.get_hosts()[0] diff --git a/metricbeat/tests/system/test_kubernetes.py b/metricbeat/tests/system/test_kubernetes.py index 6ede3cfe30c9..5c469bc3902e 100644 --- a/metricbeat/tests/system/test_kubernetes.py +++ b/metricbeat/tests/system/test_kubernetes.py @@ -77,16 +77,8 @@ def _test_metricset(self, metricset, expected_events, hosts): @classmethod def get_kubelet_hosts(cls): - return [ - "http://" + - os.getenv('KUBELET_HOST', 'localhost') + ':' + - os.getenv('KUBELET_PORT', '10255') - ] + return [self.compose_host("kubernetes")] @classmethod def get_kube_state_hosts(cls): - return [ - "http://" + - os.getenv('KUBE_STATE_METRICS_HOST', 'localhost') + ':' + - os.getenv('KUBE_STATE_METRICS_PORT', '18080') - ] + return [self.compose_host("kubestate")] diff --git a/metricbeat/tests/system/test_logstash.py b/metricbeat/tests/system/test_logstash.py index 8280bfb0223a..f9f4f6e6c999 100644 --- a/metricbeat/tests/system/test_logstash.py +++ b/metricbeat/tests/system/test_logstash.py @@ -53,7 +53,3 @@ def test_node_stats(self): print(evt) self.assert_fields_are_documented(evt) - - def get_hosts(self): - return [os.getenv('LOGSTASH_HOST', 'localhost') + ':' + - os.getenv('LOGSTASH_PORT', '9600')] diff --git a/metricbeat/tests/system/test_memcached.py b/metricbeat/tests/system/test_memcached.py index ede980b0581c..7d2bf31f0fea 100644 --- a/metricbeat/tests/system/test_memcached.py +++ b/metricbeat/tests/system/test_memcached.py @@ -29,7 +29,3 @@ def test_stats(self): print(evt) self.assert_fields_are_documented(evt) - - def get_hosts(self): - return [os.getenv('MEMCACHED_HOST', 'localhost') + ':' + - os.getenv('MEMCACHED_PORT', '11211')] diff --git a/metricbeat/tests/system/test_mongodb.py b/metricbeat/tests/system/test_mongodb.py index 4400d1c95b8b..e20e37758914 100644 --- a/metricbeat/tests/system/test_mongodb.py +++ b/metricbeat/tests/system/test_mongodb.py @@ -34,7 +34,3 @@ def test_status(self): self.assertItemsEqual(self.de_dot(MONGODB_FIELDS + ["process"]), evt.keys()) self.assert_fields_are_documented(evt) - - def get_hosts(self): - return [os.getenv('MONGODB_HOST', 'localhost') + ':' + - os.getenv('MONGODB_PORT', '27017')] diff --git a/metricbeat/tests/system/test_munin.py b/metricbeat/tests/system/test_munin.py index 63cc80a94ff4..ae3bfdf8e35e 100644 --- a/metricbeat/tests/system/test_munin.py +++ b/metricbeat/tests/system/test_munin.py @@ -36,7 +36,3 @@ def test_munin_node(self): assert evt["munin"]["metrics"]["user"] > 0 self.assert_fields_are_documented(evt) - - def get_hosts(self): - return [self.compose_hosts()[0] + ':' + - os.getenv('MUNIN_PORT', '4949')] diff --git a/metricbeat/tests/system/test_mysql.py b/metricbeat/tests/system/test_mysql.py index 105ceaa9441b..fc89378b834a 100644 --- a/metricbeat/tests/system/test_mysql.py +++ b/metricbeat/tests/system/test_mysql.py @@ -43,7 +43,7 @@ def test_status(self): self.assert_fields_are_documented(evt) def get_hosts(self): - return ['root:test@tcp({}:3306)/'.format(self.compose_hosts()[0])] + return ['root:test@tcp({})/'.format(self.compose_host())] class TestMysql80(Test): diff --git a/metricbeat/tests/system/test_nats.py b/metricbeat/tests/system/test_nats.py index d2f5bb6d8efb..1254a6c12ecc 100644 --- a/metricbeat/tests/system/test_nats.py +++ b/metricbeat/tests/system/test_nats.py @@ -108,9 +108,3 @@ def test_subscriptions(self): self.assertItemsEqual(self.de_dot(NATS_FIELDS), evt.keys(), evt) self.assert_fields_are_documented(evt) - - def get_hosts(self): - return ["{}:{}".format( - os.getenv('NATS_HOST', 'localhost'), - os.getenv('NATS_PORT', '8222') - )] diff --git a/metricbeat/tests/system/test_phpfpm.py b/metricbeat/tests/system/test_phpfpm.py index edb5405a404d..8b3cf804e67f 100644 --- a/metricbeat/tests/system/test_phpfpm.py +++ b/metricbeat/tests/system/test_phpfpm.py @@ -32,7 +32,3 @@ def test_info(self): self.assertItemsEqual(self.de_dot(PHPFPM_FIELDS), evt.keys(), evt) self.assert_fields_are_documented(evt) - - def get_hosts(self): - return [os.getenv('PHPFPM_HOST', 'localhost') + ':' + - os.getenv('PHPFPM_PORT', '81')] diff --git a/metricbeat/tests/system/test_postgresql.py b/metricbeat/tests/system/test_postgresql.py index 5150d9ab28b1..43a8db4a3858 100644 --- a/metricbeat/tests/system/test_postgresql.py +++ b/metricbeat/tests/system/test_postgresql.py @@ -19,8 +19,14 @@ def common_checks(self, output): self.assert_fields_are_documented(evt) def get_hosts(self): - return [os.getenv("POSTGRESQL_DSN")], os.getenv("POSTGRESQL_USERNAME"), \ - os.getenv("POSTGRESQL_PASSWORD") + username = "postgres" + host = self.compose_host() + dsn = "postgres://{}?sslmode=disable".format(host) + return ( + [dsn], + username, + os.getenv("POSTGRESQL_PASSWORD"), + ) @unittest.skipUnless(metricbeat.INTEGRATION_TESTS, "integration test") @attr('integration') diff --git a/metricbeat/tests/system/test_prometheus.py b/metricbeat/tests/system/test_prometheus.py index 07fec23705e0..34f3278b76f7 100644 --- a/metricbeat/tests/system/test_prometheus.py +++ b/metricbeat/tests/system/test_prometheus.py @@ -31,7 +31,3 @@ def test_stats(self): self.assertItemsEqual(self.de_dot(PROMETHEUS_FIELDS), evt.keys(), evt) self.assert_fields_are_documented(evt) - - def get_hosts(self): - return ["http://" + os.getenv('PROMETHEUS_HOST', 'localhost') + ':' + - os.getenv('PROMETHEUS_PORT', '9090')] diff --git a/metricbeat/tests/system/test_redis.py b/metricbeat/tests/system/test_redis.py index 61e9fd1e56bf..2f65c4ef081c 100644 --- a/metricbeat/tests/system/test_redis.py +++ b/metricbeat/tests/system/test_redis.py @@ -60,9 +60,10 @@ def test_keyspace(self): """ # At least one event must be inserted so db stats exist + host, port = self.compose_host().split(":") r = redis.StrictRedis( - host=self.get_host(), - port=os.getenv('REDIS_PORT', '6379'), + host=host, + port=port, db=0) r.flushall() r.set('foo', 'bar') @@ -95,9 +96,10 @@ def test_key(self): """ # At least one event must be inserted so db stats exist + host, port = self.compose_host().split(":") r = redis.StrictRedis( - host=self.get_host(), - port=os.getenv('REDIS_PORT', '6379'), + host=host, + port=port, db=0) r.flushall() r.rpush('list-key', 'one', 'two', 'three') @@ -158,15 +160,6 @@ def test_module_processors(self): self.assertItemsEqual(self.de_dot(CLIENTS_FIELDS), redis_info["clients"].keys()) self.assertItemsEqual(self.de_dot(CPU_FIELDS), redis_info["cpu"].keys()) - def get_hosts(self): - return [self.get_host() + ':' + - os.getenv('REDIS_PORT', '6379')] - - def get_host(self): - if len(self.compose_hosts()) > 0: - return self.compose_hosts()[0] - return "localhost" - class TestRedis4(Test): COMPOSE_SERVICES = ['redis_4'] diff --git a/metricbeat/tests/system/test_uwsgi.py b/metricbeat/tests/system/test_uwsgi.py index 3707d2cab862..a35576fb85e4 100644 --- a/metricbeat/tests/system/test_uwsgi.py +++ b/metricbeat/tests/system/test_uwsgi.py @@ -8,8 +8,7 @@ class Test(metricbeat.BaseTest): - - COMPOSE_SERVICES = ['uwsgi_tcp', "uwsgi_http"] + COMPOSE_SERVICES = ['uwsgi_tcp'] def common_checks(self, output): # Ensure no errors or warnings exist in the log. @@ -51,15 +50,14 @@ def common_checks(self, output): @unittest.skipUnless(metricbeat.INTEGRATION_TESTS, "integration test") @attr('integration') - def test_status_tcp(self): + def test_status(self): """ uWSGI module outputs an event. """ - hosts = [os.getenv("UWSGI_STAT_TCP_SERVER")] self.render_config_template(modules=[{ "name": "uwsgi", "metricsets": ["status"], - "hosts": hosts, + "hosts": [self.get_host()], "period": "5s" }]) proc = self.start_beat() @@ -69,22 +67,12 @@ def test_status_tcp(self): output = self.read_output_json() self.common_checks(output) - @unittest.skipUnless(metricbeat.INTEGRATION_TESTS, "integration test") - @attr('integration') - def test_status_http(self): - """ - uWSGI module outputs an event. - """ - hosts = [os.getenv("UWSGI_STAT_HTTP_SERVER")] - self.render_config_template(modules=[{ - "name": "uwsgi", - "metricsets": ["status"], - "hosts": hosts, - "period": "5s" - }]) - proc = self.start_beat() - self.wait_until(lambda: self.output_lines() > 0) - proc.check_kill_and_wait() + def get_host(self): + return "tcp://" + self.compose_host() - output = self.read_output_json() - self.common_checks(output) + +class TestHTTP(Test): + COMPOSE_SERVICES = ['uwsgi_http'] + + def get_host(self): + return "http://" + self.compose_host() diff --git a/metricbeat/tests/system/test_zookeeper.py b/metricbeat/tests/system/test_zookeeper.py index 5aebfae35e49..ae7e21a8b50d 100644 --- a/metricbeat/tests/system/test_zookeeper.py +++ b/metricbeat/tests/system/test_zookeeper.py @@ -105,7 +105,3 @@ def test_connection(self): assert zk_conns["queued"] >= 0 self.assert_fields_are_documented(evt) - - def get_hosts(self): - return [os.getenv('ZOOKEEPER_HOST', 'localhost') + ':' + - os.getenv('ZOOKEEPER_PORT', '2181')] diff --git a/x-pack/metricbeat/docker-compose.yml b/x-pack/metricbeat/docker-compose.yml index bec53d09468e..0a6e217d31c5 100644 --- a/x-pack/metricbeat/docker-compose.yml +++ b/x-pack/metricbeat/docker-compose.yml @@ -15,3 +15,5 @@ services: # Modules mssql: build: ./module/mssql/_meta + ports: + - 1433 diff --git a/x-pack/metricbeat/tests/system/test_mssql.py b/x-pack/metricbeat/tests/system/test_mssql.py index 963177b718c1..b68b866308dd 100644 --- a/x-pack/metricbeat/tests/system/test_mssql.py +++ b/x-pack/metricbeat/tests/system/test_mssql.py @@ -74,9 +74,6 @@ def test_performance(self): self.assert_fields_are_documented(evt) - def get_hosts(self): - return [os.getenv('MSSQL_HOST', 'mssql')] - def get_username(self): return os.getenv('MSSQL_USERNAME', 'SA')