Code Monkey home page Code Monkey logo

newrelic-gradle-verify-instrumentation's Introduction

New Relic Open Source community project banner.

gradle-verify-instrumentation-plugin

This plugin provides support for verifyInstrumentation DSL in New Relic instrumentation gradle build files. Using this plugin, you can figure out what range of versions for a library are supported by your instrumentation.

โš ๏ธ This plugin has a very niche use case for the New Relic Java Agent. It is not intended to be used or modified for any other environment.

Open source license

This project is distributed under the Apache 2 license.

What do you need to make this work?

Required:

  • Gradle, minimum 7.2
  • Java 17

Java Runtime

Most Java agent instrumentation modules are compiled to target Java 8+. However, some modules are compiled to target Java 11 and others require Java 17. The verifier must be run with a minimum Java runtime of 17 because it will fail when trying to verify instrumentation targeting Java 17 when running all modules from the same runtime. Of course, when running individual modules the runtime can be whatever version the given module requires.

Start using the plugin

To use the plugin, update your buildscript dependencies in settings.gradle:

pluginManagement {
    repositories {
      mavenLocal()
      mavenCentral()
      gradlePluginPortal()
    }
  }

Update your build.gradle:

buildscript {
    dependencies {
        classpath "com.newrelic.agent.java:gradle-verify-instrumentation-plugin:3.1"
    }
}

apply plugin "com.newrelic.gradle-verify-instrumentation-plugin"

Or:

 plugins {
   id("com.newrelic.gradle-verify-instrumentation-plugin") version "3.1"
 }

Note For instrumentation bundled with the New Relic Java agent, this is already configured and these steps are not required.

Configuring the plugin

To configure the plugin for a specific weave instrumentation library, in each instrumentation's build.gradle, you'll need to configure a verifyInstrumentation block. Within this block, specify maven ranges that your module should pass or fail against.

The task downloads all versions (and all required dependencies) within the testing ranges. Each version downloaded is then checked to make sure the instrumentation in this module applies as expected:

  • If the target code is covered by passes or passesOnly, then the module must apply successfully.
  • If the target code is covered by fails or is outside of a passesOnly range, then the module must not apply successfully.
  • If the condition above is not met, the gradle task fails with the reason.
verifyInstrumentation {
    fails("com.typesafe.play:anorm_2.11:[1.0,2.0)")
    passes("com.typesafe.play:anorm_2.11:[2.0,2.5)")
    fails("com.typesafe.play:anorm_2.11:[2.5,)")
}

In this example, we are saying that versions 2.0 (inclusive) through versions 2.5 (exclusive) of the "anorm_2.11" library should instrument correctly. We are also saying that versions 1.0 (inclusive) through versions 2.0 (exclusive) should fail. We also assert that versions greater than or equal to 2.5 fail instrumentation. This ensures that our instrumentation only works with the range specified in passes.

There are several options to use to configure the range support. In no particular order:

  • passes specifies the range that should be able to be instrumented. It does not perform any checks on versions outside the range.
  • fails specifies the range that should fail to be instrumented.
  • passesOnly specifies the range that should be able to be instrumented. It then checks all versions outside the range (for the same group:name) to ensure those versions fail.
  • exclude specifies versions (can be a range) to exclude
  • excludeRegex specifies versions to exclude using a regex, useful for excluding all snapshot builds, for example.
  • [] configures an inclusive match
  • () configures an exclusive match

For more information on range syntax, see Maven version syntax.

Note In general, using passesOnly is preferable, as it ensures that only the given range works against your instrumentation, and not anything else. We can rewrite our above example with one line using passesOnly:

verifyInstrumentation {
    passesOnly  'com.typesafe.play:anorm_2.11:[2.0,2.5)'
}

Configuring the plugin outside the java_agent repo

The java_agent repo configuration includes several values you must set if using verifyInstrumentation outside the java_agent repo.

  • nrAgent must be a reference to the newrelic.jar fat jar. You can specify a String to use a maven dependency, or a File to reference a local file.
  • passesFileName is a file name as a String if you want all successful verifications to log to the same file. That is, when the package fails to apply when it should fail, or applies successfully when it should apply successfully.
  • verifyClasspath can be used to verify that the jar successfully applies when loading exactly the compile and implementation dependencies specified for the implementation jar.

