Skip to content

Commit

Permalink
Merge branch 'main' into edeleon/nr-80764
Browse files Browse the repository at this point in the history
  • Loading branch information
deleonenriqueta committed Jul 21, 2023
2 parents d1e156d + 01e831f commit 4bbce54
Show file tree
Hide file tree
Showing 85 changed files with 4,045 additions and 199 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
labels: feature request
assignees: ''
priority: ''
---
Expand Down
9 changes: 8 additions & 1 deletion .github/actions/setup-environment/action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: Setup Environment
description: Sets up the environment to build/test the agent.
inputs:
gradle-cache-read-only:
description: 'Whether the Gradle cache should be read only'
required: false
default: 'true'
# This action expects the agent to be checked out at $GITHUB_WORKSPACE.
# It will also set up the instrumentation jar zip if AWS credentials are set.
# This action requires these because composite actions cannot use secrets.
Expand Down Expand Up @@ -29,6 +34,8 @@ runs:
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
cache-read-only: ${{ inputs.gradle-cache-read-only }}

- name: Setup Gradle options
shell: bash
Expand All @@ -37,7 +44,7 @@ runs:
- name: Download S3 instrumentation jar zip
shell: bash
run: |
aws s3 cp s3://nr-java-agent-s3-instrumentation/proprietary-jars-20220805.zip proprietary-jars.zip && unzip proprietary-jars.zip
aws s3 cp s3://nr-java-agent-s3-instrumentation/proprietary-jars-20230623.zip proprietary-jars.zip && unzip proprietary-jars.zip
if [ $? -ne 0 ]; then
echo "Instrumentation jar zip unavailable." >> $GITHUB_STEP_SUMMARY
fi
3 changes: 1 addition & 2 deletions .github/workflows/Test-AITs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ jobs:
echo "framework/snap/snap.py" >> $excluded_tests
echo "r2dbc/mssql.py" >> $excluded_tests
echo "server/mule.py" >> $excluded_tests
echo "server/was_liberty.py" >> $excluded_tests
echo "server/weblogic.py" >> $excluded_tests
# The files below are not tests
echo "trace/client.py" >> $excluded_tests
Expand Down Expand Up @@ -111,7 +110,7 @@ jobs:
uses: actions/cache@v3
with:
path: /home/runner/work/newrelic-java-agent/newrelic-java-agent/newrelic-agent/build/newrelicJar/newrelic.jar
key: ${{ github.run_id }}
key: agent-jar-${{ github.run_id }}
fail-on-cache-miss: true

## Ongoing tests with artifactory dependencies
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/VerifyInstrumentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ on:
type: string
description: 'The ref (branch, SHA, tag?) to run the tests on'
schedule:
- cron: '0 8 * * *'
- cron: '0 8 * * MON-FRI'

jobs:
# build the agent and saves Gradle's cache so all modules can use the cache
Expand All @@ -25,6 +25,7 @@ jobs:
uses: ./.github/workflows/X-Reusable-BuildAgent.yml
with:
agent-ref: ${{ inputs.agent-ref || 'main' }}
gradle-cache-read-only: ${{ github.event_name != 'schedule' }}
secrets: inherit

# GHA Matrix strategy only allows 255 entries.
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/X-Reusable-BuildAgent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ on:
default: main
type: string
description: 'The ref (branch, SHA, tag?) to run the tests on'
gradle-cache-read-only:
required: false
default: true
type: boolean
description: 'Whether the gradle cache should be read only'
jobs:
# build the agent and saves Gradle's cache so all modules can use the cache
build-agent:
Expand All @@ -31,6 +36,8 @@ jobs:

- name: Setup environment
uses: ./.github/actions/setup-environment
with:
gradle-cache-read-only: ${{ inputs.gradle-cache-read-only }}

