diff --git a/scripts/modules/elastic_stack.py b/scripts/modules/elastic_stack.py index a9b8ed417..ed20b4c34 100644 --- a/scripts/modules/elastic_stack.py +++ b/scripts/modules/elastic_stack.py @@ -52,8 +52,13 @@ def __init__(self, **options): ("monitoring.elasticsearch" if self.at_least_version("7.2") else "xpack.monitoring.elasticsearch", "true"), ("monitoring.enabled" if self.at_least_version("7.2") else "xpack.monitoring.enabled", "true") ]) - if options.get("apm_server_self_instrument"): + if options.get("apm_server_self_instrument", True): self.apm_server_command_args.append(("apm-server.instrumentation.enabled", "true")) + if self.at_least_version("7.6") and options.get("apm_server_profile", True): + self.apm_server_command_args.extend([ + ("apm-server.instrumentation.profiling.cpu.enabled", "true"), + ("apm-server.instrumentation.profiling.heap.enabled", "true"), + ]) self.depends_on = {"elasticsearch": {"condition": "service_healthy"}} if options.get( "enable_elasticsearch", True) else {} self.build = self.options.get("apm_server_build") @@ -237,6 +242,11 @@ def add_arguments(cls, parser): dest="apm_server_self_instrument", help='disable apm-server self instrumentation.' ) + parser.add_argument( + "--no-apm-server-profile", + action="store_false", + help='disable apm-server self instrumentation profiling.' + ) parser.add_argument( '--apm-server-count', type=int, diff --git a/scripts/tests/service_tests.py b/scripts/tests/service_tests.py index 28fb60008..2c867494b 100644 --- a/scripts/tests/service_tests.py +++ b/scripts/tests/service_tests.py @@ -588,6 +588,29 @@ def test_queue_mem(self): "no queue settings with memory queue (for now)" ) + def test_self_instrument(self): + # self instrumentation comes with profiling by default + apm_server = ApmServer(version="8.0.0").render()["apm-server"] + self.assertIn("apm-server.instrumentation.enabled=true", apm_server["command"]) + self.assertIn("apm-server.instrumentation.profiling.cpu.enabled=true", apm_server["command"]) + self.assertIn("apm-server.instrumentation.profiling.heap.enabled=true", apm_server["command"]) + + # self instrumentation comes with profiling by default but can be disabled + apm_server = ApmServer( + version="8.0.0", apm_server_self_instrument=True, apm_server_profile=False).render()["apm-server"] + self.assertIn("apm-server.instrumentation.enabled=true", apm_server["command"]) + self.assertFalse( + any(e.startswith("apm-server.instrumentation.profiling") for e in apm_server["command"]), + "no self profiling settings expected" + ) + + # need self instrumentation enabled to get profiling + apm_server = ApmServer( + version="8.0.0", apm_server_self_instrument=False, apm_server_profile=True).render()["apm-server"] + self.assertNotIn("apm-server.instrumentation.enabled=true", apm_server["command"]) + self.assertNotIn("apm-server.instrumentation.profiling.cpu.enabled=true", apm_server["command"]) + self.assertNotIn("apm-server.instrumentation.profiling.heap.enabled=true", apm_server["command"]) + def test_apm_server_build_branch(self): apm_server = ApmServer(version="6.3.100", apm_server_build="foo.git@bar", release=True).render()["apm-server"] self.assertIsNone(apm_server.get("image"))