Running the plugin

To verify all instrumentation libraries, simply invoke:

.../java_agent/$ ./gradlew verifyInstrumentation

...and then go for a fresh cup of coffee. You have enough time to get get a really good cup a couple blocks away.

To verify a specific instrumentation module, invoke:

...cd instrumentation/moduleToVerify
.../moduleToVerify/$ ../../gradlew verifyInstrumentation

Or:

.../java_agent/$ ./gradlew :instrumentation:moduleToVerify:verifyInstrumentation

Additional Dependencies

By default, the Maven library is verified with its transitive dependencies. To specify additional dependencies while verifying, add a configuration closure and use 'implementation'.

verifyInstrumentation {
  passesOnly("io.spray:spray-routing_2.11:[1.3.1,)") {
    implementation("com.typesafe.akka:akka-actor_2.11:2.3.14") // akka is not explicitly listed as a spray dependency so we have to tell the verifier to include it.
  }
}

Choosing versions

The versions to include and exclude are entirely dependent upon the target library being instrumented.

Once you have the general range of supported versions (something like [2.0,2.5)), you need to verify the whole range and make note of any failures. If you are maintaining an instrumentation module with an open-ended list (such as [2.0,)), then you need to run verifyInstrumentation periodically to ensure the version range is still correct.

You'll probably see that just one build here or there fails. With that, you should add an exception, as it's probably just a problem with a specific build of the target library. If you see a whole string of failures, it might indicate a more fundamental change in the library as of a specific version. In that case, you might need to cap the version support, and create a new instrumentation to handle the newer versions.

Support

New Relic has open-sourced this project. This project is provided AS-IS WITHOUT WARRANTY OR DEDICATED SUPPORT. Report issues and contributions to the project here on GitHub.

We encourage you to bring your experiences and questions to the Explorers Hub where our community members collaborate on solutions and new ideas.

Community

New Relic hosts and moderates an online forum where customers can interact with New Relic employees as well as other customers to get help and share best practices. Like all official New Relic open source projects, there's a related Community topic in the New Relic Explorers Hub. You can find this project's topic/threads here:

Java Agent Support Forum

Issues / enhancement requests

Issues and enhancement requests can be submitted in the issues tab of this repository. Please search for and review the existing open issues before submitting a new issue.

Contributing

We encourage your contributions to improve this project! Keep in mind when you submit your pull request, you'll need to sign the CLA via the click-through using CLA-Assistant. You only have to sign the CLA one time per project. If you have any questions, or to execute our corporate CLA, required if your contribution is on behalf of a company, please drop us an email at [email protected].

A note about vulnerabilities

As noted in our security policy, New Relic is committed to the privacy and security of our customers and their data. We believe that providing coordinated disclosure by security researchers and engaging with the security community are important means to achieve our security goals.

If you believe you have found a security vulnerability in this project or any of New Relic's products or websites, we welcome and greatly appreciate you reporting it to New Relic through HackerOne.

If you would like to contribute to this project, review these guidelines.

newrelic-gradle-verify-instrumentation's People

Contributors

breedx-nr avatar cliftondobrich avatar deleonenriqueta avatar gfuller1 avatar grahamfuller1 avatar jasonjkeller avatar jeffalder avatar kanderson250 avatar kford-newrelic avatar meiao avatar melissaklein24 avatar mmfred avatar tbradellis avatar tspring avatar twcrone avatar xixiapdx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

newrelic-gradle-verify-instrumentation's Issues

What if I only want to run classpath verification?

Summary

The plugin will generate tasks for every version that it finds in the range. However:

  • If there's one version of the library
  • It's not on Maven
  • I have it copied locally

Then the plugin will not generate tasks.

Desired Behavior

For the summary above, verifyInstrumentation should automatically generate and run the classpath task unless verifyClasspath is false. No further configuration should be required - particularly no passes or passesOnly.

[Repolinter] Open Source Policy Issues

Repolinter Report

