Skip to content

Commit 08b06c7

Browse files
authored
Merge pull request #322 from newrelic/enhancments/endpoint-report-NR-287324
NR-287324: Report API endpoints immediately after 60 seconds
2 parents b2b8f7a + c361033 commit 08b06c7

File tree

8 files changed

+26
-3
lines changed

8 files changed

+26
-3
lines changed

newrelic-security-agent/src/main/java/com/newrelic/agent/security/instrumentator/utils/AgentUtils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,6 @@ private void applyNRPolicyOverride() {
651651

652652

653653
public static void sendApplicationURLMappings() {
654-
//TODO mappings to be send once new mappings are discovered, after startup.
655654
ApplicationURLMappings applicationURLMappings = new ApplicationURLMappings(URLMappingsHelper.getApplicationURLMappings());
656655
applicationURLMappings.setApplicationUUID(AgentInfo.getInstance().getApplicationUUID());
657656
logger.logInit(LogLevel.INFO, String.format("Collected application url mappings %s", applicationURLMappings), Agent.class.getName());

newrelic-security-agent/src/main/java/com/newrelic/agent/security/intcodeagent/schedulers/SchedulerHelper.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,12 @@ public ScheduledFuture<?> scheduleDailyLogRollover(Runnable command) {
9595
return null;
9696
}
9797

98+
public void scheduleURLMappingPosting(Runnable runnable) {
99+
if(scheduledFutureMap.containsKey(IAgentConstants.JSON_SEC_APPLICATION_URL_MAPPING)){
100+
ScheduledFuture<?> future = scheduledFutureMap.get(IAgentConstants.JSON_SEC_APPLICATION_URL_MAPPING);
101+
future.cancel(false);
102+
}
103+
ScheduledFuture<?> future = commonExecutor.schedule(runnable, 60, TimeUnit.SECONDS);
104+
scheduledFutureMap.put(IAgentConstants.JSON_SEC_APPLICATION_URL_MAPPING, future);
105+
}
98106
}

newrelic-security-agent/src/main/java/com/newrelic/agent/security/intcodeagent/websocket/WSClient.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ public void onOpen(ServerHandshake handshakedata) {
264264
WSUtils.getInstance().notifyAll();
265265
}
266266
WSUtils.getInstance().setConnected(true);
267-
AgentUtils.sendApplicationURLMappings();
268267
logger.logInit(LogLevel.INFO, String.format(IAgentConstants.APPLICATION_INFO_SENT_ON_WS_CONNECT, AgentInfo.getInstance().getApplicationInfo()), WSClient.class.getName());
269268
}
270269

newrelic-security-agent/src/main/java/com/newrelic/api/agent/security/Agent.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,4 +1095,9 @@ public boolean recordExceptions(SecurityMetaData securityMetaData, Throwable exc
10951095
return RuntimeErrorReporter.getInstance().addApplicationRuntimeError(applicationRuntimeError);
10961096
}
10971097

1098+
@Override
1099+
public void reportURLMapping() {
1100+
SchedulerHelper.getInstance().scheduleURLMappingPosting(AgentUtils::sendApplicationURLMappings);
1101+
}
1102+
10981103
}

newrelic-security-api-test-impl/src/main/java/com/newrelic/api/agent/security/Agent.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,9 @@ public void reportApplicationRuntimeError(SecurityMetaData securityMetaData, Thr
218218
public boolean recordExceptions(SecurityMetaData securityMetaData, Throwable exception) {
219219
return false;
220220
}
221+
222+
@Override
223+
public void reportURLMapping() {
224+
225+
}
221226
}

newrelic-security-api/src/main/java/com/newrelic/api/agent/security/NoOpAgent.java

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

88
package com.newrelic.api.agent.security;
99

10-
import com.newrelic.api.agent.security.instrumentation.helpers.LowSeverityHelper;
1110
import com.newrelic.api.agent.security.schema.AbstractOperation;
1211
import com.newrelic.api.agent.security.schema.SecurityMetaData;
1312
import com.newrelic.api.agent.security.schema.ServerConnectionConfiguration;
@@ -149,5 +148,9 @@ public boolean recordExceptions(SecurityMetaData securityMetaData, Throwable exc
149148
return false;
150149
}
151150

151+
@Override
152+
public void reportURLMapping() {
153+
154+
}
152155

153156
}

newrelic-security-api/src/main/java/com/newrelic/api/agent/security/SecurityAgent.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,6 @@ void reportIASTScanFailure(SecurityMetaData securityMetaData, String apiId, Thro
7878
void reportApplicationRuntimeError(SecurityMetaData securityMetaData, Throwable exception);
7979

8080
boolean recordExceptions(SecurityMetaData securityMetaData, Throwable exception);
81+
82+
void reportURLMapping();
8183
}

newrelic-security-api/src/main/java/com/newrelic/api/agent/security/instrumentation/helpers/URLMappingsHelper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.newrelic.api.agent.security.instrumentation.helpers;
22

3+
import com.newrelic.api.agent.security.NewRelicSecurity;
34
import com.newrelic.api.agent.security.schema.ApplicationURLMapping;
45
import com.newrelic.api.agent.security.schema.RouteSegment;
56
import com.newrelic.api.agent.security.schema.RouteSegments;
@@ -63,6 +64,7 @@ public static void addApplicationURLMapping(ApplicationURLMapping mapping) {
6364
if (mapping.getHandler() != null){
6465
handlers.add(mapping.getHandler().hashCode());
6566
}
67+
NewRelicSecurity.getAgent().reportURLMapping();
6668
}
6769

6870
private synchronized static void generateRouteSegments(String endpoint) {

0 commit comments

Comments
 (0)