- name: Build agent
run: ./gradlew $GRADLE_OPTIONS clean jar
Expand All @@ -39,4 +46,4 @@ jobs:
uses: actions/cache@v3
with:
path: /home/runner/work/newrelic-java-agent/newrelic-java-agent/newrelic-agent/build/newrelicJar/newrelic.jar
key: ${{ github.run_id }}
key: agent-jar-${{ github.run_id }}
2 changes: 1 addition & 1 deletion .github/workflows/X-Reusable-VerifyInstrumentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
uses: actions/cache@v3
with:
path: /home/runner/work/newrelic-java-agent/newrelic-java-agent/newrelic-agent/build/newrelicJar/newrelic.jar
key: ${{ github.run_id }}
key: agent-jar-${{ github.run_id }}
fail-on-cache-miss: true

# Verify instrumentation must run with Java 17
Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,28 @@ After building, Java agent artifacts are located here:
- Agent: `newrelic-agent/build/newrelicJar/newrelic.jar`
- Agent API: `newrelic-api/build/libs/newrelic-api-*.jar`

#### Non standard modules

The following modules have specific requirements to be built. The instructions for each is in the module's README.md.

- [aws-wrap-0.7.0](./instrumentation/aws-wrap-0.7.0/README.md)
- [jboss-7](./instrumentation/jboss-7/README.md)
- [jdbc-inet-merlia](./instrumentation/jdbc-inet-merlia/README.md)
- [jdbc-inet-oranxo](./instrumentation/jdbc-inet-oranxo/README.md)
- [jdbc-ojdbc](./instrumentation/jdbc-ojdbc/README.md)
- [jdbc-sybase-6](./instrumentation/jdbc-sybase-6/README.md)
- [open-liberty-jakarta-21.0.0.12](./instrumentation/open-liberty-jakarta-21.0.0.12/README.md)
- [resin-3](./instrumentation/resin-3/README.md)
- [weblogic-12.2](./instrumentation/weblogic-12.2/README.md)
- [weblogic-12](./instrumentation/weblogic-12/README.md)
- [weblogic-jmx-12.2.1](./instrumentation/weblogic-jmx-12.2.1/README.md)
- [weblogic-jmx-12](./instrumentation/weblogic-jmx-12/README.md)
- [websphere-8](./instrumentation/websphere-8/README.md)
- [websphere-jmx-7](./instrumentation/websphere-jmx-7/README.md)
- [websphere-liberty-profile-8.5.5.5](./instrumentation/websphere-liberty-profile-8.5.5.5/README.md)
- [websphere-liberty-profile-dispatcher-8.5.5.5](./instrumentation/websphere-liberty-profile-dispatcher-8.5.5.5/README.md)
- [websphere-liberty-profile-environment-8.5.5.5](./instrumentation/websphere-liberty-profile-environment-8.5.5.5/README.md)

## IntelliJ IDEA setup

We recommend using IntelliJ IDEA for development on this project. Configure as follows:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.newrelic.agent.bridge;


import com.newrelic.api.agent.weaver.internal.WeavePackageType;
import org.junit.Test;
import org.mockito.Mockito;

import java.util.concurrent.atomic.AtomicInteger;

