ryandens / javaagent-gradle-plugin

A set of Gradle plugins to ease building Java applications that leverage instrumentation agents in development and/or in production
Apache License 2.0
47 stars 8 forks source link

Feature request: add agent-jar before resources/classes layers in Jib #13

Closed blagerweij closed 2 years ago

blagerweij commented 2 years ago

Hey there,

Thanks for making this really useful plugin available, until now we have been using a combination of Helm and initContainers to enable APM for our apps. I did notice one thing that is annoying:

When the plugin is used, the agent-jar is appended as the last layer (using the Jib extension). However, since the agent-jar does not change very often, it would be better if the agent-jar could be positioned right after the base image, before any dependencies, resources and classes. I checked the Jib extensions interface for build plans, and I could only find 'addLayer' (which appends to the last layer). However I'm hoping there is a way to inject the JAR not at the end....

ryandens commented 2 years ago

👍 That makes sense! I agree that the agent layer won't change as much as the application layer, I'll see what I can do to make it create more optimized images. Looking at the jib build plan API I'm thinking we could

  1. Access the using ContainerBuildPlan.getLayers() using this API
  2. Override all the layers using the ContainerBuildPlan.setLayers(List)using this API

Your deployment model makes me think you might find some of the other things I'm working on useful. Definitely look into traceable.ai if you're looking past APM and into API security for your backend services. We have a free play 😄

blagerweij commented 2 years ago

I took the liberty of preparing a PR with the above feature. Please check carefully, since I'm no expert in Kotlin. https://github.com/ryandens/javaagent-gradle-plugin/pull/14

blagerweij commented 2 years ago

Thanks for the link to traceable.ai, will check it out. We're currently using a combination of DataDog and SnowFlake/SnowPlow to achieve pretty much the same, but that looks interesting. Also, we're currently using Open Policy Agent to not only monitor API usage, but also enforce some rulesets.

blagerweij commented 2 years ago

@ryandens any progress on reviewing the PR?