-
Notifications
You must be signed in to change notification settings - Fork 325
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
Attacher improvements #1667
Attacher improvements #1667
Conversation
- Attaching to a VM running under a different user works now - Refactor discovery rules - Add user include/exclude rules
- The --list option only lists the main class name, without the JVM arguments - The -v option includes the JVM arguments - Remove deprecated --args option - Reduce risk of exposing sensitive data in heap dumps - Use ps-based java process discovery as the last resort as it can kill non-Java processes
Revert to compiling premain module with Java 7 instead of Java 6, as we're checking the Java version before attaching now.
Only the -cli module has a dependency on log4j and ecs logging The apm-agent-attach (aka attach API) doesn't contain the CLI app now.
Codecov Report
@@ Coverage Diff @@
## master #1667 +/- ##
============================================
+ Coverage 58.77% 62.73% +3.95%
- Complexity 92 3531 +3439
============================================
Files 403 364 -39
Lines 18475 17457 -1018
Branches 2570 2395 -175
============================================
+ Hits 10858 10951 +93
+ Misses 6847 5731 -1116
- Partials 770 775 +5
Continue to review full report at Codecov.
|
💚 Build Succeeded
Expand to view the summary
Build stats
Test stats 🧪
Trends 🧪💚 Flaky test reportTests succeeded. Expand to view the summary
Test stats 🧪
|
Seems to contradict
Given the number of changes here, breaking compatibility with the Also, most of the support cases we had in the past with What exactly would be the use-case of the attacher without bundled agent in practice ? Having them bundled together tends to simplify deployment and compatibility checks. |
That's outdated. I removed -p/--pid.
I think that this is the mode we'll be using when integrating APM Server. While we want to be able to update the Java agent independently from APM Server, there is a strong dependency between the UI, the server and the attacher-cli. These three components have to have a known set of features. If we were to implement a new type of include/exclude matcher in the attacher-cli in the future, we couldn't easily expose it in the UI if different versions of the attacher-cli may be used. So, we'd bundle the attacher-cli-slim into APM Server and download the agent jar on demand, based on what's configured in the Fleet UI. |
Note that there's still the non-slim version of the attacher-cli that does ship with a bundled agent jar. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, only few comments/questions.
Will definitely make attachment easier, thus a breaking change is welcome for once !
apm-agent-attach-cli/src/main/java/co/elastic/apm/attach/JvmDiscoverer.java
Show resolved
Hide resolved
apm-agent-attach-cli/src/main/java/co/elastic/apm/attach/UserRegistry.java
Show resolved
Hide resolved
apm-agent-attach-cli/src/main/java/co/elastic/apm/attach/JvmDiscoverer.java
Show resolved
Hide resolved
apm-agent-attach-cli/src/main/java/co/elastic/apm/attach/GetAgentProperties.java
Outdated
Show resolved
Hide resolved
apm-agent-attach-cli/src/main/java/co/elastic/apm/attach/GetAgentProperties.java
Show resolved
Hide resolved
apm-agent-attach-cli/src/main/java/co/elastic/apm/attach/AgentAttacher.java
Show resolved
Hide resolved
apm-agent-attach-cli/src/test/java/co/elastic/apm/attach/AgentAttacherTest.java
Show resolved
Hide resolved
...tion-tests/src/test/java/co/elastic/apm/servlet/AbstractServletContainerIntegrationTest.java
Show resolved
Hide resolved
apm-agent-attach-cli/src/test/java/co/elastic/apm/attach/JvmDiscovererTest.java
Show resolved
Hide resolved
apm-agent-attach-cli/src/test/java/co/elastic/apm/attach/DiscoveryRulesTest.java
Outdated
Show resolved
Hide resolved
…va into feature/java-stable-tag * 'feature/java-stable-tag' of github.com:v1v/apm-agent-java: (534 commits) Added Support for JBoss Logging to the log correlation plugin (elastic#1737) Removing improper RabbitMQ reference from instrumentation class (elastic#1745) Loading Advice classes lazily when required (elastic#1736) add support for ibm JVMs (elastic#1739) Adds circuit breaker to app deployment in load pipeline (elastic#1731) Bump json-schema-validator from 1.0.50 to 1.0.51 (elastic#1732) Bump java-driver-core from 4.10.0 to 4.11.0 (elastic#1733) Cassandra instrumentation (elastic#1712) Build apm-agent-attach-cli before application-server-integration-tests (elastic#1729) Fix thread pool method matchers (elastic#1717) Always use English locale when formatting doubles (elastic#1727) (elastic#1728) feat: grab locust metrics on load tests (elastic#1724) log readonly msg errors only in debug (elastic#1715) feat: use metricbeat to grab host metrics (elastic#1718) Eliminate log4j shaders dependency in slf4j (elastic#1723) Fix log correlation for log4j2 (elastic#1720) Allowing more time for the test Bump json-schema-validator from 1.0.49 to 1.0.50 (elastic#1711) Fix master build and print URL on connection error Attacher improvements (elastic#1667) ...
What does this PR do?
From changelog.asciidoc:
apm-agent-attach-cli
. The attacher API is still calledapm-agent-attach
.It requires the
--agent-jar
option to be set.The application uses {ecs-logging-java-ref}/intro.html[Java ECS logging] to emit JSON logs.
The log level can be configured with the
--log-level
option.By default, the program is logging to the console but using the
--log-file
option, it can also log to a file.The JVM requires the attacher to be running under the same user as the target VM (the attachee).
The
apm-agent-attach-standalone.jar
can now be run with a user that has permissions to switch to the user that runs the target VM.On Windows, the attacher can still only attach to JVMs that are running with under the same user.
--include-all
: Attach to all discovered JVMs. If no matchers are provided, it will not attach to any JVMs.--include-user
/--exclude-user
: Attach to all JVMs of a given operating system user.--include-main
/--exclude-main
: Attach to all JVMs that whose main class/jar name, or system properties match the provided regex.--include-vmargs
/--exclude-vmargs
: Attach to all JVMs that whose main class/jar name, or system properties match the provided regex.--arg
option has been removed.-i
/--include
,-e
/exclude
options have been removed in favor of the--<include|exclude>-<main|vmargs>
options.-p
/--pid
options have been removed in favor of the--include-pid
option.-l
/--list
optionThe option now only lists JVMs that match the include/exclude discovery rules.
Thus, it can be used to do a dry-run of the matchers without actually performing an attachment.
It even works in combination with
--continuous
now.By default, the VM arguments are not printed, but only when the
-a
/--list-vmargs
option is set.jps
Even when matching on the main class name or on system properties,
Checklist
TODOs
apm-agent-attach.jar
(attacher API) now has a compile dependency to log4j2 and log4j2-ecs-layout. Maybe we'll have to create different modules for the standalone cli attacher and the attacher API.--include-cmd foo --exclude-cmd bar
would matchfoo-bar.jar
. Should a given JVM pass the filter if it matches any include rule AND not matches any exclude rule?For Elastic Agent, they have recently added a similar rule logic. The following only allows APM to run:
Related issues
Closes #1688