Skip to content

Commit eb22fcb

Browse files
committed
Merge branch 'main' of github.com:newrelic/newrelic-java-agent into saxon/replace-otel-spans2
2 parents c8c10ff + 2b471a3 commit eb22fcb

File tree

251 files changed

+11572
-709
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

251 files changed

+11572
-709
lines changed

.github/actions/setup-environment/action.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ runs:
1818
with:
1919
distribution: 'temurin'
2020
java-version: |
21-
24
21+
25
2222
21
2323
17
2424
11
@@ -31,7 +31,7 @@ runs:
3131
s|jdk11=11|jdk11=${JAVA_HOME_11_X64}|
3232
s|jdk17=17|jdk17=${JAVA_HOME_17_X64}|
3333
s|jdk21=21|jdk21=${JAVA_HOME_21_X64}|
34-
s|jdk24=24|jdk24=${JAVA_HOME_24_X64}|" gradle.properties.gha
34+
s|jdk25=25|jdk25=${JAVA_HOME_25_X64}|" gradle.properties.gha
3535
cat gradle.properties.gha >> gradle.properties
3636
3737
- name: Setup Gradle
@@ -41,7 +41,7 @@ runs:
4141

4242
- name: Setup Gradle options
4343
shell: bash
44-
run: echo "GRADLE_OPTIONS=--console=plain --parallel -Porg.gradle.java.installations.auto-detect=false -Porg.gradle.java.installations.fromEnv=JAVA_HOME_8_X64,JAVA_HOME_11_X64,JAVA_HOME_17_X64,JAVA_HOME_21_X64,JAVA_HOME_24_X64" >> $GITHUB_ENV
44+
run: echo "GRADLE_OPTIONS=--console=plain --parallel -Porg.gradle.java.installations.auto-detect=false -Porg.gradle.java.installations.fromEnv=JAVA_HOME_8_X64,JAVA_HOME_11_X64,JAVA_HOME_17_X64,JAVA_HOME_21_X64,JAVA_HOME_25_X64" >> $GITHUB_ENV
4545

4646
- name: Download S3 instrumentation jar zip
4747
shell: bash

.github/workflows/GHA-Functional-Tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
##max-parallel: 1 ## used to force sequential
2929
fail-fast: false
3030
matrix:
31-
java-version: [ 8, 11, 17, 21, 24 ]
31+
java-version: [ 8, 11, 17, 21, 25 ]
3232
steps:
3333
- name: Checkout Java agent
3434
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # pin@v4

.github/workflows/GHA-Unit-Tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
# max-parallel: 1 ## used to force sequential vs. concurrent
2626
fail-fast: false
2727
matrix:
28-
java-version: [ 8, 11, 17, 21, 24 ]
28+
java-version: [ 8, 11, 17, 21, 25 ]
2929
steps:
3030
- name: Checkout Java agent
3131
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # pin@v4

.github/workflows/Java-Instrumentation-Tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
strategy:
2121
fail-fast: false
2222
matrix:
23-
java-version: [ 8, 11, 17, 21, 24 ]
23+
java-version: [ 8, 11, 17, 21, 25 ]
2424
name: Java ${{ matrix.java-version }}
2525
timeout-minutes: 120
2626
# needs: install-all-java

.github/workflows/Test-AITs.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ jobs:
216216
with:
217217
distribution: 'zulu'
218218
java-version: |
219-
24
219+
25
220220
21
221221
17
222222
11
@@ -227,14 +227,14 @@ jobs:
227227
echo "JDK_zulu_11=${JAVA_HOME_11_X64}" >> $GITHUB_ENV
228228
echo "JDK_zulu_17=${JAVA_HOME_17_X64}" >> $GITHUB_ENV
229229
echo "JDK_zulu_21=${JAVA_HOME_21_X64}" >> $GITHUB_ENV
230-
echo "JDK_zulu_24=${JAVA_HOME_24_X64}" >> $GITHUB_ENV
230+
echo "JDK_zulu_25=${JAVA_HOME_25_X64}" >> $GITHUB_ENV
231231
232232
- name: Set up Javas
233233
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # pin@v4
234234
with:
235235
distribution: 'temurin'
236236
java-version: |
237-
24
237+
25
238238
21
239239
17
240240
11
@@ -287,10 +287,10 @@ jobs:
287287
<toolchain>
288288
<type>jdk</type>
289289
<provides>
290-
<version>24</version>
290+
<version>25</version>
291291
</provides>
292292
<configuration>
293-
<jdkHome>${JAVA_HOME_24_X64}</jdkHome>
293+
<jdkHome>${JAVA_HOME_25_X64}</jdkHome>
294294
</configuration>
295295
</toolchain>
296296
</toolchains>
@@ -336,12 +336,12 @@ jobs:
336336
ZULU11=${JDK_zulu_11} \
337337
ZULU17=${JDK_zulu_17} \
338338
ZULU21=${JDK_zulu_21} \
339-
ZULU24=${JDK_zulu_24} \
339+
ZULU25=${JDK_zulu_25} \
340340
JAVA8JRE=${JAVA_HOME_8_X64} \
341341
JAVA11JRE=${JAVA_HOME_11_X64} \
342342
JAVA17JRE=${JAVA_HOME_17_X64} \
343343
JAVA21JRE=${JAVA_HOME_21_X64} \
344-
JAVA24JRE=${JAVA_HOME_24_X64} \
344+
JAVA25JRE=${JAVA_HOME_25_X64} \
345345
conf/autoconfigure
346346
. conf/testenv java
347347
cat conf/java_local_config.yml

