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

Trying to extract codegen plugin #3521

Merged
merged 17 commits into from
Jul 14, 2021
Merged

Conversation

iNikem
Copy link
Contributor

@iNikem iNikem commented Jul 7, 2021

No description provided.

buildSrc/build.gradle.kts Outdated Show resolved Hide resolved
@iNikem
Copy link
Contributor Author

iNikem commented Jul 9, 2021

Asking for specific feedback:

  • Name of the plugin module. Currently javaagent-muzzle-generation. Ok/Nok/better ideas?
  • Id of the plugin. Currently io.opentelemetry.instrumentation.javaagent-codegen. Ok/Nok/better ideas?

@iNikem iNikem marked this pull request as ready for review July 9, 2021 07:05
group = "io.opentelemetry.instrumentation.gradle"

dependencies {
implementation("com.google.guava:guava")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry had a pending comment but forgot to hit submit. On the topic of a codegen configuration

I think we may still want the configuration

  1. To add less to Gradle classpath. If we add too much it can cause dependency hell, a bit worried about Guava
  2. To be able to substitute in the project dependencies in our project, not sure we'd have any way of doing it for a plugin transitive dependency which would be resolved way too early for a substitution to kick in I think.

I guess 1 could be resolved with shading anyways though. But 2) seems important and a requirement to allow using an older version of the plugin even as we work on the javaagent-extension-api.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the same time self-contained plugin is good for external users. They don't need to know about "codegen" dependency and that something has to be added to it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah they wouldn't need to with the configuration either since we configure it with defaults here. Before this PR our repo is substituting to use our project dependencies but it's not required to care otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am afraid I don't quite understand what do you suggest? Do you mean to create and use codegen configuration already here, right in the module? Or how?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose using the same pattern we have

https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/buildSrc/src/main/kotlin/io.opentelemetry.instrumentation.javaagent-testing.gradle.kts#L33

This as all the io.openteletry.* ones are meant to be published for downstream. Though most will get this one transitively via io.opentelemetry.instrumentation.javaagent-instrumentation.

The configuration is set here when the plugin is included so most users won't need to worry about it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also makes me realize this project shouldn't be called muzzle or codegen or anything - let's call it gradle-plugins. We have a few plugins to publish.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also makes me realize this project shouldn't be called muzzle or codegen or anything - let's call it gradle-plugins. We have a few plugins to publish.

Which ones? I am fine with publishing muzzle generation and checking as one plugin. But I am not sure we should bundle all our plugins into one artifact?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose using the same pattern we have

https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/buildSrc/src/main/kotlin/io.opentelemetry.instrumentation.javaagent-testing.gradle.kts#L33

This as all the io.openteletry.* ones are meant to be published for downstream. Though most will get this one transitively via io.opentelemetry.instrumentation.javaagent-instrumentation.

The configuration is set here when the plugin is included so most users won't need to worry about it.

Do I understand you correctly?

  • Published io.opentelemetry.instrumentation.javaagent-codegen plugin does not have any declared runtime dependencies
  • Actual dependencies, such as guava and javaagent-extension-api are added by io.opentelemetry.instrumentation.javaagent-instrumentation plugin
  • End users are supposed to use io.opentelemetry.instrumentation.javaagent-instrumentation plugin when it gets published

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that understanding sounds correct to me.

But I am not sure we should bundle all our plugins into one artifact?

I don't think there's any real downside - anyways we'll publish to Gradle Plugin Portal so users just add the plugin to their project and don't care how the artifact is structured. So it allows us to keep all plugin publishing type of logic together.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, we don't actually HAVE to publish to Gradle Plugin Portal. Plugins can be consumed just from Maven Central as well.

Second, ok, let's give it a try...

@@ -0,0 +1,22 @@
plugins {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want the word muzzle in these projects? Assuming muzzle refers to our safety mechanism for applying instrumentation across versions, a lot of the codegen is independent of muzzle

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This plugin generates bodies for InstrumentationModule methods with word muzzle in method names. So currently it is certainly muzzle-related.

website = "https://opentelemetry.io"
vcsUrl = "https://github.com/open-telemetry/opentelemetry-java-instrumentation"
tags = listOf("opentelemetry", "instrumentation")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need that plugins snippet from my draft PR when publishing to portal so may as well add it now right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which PR? :) Sorry, you are too laconic for me recently :(

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for my smartphone replies, somehow GitHub app still doesn't support linking to lines of code. And now that I look for it I can't find it in the PR I sent, that's definitely too laconic...

gradlePlugin {
    plugins { 
        named("io.opentelemetry.instrumentation.javaagent-codegen") { 
            displayName = "<short displayable name for plugin>" 
            description = "<Good human-readable description of what your plugin is about>" 
        }
    }
}

https://docs.gradle.org/current/userguide/publishing_gradle_plugins.html#configure_the_plugin_publishing_plugin

One thing I found is for precompiled script plugin, we leave out id and implementationClass and it seems to work ok

@iNikem
Copy link
Contributor Author

iNikem commented Jul 12, 2021

For the reference: here is an example of using this new plugin in an external project: https://github.com/signalfx/splunk-otel-java/compare/muzzle-codegen?expand=1. Only one module was verified to work for now.

I am concerned about using codegen configuration in that module's build script.

Copy link
Contributor

@anuraaga anuraaga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just nits, thanks!

}

dependencies {
add("muzzleBootstrap", "io.opentelemetry.javaagent:opentelemetry-javaagent-bootstrap")
add("muzzleTooling", "io.opentelemetry.javaagent:opentelemetry-javaagent-tooling")
add("muzzleTooling", "io.opentelemetry.javaagent:opentelemetry-javaagent-extension-api")

add("codegen", "io.opentelemetry.javaagent:opentelemetry-javaagent-tooling")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is tooling needed for codegen?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently not right now...

@@ -11,6 +11,8 @@ plugins {
See https://imperceptiblethoughts.com/shadow/ for more details about Shadow plugin.
*/
id "com.github.johnrengelman.shadow" version "6.1.0"

id "io.opentelemetry.instrumentation.javaagent-codegen" version "0.1.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 0.1.0 some temporary released version? Are we going to version gradle plugins the same way we do all other artficats?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently this module is totally independent from the main build. I don't have a strong opinion on its versioning atm

@iNikem iNikem merged commit cbfd7e1 into open-telemetry:main Jul 14, 2021
@iNikem iNikem deleted the extract-codegen branch July 14, 2021 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants