Skip to content
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

Enable agent-based instrumentation by default #23297

Closed
5 tasks done
mlopatkin opened this issue Dec 23, 2022 · 0 comments · Fixed by #23351, #23373 or #23807
Closed
5 tasks done

Enable agent-based instrumentation by default #23297

mlopatkin opened this issue Dec 23, 2022 · 0 comments · Fixed by #23351, #23373 or #23807
Assignees
Labels
a:feature A new functionality @configuration-cache in:configuration-cache Configuration Caching
Milestone

Comments

@mlopatkin
Copy link
Member

mlopatkin commented Dec 23, 2022

Currently, the agent-based instrumentation is under a feature flag. There are some rough edges that prevent us from enabling it:

@mlopatkin mlopatkin added a:feature A new functionality in:configuration-cache Configuration Caching @configuration-cache labels Dec 23, 2022
@mlopatkin mlopatkin added this to the 8.1 RC1 milestone Dec 23, 2022
@mlopatkin mlopatkin self-assigned this Dec 23, 2022
@mlopatkin mlopatkin moved this to In Progress in Stable Configuration Cache Jan 3, 2023
bot-gradle added a commit that referenced this issue Jan 27, 2023
…ntation around TransformedClassPath

Part of #23297

Co-authored-by: Mikhail Lopatkin <mlopatkin@gradle.com>
bot-gradle added a commit that referenced this issue Feb 24, 2023
## Review notes
This PR adds the ability to use the instrumenting agent in all Gradle integration tests, but using the new instrumentation mode is still gated behind a feature flag, so there are no observable behavior changes (these are to come). As of this PR, you have to specify `-Porg.gradle.integtest.agent.allowed=true` flag to run tests with the new instrumentation mode. The follow-up PR will change the default value of the feature flag.

I strived to make commits self-contained and to avoid back-and-forth, so the PR commits can be reviewed one-by-one. Some TODOs are addressed in the follow-up commits, but several left for coming PRs.

## A summary of changes

A quick recap: there are two essential pieces to make the new instrumentation work. First, the agent has to be applied to the process running the build, and the `DefaultClassFileTransformer` has to be registered within the agent. Second, the `DefaultCachedClasspathTransformer` has to output `TransformedClassPath` instead of `DefaultClassPath`. Prior to this PR, applying the agent would toggle the DefaultCachedClasspathTransformer.

However, to make feature flag working in all modes, we have to break this link. When the build runs in the "--no-daemon" mode (i.e. everything happens in the client process), the agent is being applied with a flag in the start script. It is not possible to figure out the state of the feature flag in the start script. The same applies to the "--foreground" mode of starting the daemon.

This PR introduces the AgentStatus interface that is being controlled by both the presence of the agent and the value of the feature flag. With this, it becomes possible to apply the agent in the start scripts. For foreground daemons, there are changes to the compatibility checking: the `-javaagent:..gradle-instrumentation-agent` switch doesn't affect the compatibility of daemon contexts, as the agent status is present in the context explicitly anyway.

It is not possible for the daemon/process to change its instrumentation mode. The daemon flags (maybe coming from the `gradle.properties` of the first build) at startup determine the mode.

The rest of the changes are mostly dealing with the test infrastructure to allow enabling the new instrumentation in different modes:
1. Embedded mode: agent is applied to test processes, and to the daemons spawned in the tests.
2. No-daemon mode: start script tweaks and process compatibility tweaks (process with agent applied can run tests with legacy instrumentation)
3. Forking mode: it was working already.

In the end, when  `-Porg.gradle.integtest.agent.allowed=true` is used, all executors enable the feature flag in their command line.

## Follow-up work
- TAPI tests are not executed with the agent instrumentation enabled. This is going to be revisited when the feature flag becomes on by default. It is just too hard to plumb the feature flag all the way for TAPI.
- A few tests are ignored for now, but the breakages are not really affecting correctness.

Part of #23297.

Co-authored-by: Mikhail Lopatkin <mlopatkin@gradle.com>
@mlopatkin mlopatkin reopened this Feb 24, 2023
@github-project-automation github-project-automation bot moved this from In Progress to Todo in Stable Configuration Cache Feb 24, 2023
@mlopatkin mlopatkin moved this from Todo to In Progress in Stable Configuration Cache Feb 24, 2023
@mlopatkin mlopatkin moved this from In Progress to Done in Stable Configuration Cache Feb 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment