Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NR-287324: Report API endpoints immediately after 60 seconds #322

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,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 @@ -86,4 +86,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 @@ -257,7 +257,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 @@ -956,4 +956,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 @@ -211,4 +211,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 @@ -142,5 +141,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 @@ -75,4 +75,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
Loading