import static org.junit.Assert.*;
public class AgentBridgeTest {
@Test
public void distributedTraceParseInstance_returnsNull() {
assertNull(AgentBridge.distributedTraceParser.parseDistributedTracePayload("foo"));
}

@Test
public void getAgent_returnsNoOpAgent() {
assertEquals(NoOpAgent.INSTANCE, AgentBridge.getAgent());
}

@Test
public void extensionHolderFactoryInstance_returnsNoOpInstance() {
assertEquals(ExtensionHolderFactory.NoOpExtensionHolderFactory.class, AgentBridge.extensionHolderFactory.getClass());
}

@Test
public void testCurrentApiSourceThreadLocalInstance() {

ThreadLocal<WeavePackageType> instance = AgentBridge.currentApiSource;

instance.set(WeavePackageType.FIELD);
assertEquals(WeavePackageType.FIELD, instance.get());

instance.remove();
assertEquals(WeavePackageType.UNKNOWN, instance.get());

instance.set(null);
assertEquals(WeavePackageType.UNKNOWN, instance.get());
}

@Test
public void testTokenAndRefCount() {
Token mockToken = Mockito.mock(Token.class);
TracedMethod mockTracedMethod = Mockito.mock(TracedMethod.class);
AgentBridge.TokenAndRefCount instance = new AgentBridge.TokenAndRefCount(mockToken, mockTracedMethod, new AtomicInteger(1));

assertEquals(mockToken, instance.token);
assertEquals(mockTracedMethod, instance.tracedMethod.get());
assertEquals(1, instance.refCount.get());

instance = new AgentBridge.TokenAndRefCount(null, mockTracedMethod, new AtomicInteger(1));
assertEquals(NoOpToken.INSTANCE, instance.token);

// Just to get a coverage hit
ThreadLocal<AgentBridge.TokenAndRefCount> dummy = AgentBridge.activeToken;


}
}
4 changes: 1 addition & 3 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ sourceCompatibility = 1.8
repositories {
mavenLocal()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
gradlePluginPortal()
}

dependencies {
Expand Down
4 changes: 0 additions & 4 deletions functional_test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ jar {
manifest { attributes 'Premain-Class': 'com.newrelic.agent.test.agent.FunctionalAgent' }
}

repositories {
mavenCentral()
}

dependencies {
implementation(project(":agent-bridge"))
implementation(project(":agent-bridge-datastore"))
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The agent version.
agentVersion=8.5.0
securityAgentVersion=1.0.3-limited-preview
securityAgentVersion=1.0.4-public-preview

newrelicDebug=false
org.gradle.jvmargs=-Xmx2048m
Expand Down
12 changes: 11 additions & 1 deletion gradle/script/java.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ jacocoTestReport {
'com/newrelic/agent/jmx/metrics/*Generator.class',
'com/newrelic/agent/jmx/metrics/*Generator$*.class',
'com/newrelic/agent/bridge/external/ExternalParametersFactory.class',
'com/newrelic/agent/instrumentation/tracing/TraceDetailsBuilder*.class',
'com/newrelic/agent/model/ApdexPerfZone.class',
'com/newrelic/agent/model/CountedDuration.class',
'com/newrelic/agent/model/PathHashes.class',
Expand All @@ -253,7 +254,16 @@ jacocoTestReport {
'com/newrelic/weave/verification/*.class',
'com/newrelic/agent/bridge/datastore/DatastoreMetrics.class',
'com/newrelic/api/agent/ApplicationNamePriority.class',
'com/newrelic/agent/bridge/TransactionNamePriority'
'com/newrelic/agent/bridge/TransactionNamePriority.class',
'com/newrelic/weave/utils/Synchronized*.class',
'com/newrelic/agent/tracers/UltraLightTracer.class',
'com/newrelic/agent/core/CoreServiceImpl.class',
'com/newrelic/agent/Deployments.class',
'com/newrelic/agent/LifecycleObserver$*.class',
'com/newrelic/agent/LifecycleObserver.class',
'com/newrelic/agent/InitProblemClasses.class',
'com/newrelic/agent/reinstrument/ReinstrumentUtils.class',
'com/newrelic/agent/AsyncApiImpl.class'
])
}))
}
Expand Down
4 changes: 0 additions & 4 deletions instrumentation-test/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
evaluationDependsOn(":newrelic-agent")

repositories {
mavenCentral()
}

