Skip to content

Commit

Permalink
Merge pull request #322 from newrelic/enhancments/endpoint-report-NR-…
Browse files Browse the repository at this point in the history
…287324

NR-287324: Report API endpoints immediately after 60 seconds
  • Loading branch information
IshikaDawda authored Sep 20, 2024
2 parents b2b8f7a + c361033 commit 08b06c7
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,6 @@ private void applyNRPolicyOverride() {


public static void sendApplicationURLMappings() {
//TODO mappings to be send once new mappings are discovered, after startup.
ApplicationURLMappings applicationURLMappings = new ApplicationURLMappings(URLMappingsHelper.getApplicationURLMappings());
applicationURLMappings.setApplicationUUID(AgentInfo.getInstance().getApplicationUUID());
logger.logInit(LogLevel.INFO, String.format("Collected application url mappings %s", applicationURLMappings), Agent.class.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,12 @@ public ScheduledFuture<?> scheduleDailyLogRollover(Runnable command) {
return null;
}

public void scheduleURLMappingPosting(Runnable runnable) {
if(scheduledFutureMap.containsKey(IAgentConstants.JSON_SEC_APPLICATION_URL_MAPPING)){
ScheduledFuture<?> future = scheduledFutureMap.get(IAgentConstants.JSON_SEC_APPLICATION_URL_MAPPING);
future.cancel(false);
}
ScheduledFuture<?> future = commonExecutor.schedule(runnable, 60, TimeUnit.SECONDS);
scheduledFutureMap.put(IAgentConstants.JSON_SEC_APPLICATION_URL_MAPPING, future);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ public void onOpen(ServerHandshake handshakedata) {
WSUtils.getInstance().notifyAll();
}
WSUtils.getInstance().setConnected(true);
AgentUtils.sendApplicationURLMappings();
logger.logInit(LogLevel.INFO, String.format(IAgentConstants.APPLICATION_INFO_SENT_ON_WS_CONNECT, AgentInfo.getInstance().getApplicationInfo()), WSClient.class.getName());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1095,4 +1095,9 @@ public boolean recordExceptions(SecurityMetaData securityMetaData, Throwable exc
return RuntimeErrorReporter.getInstance().addApplicationRuntimeError(applicationRuntimeError);
}

@Override
public void reportURLMapping() {
SchedulerHelper.getInstance().scheduleURLMappingPosting(AgentUtils::sendApplicationURLMappings);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,9 @@ public void reportApplicationRuntimeError(SecurityMetaData securityMetaData, Thr
public boolean recordExceptions(SecurityMetaData securityMetaData, Throwable exception) {
return false;
}

@Override
public void reportURLMapping() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

package com.newrelic.api.agent.security;

import com.newrelic.api.agent.security.instrumentation.helpers.LowSeverityHelper;
import com.newrelic.api.agent.security.schema.AbstractOperation;
import com.newrelic.api.agent.security.schema.SecurityMetaData;
import com.newrelic.api.agent.security.schema.ServerConnectionConfiguration;
Expand Down Expand Up @@ -149,5 +148,9 @@ public boolean recordExceptions(SecurityMetaData securityMetaData, Throwable exc
return false;
}

@Override
public void reportURLMapping() {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,6 @@ void reportIASTScanFailure(SecurityMetaData securityMetaData, String apiId, Thro
void reportApplicationRuntimeError(SecurityMetaData securityMetaData, Throwable exception);

boolean recordExceptions(SecurityMetaData securityMetaData, Throwable exception);

void reportURLMapping();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.newrelic.api.agent.security.instrumentation.helpers;

import com.newrelic.api.agent.security.NewRelicSecurity;
import com.newrelic.api.agent.security.schema.ApplicationURLMapping;
import com.newrelic.api.agent.security.schema.RouteSegment;
import com.newrelic.api.agent.security.schema.RouteSegments;
Expand Down Expand Up @@ -63,6 +64,7 @@ public static void addApplicationURLMapping(ApplicationURLMapping mapping) {
if (mapping.getHandler() != null){
handlers.add(mapping.getHandler().hashCode());
}
NewRelicSecurity.getAgent().reportURLMapping();
}

private synchronized static void generateRouteSegments(String endpoint) {
Expand Down

0 comments on commit 08b06c7

Please sign in to comment.