๐Ÿค–This issue was automatically generated by repolinter-action, developed by the Open Source and Developer Advocacy team at New Relic. This issue will be automatically updated or closed when changes are pushed. If you have any problems with this tool, please feel free to open a GitHub issue or give us a ping in #help-opensource.

This Repolinter run generated the following results:

โ— Error โŒ Fail โš ๏ธ Warn โœ… Pass Ignored Total
0 4 1 2 0 7

Fail #

โŒ readme-starts-with-community-header #

The README of a community project should have a community project header at the start of the README. If you already have a community project header and this rule is failing, your header may be out of date, and you should update your header with the suggested one below. For more information please visit https://opensource.newrelic.com/oss-category/. Below is a list of files or patterns that failed:

  • README.md: The first 5 lines do not contain the pattern(s): Open source Community header (see https://opensource.newrelic.com/oss-category).
    • ๐Ÿ”จ Suggested Fix: prepend the latest code snippet found at https://github.com/newrelic/opensource-website/wiki/Open-Source-Category-Snippets#code-snippet-1 to file

โŒ readme-contains-link-to-security-policy #

Doesn't contain a link to the security policy for this repository (README.md). New Relic recommends putting a link to the open source security policy for your project (https://github.com/newrelic/<repo-name>/security/policy or ../../security/policy) in the README. For an example of this, please see the "a note about vulnerabilities" section of the Open By Default repository. For more information please visit https://nerdlife.datanerd.us/new-relic/security-guidelines-for-publishing-source-code.

โŒ readme-contains-forum-topic #

Doesn't contain a link to the appropriate forum.newrelic.com topic (README.md). New Relic recommends directly linking the your appropriate forum.newrelic.com topic in the README, allowing developer an alternate method of getting support. For more information please visit https://nerdlife.datanerd.us/new-relic/security-guidelines-for-publishing-source-code.

โŒ code-of-conduct-should-not-exist-here #

New Relic has moved the CODE_OF_CONDUCT file to a centralized location where it is referenced automatically by every repository in the New Relic organization. Because of this change, any other CODE_OF_CONDUCT file in a repository is now redundant and should be removed. Note that you will need to adjust any links to the local CODE_OF_CONDUCT file in your documentation to point to the central file (README and CONTRIBUTING will probably have links that need updating). For more information please visit https://docs.google.com/document/d/1y644Pwi82kasNP5VPVjDV8rsmkBKclQVHFkz8pwRUtE/view. Found files. Below is a list of files or patterns that failed:

  • CODE_OF_CONDUCT.md
    • ๐Ÿ”จ Suggested Fix: Remove file

Warning #

Click to see rules

โš ๏ธ third-party-notices-file-exists #

A THIRD_PARTY_NOTICES.md file can be present in your repository to grant attribution to all dependencies being used by this project. This document is necessary if you are using third-party source code in your project, with the exception of code referenced outside the project's compiled/bundled binary (ex. some Java projects require modules to be pre-installed in the classpath, outside the project binary and therefore outside the scope of the THIRD_PARTY_NOTICES). Please review your project's dependencies and create a THIRD_PARTY_NOTICES.md file if necessary. For JavaScript projects, you can generate this file using the oss-cli. For more information please visit https://docs.google.com/document/d/1y644Pwi82kasNP5VPVjDV8rsmkBKclQVHFkz8pwRUtE/view. Did not find a file matching the specified patterns. Below is a list of files or patterns that failed:

  • THIRD_PARTY_NOTICES*
  • THIRD-PARTY-NOTICES*
  • THIRDPARTYNOTICES*

Passed #

Click to see rules

โœ… license-file-exists #

Found file (LICENSE). New Relic requires that all open source projects have an associated license contained within the project. This license must be permissive (e.g. non-viral or copyleft), and we recommend Apache 2.0 for most use cases. For more information please visit https://docs.google.com/document/d/1vML4aY_czsY0URu2yiP3xLAKYufNrKsc7o4kjuegpDw/edit.

โœ… readme-file-exists #

Found file (README.md). New Relic requires a README file in all projects. This README should give a general overview of the project, and should point to additional resources (security, contributing, etc.) where developers and users can learn further. For more information please visit https://github.com/newrelic/open-by-default.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.