dependencies {
// Instrumentation-test (this project) serves as a consolidation point for
// multiple types of dependencies. Beyond the introspector, many of these dependencies
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package com.newrelic.agent.introspec.internal;

import com.newrelic.agent.introspec.Event;
import org.junit.Test;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

public class IntrospectorInsightsServiceTest {
@Test
public void getName_returnsServiceName() {
IntrospectorInsightsService introspectorInsightsService = new IntrospectorInsightsService();
assertEquals("InsightsService", introspectorInsightsService.getName());
}

@Test
public void controlMethods_behaveProperly() throws Exception {
IntrospectorInsightsService introspectorInsightsService = new IntrospectorInsightsService();

introspectorInsightsService.start(); //No op
introspectorInsightsService.stop(); //No op

assertTrue(introspectorInsightsService.isEnabled());
assertTrue(introspectorInsightsService.isStarted());
assertTrue(introspectorInsightsService.isStartedOrStarting());
assertFalse(introspectorInsightsService.isStopped());
assertFalse(introspectorInsightsService.isStoppedOrStopping());
}

@Test
public void getLogger_returnsLoggerInstance() {
IntrospectorInsightsService introspectorInsightsService = new IntrospectorInsightsService();

assertNotNull(introspectorInsightsService.getLogger());
}

@Test
public void recordCustomEvent_storeSuppliedLogEvent() {
IntrospectorInsightsService introspectorInsightsService = new IntrospectorInsightsService();
Map<String, String> attributes = new HashMap<>();
attributes.put("key1", "val1");
attributes.put("key2", "val2");

introspectorInsightsService.recordCustomEvent("event", attributes);
Collection<Event> events = introspectorInsightsService.getEvents("event");

assertEquals(1, events.size());
assertEquals(2, events.iterator().next().getAttributes().size());
}

@Test
public void getEventTypes_returnsStoredEventTypes() {
IntrospectorInsightsService introspectorInsightsService = new IntrospectorInsightsService();
Map<String, String> attributes = new HashMap<>();

introspectorInsightsService.recordCustomEvent("event", attributes);
introspectorInsightsService.recordCustomEvent("event2", attributes);
Collection<String> events = introspectorInsightsService.getEventTypes();

assertEquals(2, events.size());
assertTrue(events.contains("event"));
assertTrue(events.contains("event2"));
}

@Test
public void clearMethods_clearEventReservoir() {
IntrospectorInsightsService introspectorInsightsService = new IntrospectorInsightsService();
Map<String, String> attributes = new HashMap<>();

introspectorInsightsService.recordCustomEvent("event", attributes);
Collection<Event> events = introspectorInsightsService.getEvents("event");
assertEquals(1, events.size());

introspectorInsightsService.clear();
events = introspectorInsightsService.getEvents("event");
assertEquals(0, events.size());

introspectorInsightsService.recordCustomEvent("event", attributes);
events = introspectorInsightsService.getEvents("event");
assertEquals(1, events.size());

introspectorInsightsService.clearReservoir();
events = introspectorInsightsService.getEvents("event");
assertEquals(0, events.size());
}

@Test
public void getEventHarvestIntervalMetric_returnsEmptyString() {
IntrospectorInsightsService introspectorInsightsService = new IntrospectorInsightsService();
assertEquals("", introspectorInsightsService.getEventHarvestIntervalMetric());
}

@Test
public void getReportPeriodInSecondsMetric_returnsEmptyString() {
IntrospectorInsightsService introspectorInsightsService = new IntrospectorInsightsService();
assertEquals("", introspectorInsightsService.getReportPeriodInSecondsMetric());
}

@Test
public void getEventHarvestLimitMetric_returnsEmptyString() {
IntrospectorInsightsService introspectorInsightsService = new IntrospectorInsightsService();
assertEquals("", introspectorInsightsService.getEventHarvestLimitMetric());
}

@Test
public void getMaxSamplesStored_returnsZero() {
IntrospectorInsightsService introspectorInsightsService = new IntrospectorInsightsService();
assertEquals(0, introspectorInsightsService.getMaxSamplesStored());
}
}
Loading

0 comments on commit 4bbce54

Please sign in to comment.