diff --git a/scripts/modules/elastic_stack.py b/scripts/modules/elastic_stack.py index 37d08760e..d11291ffa 100644 --- a/scripts/modules/elastic_stack.py +++ b/scripts/modules/elastic_stack.py @@ -67,6 +67,7 @@ def __init__(self, **options): elif self.at_least_version("7.3"): self.apm_server_command_args.extend([ ("apm-server.kibana.enabled", "true"), + ("apm-server.agent.config.cache.expiration", "1s"), ("apm-server.kibana.host", self.DEFAULT_KIBANA_HOST)]) if self.options.get("enable_kibana", True): diff --git a/scripts/tests/localsetup_tests.py b/scripts/tests/localsetup_tests.py index de674bdcc..bf7fa528d 100644 --- a/scripts/tests/localsetup_tests.py +++ b/scripts/tests/localsetup_tests.py @@ -818,7 +818,7 @@ def test_start_master_default(self): -E, 'setup.kibana.host=kibana:5601', -E, setup.template.settings.index.number_of_replicas=0, -E, setup.template.settings.index.number_of_shards=1, -E, setup.template.settings.index.refresh_interval=1ms, -E, monitoring.elasticsearch=true, -E, monitoring.enabled=true, - -E, apm-server.kibana.enabled=true, -E, 'apm-server.kibana.host=kibana:5601', + -E, apm-server.kibana.enabled=true, -E, apm-server.agent.config.cache.expiration=1s, -E, 'apm-server.kibana.host=kibana:5601', -E, 'output.elasticsearch.hosts=["elasticsearch:9200"]', -E, output.elasticsearch.enabled=true, -E, "output.elasticsearch.pipelines=[{pipeline: 'apm'}]", -E, 'apm-server.register.ingest.pipeline.enabled=true' ] diff --git a/scripts/tests/service_tests.py b/scripts/tests/service_tests.py index 4bdbbf370..619442116 100644 --- a/scripts/tests/service_tests.py +++ b/scripts/tests/service_tests.py @@ -662,7 +662,7 @@ def test_dashboards(self): def test_apm_server_acm(self): apm_server = ApmServer(version="7.3").render()["apm-server"] self.assertTrue("apm-server.kibana.enabled=true" in apm_server["command"], - "APM Server Kbana enabled by default") + "APM Server Kibana enabled by default") self.assertTrue("apm-server.kibana.host=kibana:5601" in apm_server["command"], "APM Server Kibana host set by default") diff --git a/tests/agent/__init__.py b/tests/agent/__init__.py index e69de29bb..b09b9b1c2 100644 --- a/tests/agent/__init__.py +++ b/tests/agent/__init__.py @@ -0,0 +1,48 @@ +from contextlib import contextmanager +import requests +import time +from urllib.parse import urljoin + +from tests.fixtures import default + + +@contextmanager +def remote_config(kibana_url, sampling_rate=1.0): + def data(sample_rate): + return { + "agent_name": "python", + "service": {"name": default.from_env('FLASK_SERVICE_NAME')}, + "settings": {"transaction_sample_rate": sample_rate} + } + + headers = {"Content-Type": "application/json", "kbn-xsrf": "1"} + wait = 1.5 # just higher than apm-server.agent.config.cache.expiration + + try: + r = requests.post( + urljoin(kibana_url, "/api/apm/settings/agent-configuration/new"), + headers=headers, + json=data(sampling_rate), + ) + r.raise_for_status() + config_id = r.json()["_id"] + time.sleep(wait) # give enough time to agent to pick up the config + + yield config_id + + finally: + # revert to original + r2 = requests.put( + urljoin(kibana_url, "/api/apm/settings/agent-configuration/" + config_id), + headers=headers, + json=data(1.0), + ) + r2.raise_for_status() + time.sleep(wait) + + r3 = requests.delete( + urljoin(kibana_url, "/api/apm/settings/agent-configuration/" + config_id), + headers=headers, + ) + r3.raise_for_status() + time.sleep(wait) diff --git a/tests/agent/test_python.py b/tests/agent/test_python.py index 4eabcbb93..f465b2007 100644 --- a/tests/agent/test_python.py +++ b/tests/agent/test_python.py @@ -1,6 +1,6 @@ import pytest -from tests import utils +from tests import utils, agent from tests.agent.concurrent_requests import Concurrent @@ -27,6 +27,15 @@ def test_concurrent_req_flask(flask): Concurrent(flask.apm_server.elasticsearch, [foo], iters=2).run() +@pytest.mark.version +@pytest.mark.flask +def test_req_flask_agent_config(flask, kibana): + with agent.remote_config(kibana.url, sampling_rate=0.0): + # 1 transaction, 0 spans + utils.check_agent_transaction( + flask.foo, flask.apm_server.elasticsearch, ct=1) + + @pytest.mark.version @pytest.mark.flask def test_concurrent_req_flask_foobar(flask):