Skip to content

Commit c361033

Browse files
committed
NR-287324: Report API endpoints immediately after 60 seconds, as soon as new endpoints are discovered
1 parent 4b64b6a commit c361033

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
@@ -667,7 +667,6 @@ private void applyNRPolicyOverride() {
667667

668668

669669
public static void sendApplicationURLMappings() {
670-
//TODO mappings to be send once new mappings are discovered, after startup.
671670
ApplicationURLMappings applicationURLMappings = new ApplicationURLMappings(URLMappingsHelper.getApplicationURLMappings());
672671
applicationURLMappings.setApplicationUUID(AgentInfo.getInstance().getApplicationUUID());
673672
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
@@ -86,4 +86,12 @@ public ScheduledFuture<?> scheduleDailyLogRollover(Runnable command) {
8686
return null;
8787
}
8888

89+
public void scheduleURLMappingPosting(Runnable runnable) {
90+
if(scheduledFutureMap.containsKey(IAgentConstants.JSON_SEC_APPLICATION_URL_MAPPING)){
91+
ScheduledFuture<?> future = scheduledFutureMap.get(IAgentConstants.JSON_SEC_APPLICATION_URL_MAPPING);
92+
future.cancel(false);
93+
}
94+
ScheduledFuture<?> future = commonExecutor.schedule(runnable, 60, TimeUnit.SECONDS);
95+
scheduledFutureMap.put(IAgentConstants.JSON_SEC_APPLICATION_URL_MAPPING, future);
96+
}
8997
}

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
@@ -257,7 +257,6 @@ public void onOpen(ServerHandshake handshakedata) {
257257
WSUtils.getInstance().notifyAll();
258258
}
259259
WSUtils.getInstance().setConnected(true);
260-
AgentUtils.sendApplicationURLMappings();
261260
logger.logInit(LogLevel.INFO, String.format(IAgentConstants.APPLICATION_INFO_SENT_ON_WS_CONNECT, AgentInfo.getInstance().getApplicationInfo()), WSClient.class.getName());
262261
}
263262

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
@@ -956,4 +956,9 @@ public boolean recordExceptions(SecurityMetaData securityMetaData, Throwable exc
956956
return RuntimeErrorReporter.getInstance().addApplicationRuntimeError(applicationRuntimeError);
957957
}
958958

959+
@Override
960+
public void reportURLMapping() {
961+
SchedulerHelper.getInstance().scheduleURLMappingPosting(AgentUtils::sendApplicationURLMappings);
962+
}
963+
959964
}

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
@@ -211,4 +211,9 @@ public void reportApplicationRuntimeError(SecurityMetaData securityMetaData, Thr
211211
public boolean recordExceptions(SecurityMetaData securityMetaData, Throwable exception) {
212212
return false;
213213
}
214+
215+
@Override
216+
public void reportURLMapping() {
217+
218+
}
214219
}

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;
@@ -142,5 +141,9 @@ public boolean recordExceptions(SecurityMetaData securityMetaData, Throwable exc
142141
return false;
143142
}
144143

144+
@Override
145+
public void reportURLMapping() {
146+
147+
}
145148

146149
}

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
@@ -75,4 +75,6 @@ void reportIASTScanFailure(SecurityMetaData securityMetaData, String apiId, Thro
7575
void reportApplicationRuntimeError(SecurityMetaData securityMetaData, Throwable exception);
7676

7777
boolean recordExceptions(SecurityMetaData securityMetaData, Throwable exception);
78+
79+
void reportURLMapping();
7880
}

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)