agent-bridge/src/main/java/com/newrelic/agent/bridge/datastore/DatastoreInstanceDetection.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package com.newrelic.agent.bridge.datastore;
99

1010
import com.newrelic.agent.bridge.AgentBridge;
11+
import com.newrelic.api.agent.NewRelic;
1112

1213
import java.net.InetSocketAddress;
1314
import java.util.Map;
@@ -35,6 +36,11 @@ protected ConnectionState initialValue() {
3536
}
3637
};
3738

39+
public static enum MultiHostConfig {
40+
NONE, FIRST, LAST
41+
}
42+
public static MultiHostConfig multihostConfig = MultiHostConfig.NONE;
43+
3844
private static final ThreadLocal<InetSocketAddress> address = new ThreadLocal<>();
3945
private static final Map<Object, InetSocketAddress> connectionToAddress = AgentBridge.collectionFactory.createConcurrentWeakKeyedMap();
4046

@@ -94,11 +100,25 @@ public static void saveAddress(InetSocketAddress addressToStore) {
94100

95101
InetSocketAddress previousAddress = address.get();
96102
if (previousAddress != null && !previousAddress.equals(addressToStore)) {
103+
// the only way I've been able to reproduce this is talking via JDBC to an Azure SQL DB from
104+
// inside of Azure App Services, where we appear to be redirected to a worker host during the connect
105+
// in that case, the first detected address always appeared to be the requested address
106+
// and the 2nd/last address was always the worker
97107
AgentBridge.getAgent().getLogger().log(Level.FINEST,
98-
"Two different addresses detected: {0} and {1}. Invalidating previously detected address.",
99-
previousAddress, address);
100-
stopDetectingConnectionAddress();
101-
return;
108+
"Two different addresses detected: previous: {0} and new: {1}", previousAddress, addressToStore);
109+
MultiHostConfig multihostPreference = NewRelic.getAgent().getConfig().getValue("datastore_multihost_preference", MultiHostConfig.NONE);
110+
if (MultiHostConfig.FIRST.equals(multihostPreference)) {
111+
AgentBridge.getAgent().getLogger().log(Level.FINEST, "Keeping previous address: "+previousAddress);
112+
return;
113+
} else if (MultiHostConfig.LAST.equals(multihostPreference)) {
114+
AgentBridge.getAgent().getLogger().log(Level.FINEST, "Using new address: "+addressToStore);
115+
// just keep going, and we'll store the new address
116+
} else {
117+
// I cannot discern why this option was necessary, but it has been left in for backward compatibility
118+
AgentBridge.getAgent().getLogger().log(Level.FINEST, "Clearing address and stopping detection");
119+
stopDetectingConnectionAddress();
120+
return;
121+
}
102122
}
103123

104124
AgentBridge.getAgent().getLogger().log(Level.FINEST, "Storing address: {0}", address);

agent-bridge/src/test/java/com/newrelic/agent/bridge/datastore/DatastoreInstanceDetectionTest.java

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77

88
package com.newrelic.agent.bridge.datastore;
99

10+
import com.newrelic.api.agent.Agent;
11+
import com.newrelic.api.agent.NewRelic;
1012
import org.junit.Test;
13+
import org.mockito.MockedStatic;
1114
import org.mockito.Mockito;
1215

1316
import java.net.InetSocketAddress;
@@ -47,7 +50,48 @@ public void testMultipleAddresses() {
4750
}
4851

