Support profiling queries in Tracer#90574
Conversation
| permission java.io.FilePermission "/proc/self/cgroup", "read"; | ||
| permission java.io.FilePermission "/sys/fs/cgroup/-", "read"; | ||
|
|
||
| // system memory on Linux systems affected by JDK bug (#66629) |
There was a problem hiding this comment.
spotted this old permission, no longer relevant since we have minimum Java > 17
| * Has to be declared as a header copied over for tasks. | ||
| */ | ||
| public static final String TRACE_ID = "trace.id"; | ||
| public static final String TRACE_PARENT = "traceparent"; |
There was a problem hiding this comment.
I hit this in my testing, added here to be in the headers allowlist
| permission java.lang.RuntimePermission "loadLibrary.*"; | ||
| permission java.lang.RuntimePermission "getClassLoader"; | ||
| permission java.io.FilePermission "<<ALL FILES>>", "read,write"; | ||
| permission org.elasticsearch.secure_sm.ThreadPermission "modifyArbitraryThreadGroup"; |
There was a problem hiding this comment.
added due to the following error:
2022-09-30 20:33:32,521 [elastic-apm-sampling-profiler] ERROR co.elastic.apm.agent.profiler.SamplingProfiler - Stopping profiler
java.security.AccessControlException: access denied ("org.elasticsearch.secure_sm.ThreadPermission" "modifyArbitraryThreadGroup")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:485) ~[?:?]
at java.security.AccessController.checkPermission(AccessController.java:1068) ~[?:?]
at java.lang.SecurityManager.checkPermission(SecurityManager.java:411) ~[?:?]
at org.elasticsearch.secure_sm.SecureSM.checkThreadGroupAccess(SecureSM.java:195) ~[elasticsearch-secure-sm-8.5.0-SNAPSHOT.jar:?]
at org.elasticsearch.secure_sm.SecureSM.checkAccess(SecureSM.java:135) ~[elasticsearch-secure-sm-8.5.0-SNAPSHOT.jar:?]
at java.lang.ThreadGroup.checkAccess(ThreadGroup.java:335) ~[?:?]
at java.lang.ThreadGroup.enumerate(ThreadGroup.java:441) ~[?:?]
at co.elastic.apm.agent.profiler.ThreadMatcher.forEachThread(ThreadMatcher.java:41) ~[?:?]
at co.elastic.apm.agent.profiler.SamplingProfiler.restoreFilterState(SamplingProfiler.java:433) ~[?:?]
at co.elastic.apm.agent.profiler.SamplingProfiler.profile(SamplingProfiler.java:402) ~[?:?]
at co.elastic.apm.agent.profiler.SamplingProfiler.run(SamplingProfiler.java:377) ~[?:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) ~[?:?]
at java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) ~[?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[?:?]
at java.lang.Thread.run(Thread.java:833) ~[?:?]
Required additionally permitting this to the "class permissions" for modules. In actuality, this permission is preventing the ProfilingSampler from doing ThreadGroup::enumerate in order to pass threads to async-profiler, not actually working to modify them. Anyway it doesn't seem so concerning as the already-permitted-for-modules <<ALL FILES>> | read,write so I've added it
|
Pinging @elastic/es-core-infra (Team:Core/Infra) |
pugnascotia
left a comment
There was a problem hiding this comment.
I wonder if we'll want to have a releasable startTrace at some point for the non-thread context case, but we can look at that in the future.
It's nice to avoid introducing too many constructors -- if we did this for all arguments, we could have a lot of "telescoping" going on. Follow up to #90574.
This pull request adds the necessary support, and implementation, for profiling queries in the Tracer.
In order to use the APM Agent's inferred spans functionality, the active span's context has to be open in the current thread. This PR adds context-sensitive methods to the Tracer interface, implements them in APMTracer, and makes use of them in the private
SearchService.executeQueryPhase(), which is on the stack for a lot of our most critical operations. Here is an example of the added functionality supported here (inferred spans in pink).