Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests/system: basic smoke-test for monitoring #3111

Merged
merged 3 commits into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion tests/system/config/apm-server.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ apm-server:
api_key.limit: {{ api_key_limit | default(100) }}
{% endif %}
{% if api_key_es %}
api_key.elasticsearch.hosts: [{{ api_key_es}}]
api_key.elasticsearch.hosts: [{{ api_key_es }}]
{% endif %}

{% if max_event_size %}
Expand Down Expand Up @@ -185,6 +185,8 @@ output.file:
{% if elasticsearch_host %}
output.elasticsearch:
hosts: ["{{ elasticsearch_host }}"]
username: {{ elasticsearch_username }}
password: {{ elasticsearch_password }}

{% if override_index %}
index: {{ override_index }}
Expand Down Expand Up @@ -257,3 +259,15 @@ logging:
#keepfiles: 7

queue.mem.flush.min_events: {{ queue_flush }}

############################# X-pack Monitoring ###############################

{% if monitoring_enabled %}
monitoring.enabled: true
{% if monitoring_elasticsearch_username %}
monitoring.elasticsearch.username: {{ monitoring_elasticsearch_username }}
{% endif %}
{% if monitoring_elasticsearch_password %}
monitoring.elasticsearch.password: {{ monitoring_elasticsearch_password }}
{% endif %}
{% endif %}
46 changes: 46 additions & 0 deletions tests/system/test_monitoring.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from apmserver import integration_test
from apmserver import ElasticTest

import os
import urlparse

from elasticsearch import Elasticsearch


@integration_test
class Test(ElasticTest):
def config(self):
cfg = super(Test, self).config()

# Extract username/password from the URL, and store
# separately from elasticsearch_host. This is necessary
# because Beats will use the userinfo from the URL in
# preference to specified values.
url = urlparse.urlparse(cfg["elasticsearch_host"])
if url.username:
cfg["elasticsearch_username"] = url.username
if url.password:
cfg["elasticsearch_password"] = url.password
bare_netloc = url.netloc.split('@')[-1]
url = list(url)
url[1] = bare_netloc

# Set a password for the built-in apm_system user, and use that for monitoring.
monitoring_password = "changeme"
admin_user = os.getenv("ES_SUPERUSER_USER", "admin")
admin_password = os.getenv("ES_SUPERUSER_PASS", "changeme")
admin_es = Elasticsearch([self.get_elasticsearch_url(admin_user, admin_password)])
admin_es.xpack.security.change_password(username="apm_system",
body='{"password":"%s"}' % monitoring_password)
cfg.update({
"elasticsearch_host": urlparse.urlunparse(url),
"monitoring_enabled": "true",
"monitoring_elasticsearch_username": "apm_system",
"monitoring_elasticsearch_password": monitoring_password,
})
cfg.update(self.config_overrides)
return cfg

def test_connect(self):
goal_log = "Successfully connected to X-Pack Monitoring endpoint"
self.wait_until(lambda: self.log_contains(goal_log), name="apm-server connected to monitoring endpoint")