4952
@Test
50-
public void testDifferentAddresses() {
53+
public void testDifferentAddresses_UseFirst() {
54+
Agent mockAgent = Mockito.mock(Agent.class, Mockito.RETURNS_DEEP_STUBS);
55+
Mockito.when(mockAgent.getConfig().getValue("datastore_multihost_preference",
56+
DatastoreInstanceDetection.MultiHostConfig.NONE)).thenReturn(DatastoreInstanceDetection.MultiHostConfig.FIRST);
57+
try (MockedStatic<NewRelic> mockNewRelic = Mockito.mockStatic(NewRelic.class)) {
58+
mockNewRelic.when(NewRelic::getAgent).thenReturn(mockAgent);
59+
DatastoreInstanceDetection.detectConnectionAddress();
60+
DatastoreInstanceDetection.saveAddress(InetSocketAddress.createUnresolved("myhost", 1234));
61+
DatastoreInstanceDetection.saveAddress(InetSocketAddress.createUnresolved("someOtherHost", 9128));
62+
Connection connection = Mockito.mock(Connection.class);
63+
DatastoreInstanceDetection.associateAddress(connection);
64+
DatastoreInstanceDetection.stopDetectingConnectionAddress();
65+
66+
InetSocketAddress address = DatastoreInstanceDetection.getAddressForConnection(connection);
67+
assertEquals("myhost", address.getHostName());
68+
assertEquals(1234, address.getPort());
69+
}
70+
}
71+
72+
@Test
73+
public void testDifferentAddresses_UseLast() {
74+
Agent mockAgent = Mockito.mock(Agent.class, Mockito.RETURNS_DEEP_STUBS);
75+
Mockito.when(mockAgent.getConfig().getValue("datastore_multihost_preference",
76+
DatastoreInstanceDetection.MultiHostConfig.NONE)).thenReturn(DatastoreInstanceDetection.MultiHostConfig.LAST);
77+
try (MockedStatic<NewRelic> mockNewRelic = Mockito.mockStatic(NewRelic.class)) {
78+
mockNewRelic.when(NewRelic::getAgent).thenReturn(mockAgent);
79+
DatastoreInstanceDetection.detectConnectionAddress();
80+
DatastoreInstanceDetection.saveAddress(InetSocketAddress.createUnresolved("myhost", 1234));
81+
DatastoreInstanceDetection.saveAddress(InetSocketAddress.createUnresolved("someOtherHost", 9128));
82+
Connection connection = Mockito.mock(Connection.class);
83+
DatastoreInstanceDetection.associateAddress(connection);
84+
DatastoreInstanceDetection.stopDetectingConnectionAddress();
85+
86+
InetSocketAddress address = DatastoreInstanceDetection.getAddressForConnection(connection);
87+
assertEquals("someOtherHost", address.getHostName());
88+
assertEquals(9128, address.getPort());
89+
}
90+
}
91+
92+
@Test
93+
public void testDifferentAddresses_UseNone() {
94+
// NONE is the default
5195
DatastoreInstanceDetection.detectConnectionAddress();
5296
DatastoreInstanceDetection.saveAddress(InetSocketAddress.createUnresolved("myhost", 1234));
5397
DatastoreInstanceDetection.saveAddress(InetSocketAddress.createUnresolved("someOtherHost", 9128));
@@ -60,6 +104,50 @@ public void testDifferentAddresses() {
60104
assertNull(address);
61105
}
62106

107+
@Test
108+
public void testThreading() throws Exception {
109+
PausedConnectThread t1 = new PausedConnectThread("first");
110+
PausedConnectThread t2 = new PausedConnectThread("second");
111+
112+
t1.start();
113+
Thread.sleep(100);
114+
t2.start();
115+
Thread.sleep(100);
116+
117+
t2.goOn();
118+
Thread.sleep(100);
119+
t1.goOn();
120+
Thread.sleep(100);
121+
}
122+
123+
private class PausedConnectThread extends Thread {
124+
String host;
125+
boolean paused = false;
126+
PausedConnectThread(String name) {
127+
this.host = name;
128+
}
129+
public void run() {
130+
DatastoreInstanceDetection.detectConnectionAddress();
131+
DatastoreInstanceDetection.saveAddress(InetSocketAddress.createUnresolved(host, 1234));
132+
paused = true;
133+
while (paused) {
134+
//System.out.println("Paused, waiting 10ms: "+host);
135+
try { Thread.sleep(10); } catch (Exception e) {}
136+
}
137+
Connection connection = Mockito.mock(Connection.class);
138+
DatastoreInstanceDetection.associateAddress(connection);
139+
DatastoreInstanceDetection.stopDetectingConnectionAddress();
140+
141+
InetSocketAddress address = DatastoreInstanceDetection.getAddressForConnection(connection);
142+
assertEquals(host, address.getHostName());
143+
assertEquals(1234, address.getPort());
144+
145+
}
146+
public void goOn() {
147+
this.paused = false;
148+
}
149+
}
150+
63151
@Test
64152
public void testMultipleConnection() {
65153
DatastoreInstanceDetection.detectConnectionAddress();

agent-interfaces/src/main/java/com/newrelic/agent/interfaces/SamplingPriorityQueue.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,11 @@ public interface SamplingPriorityQueue<E extends PriorityAware> {
3434

3535
String getServiceName();
3636

37-
int getSampled();
38-
39-
int getDecided();
40-
41-
int getTarget();
42-
43-
int getDecidedLast();
37+
int getTotalSampledPriorityEvents();
4438

4539
int size();
4640

4741
void clear();
42+
43+
void logReservoirStats();
4844
}

agent-model/src/main/java/com/newrelic/agent/model/AnalyticsEvent.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@ public long getTimestamp() {
6868
return timestamp;
6969
}
7070

71-
@Override
72-
public boolean decider() {
73-
return false;
74-
}
75-
7671
@Override
7772
public float getPriority() {
7873
return priority;

agent-model/src/main/java/com/newrelic/agent/model/PriorityAware.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88
package com.newrelic.agent.model;
99

1010
/**
11-
* Simple interface to grab a priority (float) value from an object and to determine if this app was the "decider".
11+
* Simple interface to grab a priority (float) value from an object.
1212
*/
1313
public interface PriorityAware {
1414

15-
boolean decider();
16-
1715
float getPriority();
1816

1917
}

0 commit comments

Comments
 (0)