Skip to content

Commit

Permalink
Merge pull request #6 from newrelic-experimental/update_gradle
Browse files Browse the repository at this point in the history
Update gradle
  • Loading branch information
dhilpipre authored Jun 26, 2024
2 parents 776ac56 + f1b5cd1 commit b8c01be
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 22 deletions.
2 changes: 1 addition & 1 deletion atomikos-cp-5.0/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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]'
}
12 changes: 4 additions & 8 deletions atomikos-jms/build.gradle → atomikos-jms-3.9/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -15,17 +15,13 @@ 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
}
}

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)'
}
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -16,17 +15,13 @@ 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
}
}

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:[5.0.0,)'
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.atomikos.jms;

import com.newrelic.api.agent.weaver.SkipIfPresent;

@SkipIfPresent
abstract class AtomikosJmsXAConnectionFactory {

}
Original file line number Diff line number Diff line change
@@ -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<AtomikosConnectionFactoryBean> 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<AtomikosConnectionFactoryBean>();
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);

}
}

}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit b8c01be

Please sign in to comment.