From b65d2c1308c25661cc88a1e10b3aadbdad5cfe42 Mon Sep 17 00:00:00 2001 From: Doug Hilpipre Date: Tue, 25 Jun 2024 16:37:55 -0500 Subject: [PATCH 1/3] Updated Gradle to 7.3 --- gradle/wrapper/gradle-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a4f0001..e750102 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists From 5f6905ca99a55cbc560d341361f09de723a89ea2 Mon Sep 17 00:00:00 2001 From: Doug Hilpipre Date: Wed, 26 Jun 2024 05:33:57 -0500 Subject: [PATCH 2/3] updated Gradle and fixed verifyInstrumentation --- atomikos-cp-5.0/build.gradle | 2 +- .../build.gradle | 12 ++-- .../jms/AtomikosConnectionFactoryBean.java | 0 .../jms/AtomikosJmsXAConnectionFactory.java | 0 .../atomikos/jms/DataSourceSampler.java | 0 .../build.gradle | 17 ++---- .../jms/AtomikosConnectionFactoryBean.java | 43 +++++++++++++ .../jms/AtomikosJmsXAConnectionFactory.java | 8 +++ .../atomikos/jms/DataSourceSampler.java | 61 +++++++++++++++++++ 9 files changed, 123 insertions(+), 20 deletions(-) rename {atomikos-jms => atomikos-jms-3.9}/build.gradle (64%) rename {atomikos-jms => atomikos-jms-3.9}/src/main/java/com/atomikos/jms/AtomikosConnectionFactoryBean.java (100%) rename {atomikos-jms => atomikos-jms-3.9}/src/main/java/com/atomikos/jms/AtomikosJmsXAConnectionFactory.java (100%) rename {atomikos-jms => atomikos-jms-3.9}/src/main/java/com/nr/instrumentation/atomikos/jms/DataSourceSampler.java (100%) rename {atomikos-transaction-core => atomikos-jms-5.0}/build.gradle (53%) create mode 100644 atomikos-jms-5.0/src/main/java/com/atomikos/jms/AtomikosConnectionFactoryBean.java create mode 100644 atomikos-jms-5.0/src/main/java/com/atomikos/jms/AtomikosJmsXAConnectionFactory.java create mode 100644 atomikos-jms-5.0/src/main/java/com/nr/instrumentation/atomikos/jms/DataSourceSampler.java diff --git a/atomikos-cp-5.0/build.gradle b/atomikos-cp-5.0/build.gradle index 4e44312..6268ada 100644 --- a/atomikos-cp-5.0/build.gradle +++ b/atomikos-cp-5.0/build.gradle @@ -22,6 +22,6 @@ jar { } verifyInstrumentation { - passes 'com.atomikos:transactions-jdbc:[5.0.0]' + passes 'com.atomikos:transactions-jdbc:[5.0.0,)' excludeRegex '.*M[0-9]' } \ No newline at end of file diff --git a/atomikos-jms/build.gradle b/atomikos-jms-3.9/build.gradle similarity index 64% rename from atomikos-jms/build.gradle rename to atomikos-jms-3.9/build.gradle index f3ba66d..4fecc44 100644 --- a/atomikos-jms/build.gradle +++ b/atomikos-jms-3.9/build.gradle @@ -4,8 +4,8 @@ apply plugin: 'java' dependencies { - compile 'com.atomikos:transactions-jms:3.9.3' - compile 'javax.jms:jms-api:1.1-rev-1' + implementation 'com.atomikos:transactions-jms:3.9.3' + implementation 'javax.jms:jms-api:1.1-rev-1' // New Relic Labs Java Agent dependencies implementation 'com.newrelic.agent.java:newrelic-agent:6.0.0' @@ -15,7 +15,7 @@ dependencies { jar { manifest { - attributes 'Implementation-Title': 'com.newrelic.instrumentation.labs.atomikos_jms' + attributes 'Implementation-Title': 'com.newrelic.instrumentation.labs.atomikos_jms-3.9' attributes 'Implementation-Vendor': 'New Relic Labs' attributes 'Implementation-Vendor-Id': 'com.newrelic.labs' attributes 'Implementation-Version': 1.0 @@ -23,9 +23,5 @@ jar { } verifyInstrumentation { - // Verifier plugin documentation: - // https://github.com/newrelic/newrelic-gradle-verify-instrumentation - // Example: - // passes 'javax.servlet:servlet-api:[2.2,2.5]' - // exclude 'javax.servlet:servlet-api:2.4.public_draft' + passes 'com.atomikos:transactions-jms:[3.9.0,5.0.0)' } diff --git a/atomikos-jms/src/main/java/com/atomikos/jms/AtomikosConnectionFactoryBean.java b/atomikos-jms-3.9/src/main/java/com/atomikos/jms/AtomikosConnectionFactoryBean.java similarity index 100% rename from atomikos-jms/src/main/java/com/atomikos/jms/AtomikosConnectionFactoryBean.java rename to atomikos-jms-3.9/src/main/java/com/atomikos/jms/AtomikosConnectionFactoryBean.java diff --git a/atomikos-jms/src/main/java/com/atomikos/jms/AtomikosJmsXAConnectionFactory.java b/atomikos-jms-3.9/src/main/java/com/atomikos/jms/AtomikosJmsXAConnectionFactory.java similarity index 100% rename from atomikos-jms/src/main/java/com/atomikos/jms/AtomikosJmsXAConnectionFactory.java rename to atomikos-jms-3.9/src/main/java/com/atomikos/jms/AtomikosJmsXAConnectionFactory.java diff --git a/atomikos-jms/src/main/java/com/nr/instrumentation/atomikos/jms/DataSourceSampler.java b/atomikos-jms-3.9/src/main/java/com/nr/instrumentation/atomikos/jms/DataSourceSampler.java similarity index 100% rename from atomikos-jms/src/main/java/com/nr/instrumentation/atomikos/jms/DataSourceSampler.java rename to atomikos-jms-3.9/src/main/java/com/nr/instrumentation/atomikos/jms/DataSourceSampler.java diff --git a/atomikos-transaction-core/build.gradle b/atomikos-jms-5.0/build.gradle similarity index 53% rename from atomikos-transaction-core/build.gradle rename to atomikos-jms-5.0/build.gradle index df720f6..a9f850f 100644 --- a/atomikos-transaction-core/build.gradle +++ b/atomikos-jms-5.0/build.gradle @@ -1,12 +1,11 @@ -// Build.gradle generated for instrumentation module atomikos-transaction-core +// Build.gradle generated for instrumentation module atomikos_jms apply plugin: 'java' dependencies { - // Declare a dependency on each JAR you want to instrument - // Example: - // implementation 'javax.servlet:servlet-api:2.5' + implementation 'com.atomikos:transactions-jms:5.0.0' + implementation 'javax.jms:jms-api:1.1-rev-1' // New Relic Labs Java Agent dependencies implementation 'com.newrelic.agent.java:newrelic-agent:6.0.0' @@ -16,7 +15,7 @@ dependencies { jar { manifest { - attributes 'Implementation-Title': 'com.newrelic.instrumentation.labs.atomikos-transaction-core' + attributes 'Implementation-Title': 'com.newrelic.instrumentation.labs.atomikos_jms-5.0' attributes 'Implementation-Vendor': 'New Relic Labs' attributes 'Implementation-Vendor-Id': 'com.newrelic.labs' attributes 'Implementation-Version': 1.0 @@ -24,9 +23,5 @@ jar { } verifyInstrumentation { - // Verifier plugin documentation: - // https://github.com/newrelic/newrelic-gradle-verify-instrumentation - // Example: - // passes 'javax.servlet:servlet-api:[2.2,2.5]' - // exclude 'javax.servlet:servlet-api:2.4.public_draft' -} \ No newline at end of file + passes 'com.atomikos:transactions-jms:[5.0.0,)' +} diff --git a/atomikos-jms-5.0/src/main/java/com/atomikos/jms/AtomikosConnectionFactoryBean.java b/atomikos-jms-5.0/src/main/java/com/atomikos/jms/AtomikosConnectionFactoryBean.java new file mode 100644 index 0000000..73df074 --- /dev/null +++ b/atomikos-jms-5.0/src/main/java/com/atomikos/jms/AtomikosConnectionFactoryBean.java @@ -0,0 +1,43 @@ +package com.atomikos.jms; + +import javax.jms.Connection; + +import com.newrelic.api.agent.weaver.NewField; +import com.newrelic.api.agent.weaver.Weave; +import com.newrelic.api.agent.weaver.Weaver; +import com.nr.instrumentation.atomikos.jms.DataSourceSampler; + +@Weave +public abstract class AtomikosConnectionFactoryBean { + + public abstract String getUniqueResourceName(); + + public abstract int poolAvailableSize(); + + public abstract int poolTotalSize(); + + @NewField + private boolean initialized = false; + + + public Connection createConnection() { + if(!initialized) { + if(!DataSourceSampler.getInstance().contains(this)) { + DataSourceSampler.getInstance().addPool(this); + } + initialized = true; + } + return Weaver.callOriginal(); + } + + public AtomikosConnectionFactoryBean() { + DataSourceSampler.getInstance().addPool(this); + initialized = true; + } + + + public synchronized void close() { + DataSourceSampler.getInstance().removePool(this); + Weaver.callOriginal(); + } +} diff --git a/atomikos-jms-5.0/src/main/java/com/atomikos/jms/AtomikosJmsXAConnectionFactory.java b/atomikos-jms-5.0/src/main/java/com/atomikos/jms/AtomikosJmsXAConnectionFactory.java new file mode 100644 index 0000000..e921988 --- /dev/null +++ b/atomikos-jms-5.0/src/main/java/com/atomikos/jms/AtomikosJmsXAConnectionFactory.java @@ -0,0 +1,8 @@ +package com.atomikos.jms; + +import com.newrelic.api.agent.weaver.SkipIfPresent; + +@SkipIfPresent +abstract class AtomikosJmsXAConnectionFactory { + +} diff --git a/atomikos-jms-5.0/src/main/java/com/nr/instrumentation/atomikos/jms/DataSourceSampler.java b/atomikos-jms-5.0/src/main/java/com/nr/instrumentation/atomikos/jms/DataSourceSampler.java new file mode 100644 index 0000000..0a80f4c --- /dev/null +++ b/atomikos-jms-5.0/src/main/java/com/nr/instrumentation/atomikos/jms/DataSourceSampler.java @@ -0,0 +1,61 @@ +package com.nr.instrumentation.atomikos.jms; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import com.atomikos.jms.AtomikosConnectionFactoryBean; +import com.newrelic.agent.bridge.AgentBridge; +import com.newrelic.api.agent.NewRelic; +import com.newrelic.api.agent.weaver.Weaver; + +public class DataSourceSampler implements Runnable { + + private static List pools; + + private static String METRIC_PREFIX = "Custom/Atomikos Connection Pools/JMS/"; + + private static DataSourceSampler instance = null; + + public static DataSourceSampler getInstance() { + if(instance == null) { + instance = new DataSourceSampler(); + } + return instance; + } + + public boolean contains(AtomikosConnectionFactoryBean b) { + return pools.contains(b); + } + + public void addPool(AtomikosConnectionFactoryBean b) { + if(!pools.contains(b)) { + pools.add(b); + } + } + + public boolean removePool(AtomikosConnectionFactoryBean b) { + return pools.remove(b); + } + + private DataSourceSampler() { + pools = new ArrayList(); + AgentBridge.instrumentation.registerCloseable(Weaver.getImplementationTitle(),AgentBridge.privateApi.addSampler(this, 15, TimeUnit.SECONDS)); + } + + @Override + public void run() { + NewRelic.recordMetric(METRIC_PREFIX+"Pools Monitored", pools.size()); + for(AtomikosConnectionFactoryBean pool : pools) { + String poolName = pool.getUniqueResourceName(); + int available = pool.poolAvailableSize(); + int total = pool.poolTotalSize(); + String metricName = METRIC_PREFIX + poolName + "/Available"; + NewRelic.recordMetric(metricName, available); + metricName = METRIC_PREFIX + poolName + "/Total"; + NewRelic.recordMetric(metricName, total); + + } + } + +} From f1b5cd1edc7e2706194512d0c91214e643ea579d Mon Sep 17 00:00:00 2001 From: Doug Hilpipre Date: Wed, 26 Jun 2024 05:34:32 -0500 Subject: [PATCH 3/3] updated Gradle and fixed verifyInstrumentation --- settings.gradle | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index bab9340..72b0f8e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,5 +1,6 @@ rootProject.name = 'newrelic-java-atomikos' include 'atomikos-cp' -include 'atomikos-jms' +include 'atomikos-jms-3.9' +include 'atomikos-jms-5.0' include 'atomikos-cp-4.0' include 'atomikos-cp-5.0'