Skip to content
This repository was archived by the owner on Jan 23, 2024. It is now read-only.

Commit 0fad963

Browse files
authored
enable apm-server self profiling by default (#686)
1 parent e53ce47 commit 0fad963

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

scripts/modules/elastic_stack.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,13 @@ def __init__(self, **options):
5252
("monitoring.elasticsearch" if self.at_least_version("7.2") else "xpack.monitoring.elasticsearch", "true"),
5353
("monitoring.enabled" if self.at_least_version("7.2") else "xpack.monitoring.enabled", "true")
5454
])
55-
if options.get("apm_server_self_instrument"):
55+
if options.get("apm_server_self_instrument", True):
5656
self.apm_server_command_args.append(("apm-server.instrumentation.enabled", "true"))
57+
if self.at_least_version("7.6") and options.get("apm_server_profile", True):
58+
self.apm_server_command_args.extend([
59+
("apm-server.instrumentation.profiling.cpu.enabled", "true"),
60+
("apm-server.instrumentation.profiling.heap.enabled", "true"),
61+
])
5762
self.depends_on = {"elasticsearch": {"condition": "service_healthy"}} if options.get(
5863
"enable_elasticsearch", True) else {}
5964
self.build = self.options.get("apm_server_build")
@@ -237,6 +242,11 @@ def add_arguments(cls, parser):
237242
dest="apm_server_self_instrument",
238243
help='disable apm-server self instrumentation.'
239244
)
245+
parser.add_argument(
246+
"--no-apm-server-profile",
247+
action="store_false",
248+
help='disable apm-server self instrumentation profiling.'
249+
)
240250
parser.add_argument(
241251
'--apm-server-count',
242252
type=int,

scripts/tests/service_tests.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,29 @@ def test_queue_mem(self):
588588
"no queue settings with memory queue (for now)"
589589
)
590590

591+
def test_self_instrument(self):
592+
# self instrumentation comes with profiling by default
593+
apm_server = ApmServer(version="8.0.0").render()["apm-server"]
594+
self.assertIn("apm-server.instrumentation.enabled=true", apm_server["command"])
595+
self.assertIn("apm-server.instrumentation.profiling.cpu.enabled=true", apm_server["command"])
596+
self.assertIn("apm-server.instrumentation.profiling.heap.enabled=true", apm_server["command"])
597+
598+
# self instrumentation comes with profiling by default but can be disabled
599+
apm_server = ApmServer(
600+
version="8.0.0", apm_server_self_instrument=True, apm_server_profile=False).render()["apm-server"]
601+
self.assertIn("apm-server.instrumentation.enabled=true", apm_server["command"])
602+
self.assertFalse(
603+
any(e.startswith("apm-server.instrumentation.profiling") for e in apm_server["command"]),
604+
"no self profiling settings expected"
605+
)
606+
607+
# need self instrumentation enabled to get profiling
608+
apm_server = ApmServer(
609+
version="8.0.0", apm_server_self_instrument=False, apm_server_profile=True).render()["apm-server"]
610+
self.assertNotIn("apm-server.instrumentation.enabled=true", apm_server["command"])
611+
self.assertNotIn("apm-server.instrumentation.profiling.cpu.enabled=true", apm_server["command"])
612+
self.assertNotIn("apm-server.instrumentation.profiling.heap.enabled=true", apm_server["command"])
613+
591614
def test_apm_server_build_branch(self):
592615
apm_server = ApmServer(version="6.3.100", apm_server_build="foo.git@bar", release=True).render()["apm-server"]
593616
self.assertIsNone(apm_server.get("image"))

0 commit comments

Comments
 (0)