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-287771] API Endpoint and Route detection Support for Vert.x Framework #302

Merged
merged 8 commits into from
Aug 9, 2024
5 changes: 4 additions & 1 deletion instrumentation-security/vertx-core-3.3.0/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ dependencies {
implementation("com.newrelic.agent.java:newrelic-api:${nrAPIVersion}")
implementation("com.newrelic.agent.java:newrelic-weaver-api:${nrAPIVersion}")
implementation("io.vertx:vertx-core:3.3.0")
implementation("io.vertx:vertx-web:3.3.0")
}

jar {
manifest { attributes 'Implementation-Title': 'com.newrelic.instrumentation.security.vertx-core-3.3.0' }
}

verifyInstrumentation {
passesOnly 'io.vertx:vertx-core:[3.3.0,3.4.0)'
passesOnly ('io.vertx:vertx-core:[3.3.0,3.4.0)') {
implementation("io.vertx:vertx-web:3.3.0")
}
excludeRegex '.*(milestone|CR|Beta)[0-9]*'
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.vertx.core.http;

import com.newrelic.api.agent.security.NewRelicSecurity;
import com.newrelic.api.agent.security.instrumentation.helpers.GenericHelper;
import com.newrelic.api.agent.security.instrumentation.helpers.VertxApiEndpointUtils;
import com.newrelic.api.agent.security.utils.logging.LogLevel;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;
import io.vertx.core.Handler;

@Weave(originalName = "io.vertx.core.http.HttpServer", type = MatchType.Interface)
public class HttpServer_Instrumentation {

public HttpServer_Instrumentation requestHandler(Handler<HttpServerRequest> handler){
HttpServer_Instrumentation server = Weaver.callOriginal();
try {
VertxApiEndpointUtils.getInstance().generateAPIEndpoints(handler.hashCode());
} catch (Exception e){
NewRelicSecurity.getAgent().log(LogLevel.WARNING, String.format(GenericHelper.ERROR_WHILE_GETTING_APP_ENDPOINTS, "VERTX-CORE-3.3.0", e.getMessage()), e, VertxApiEndpointUtils.class.getName());
}
return server;
}

}
5 changes: 4 additions & 1 deletion instrumentation-security/vertx-core-3.4.0/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ dependencies {
implementation("com.newrelic.agent.java:newrelic-api:${nrAPIVersion}")
implementation("com.newrelic.agent.java:newrelic-weaver-api:${nrAPIVersion}")
implementation("io.vertx:vertx-core:3.4.0")
implementation("io.vertx:vertx-web:3.4.0")
testImplementation('io.vertx:vertx-web-client:3.4.0')
}

Expand All @@ -11,7 +12,9 @@ jar {
}

verifyInstrumentation {
passesOnly 'io.vertx:vertx-core:[3.4.0,3.7.1)'
passesOnly ('io.vertx:vertx-core:[3.4.0,3.7.1)'){
implementation("io.vertx:vertx-web:3.4.0")
}
excludeRegex '.*CR[0-9]*'
excludeRegex '.*-milestone[0-9]'
excludeRegex '.*Beta[0-9]'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.vertx.core.http;

import com.newrelic.api.agent.security.NewRelicSecurity;
import com.newrelic.api.agent.security.instrumentation.helpers.GenericHelper;
import com.newrelic.api.agent.security.instrumentation.helpers.VertxApiEndpointUtils;
import com.newrelic.api.agent.security.utils.logging.LogLevel;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;
import io.vertx.core.Handler;


@Weave(originalName = "io.vertx.core.http.HttpServer", type = MatchType.Interface)
public class HttpServer_Instrumentation {

public HttpServer_Instrumentation requestHandler(Handler<HttpServerRequest> handler){
HttpServer_Instrumentation server = Weaver.callOriginal();
try {
VertxApiEndpointUtils.getInstance().generateAPIEndpoints(handler.hashCode());
} catch (Exception e){
NewRelicSecurity.getAgent().log(LogLevel.WARNING, String.format(GenericHelper.ERROR_WHILE_GETTING_APP_ENDPOINTS, "VERTX-CORE-3.4.0", e.getMessage()), e, VertxApiEndpointUtils.class.getName());
}
return server;
}

}
5 changes: 4 additions & 1 deletion instrumentation-security/vertx-core-3.7.1/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ dependencies {
implementation("com.newrelic.agent.java:newrelic-api:${nrAPIVersion}")
implementation("com.newrelic.agent.java:newrelic-weaver-api:${nrAPIVersion}")
implementation("io.vertx:vertx-core:3.7.1")
implementation("io.vertx:vertx-web:3.7.1")
testImplementation('io.vertx:vertx-web-client:3.7.1')
}

verifyInstrumentation {
passesOnly 'io.vertx:vertx-core:[3.7.1,4.0.0.Beta1)'
passesOnly ('io.vertx:vertx-core:[3.7.1,4.0.0.Beta1)') {
implementation('io.vertx:vertx-web:3.7.1')
}
excludeRegex '.*CR[0-9]*'
excludeRegex '.*-milestone[0-9]'
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.vertx.core.http;

import com.newrelic.api.agent.security.NewRelicSecurity;
import com.newrelic.api.agent.security.instrumentation.helpers.GenericHelper;
import com.newrelic.api.agent.security.instrumentation.helpers.VertxApiEndpointUtils;
import com.newrelic.api.agent.security.utils.logging.LogLevel;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;
import io.vertx.core.Handler;

@Weave(originalName = "io.vertx.core.http.HttpServer", type = MatchType.Interface)
public class HttpServer_Instrumentation {

public HttpServer_Instrumentation requestHandler(Handler<HttpServerRequest> handler){
HttpServer_Instrumentation server = Weaver.callOriginal();
try {
VertxApiEndpointUtils.getInstance().generateAPIEndpoints(handler.hashCode());
} catch (Exception e){
NewRelicSecurity.getAgent().log(LogLevel.WARNING, String.format(GenericHelper.ERROR_WHILE_GETTING_APP_ENDPOINTS, "VERTX-CORE-3.7.1", e.getMessage()), e, VertxApiEndpointUtils.class.getName());
}
return server;
}

}
5 changes: 4 additions & 1 deletion instrumentation-security/vertx-core-4.0.0/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ dependencies {
implementation("com.newrelic.agent.java:newrelic-api:${nrAPIVersion}")
implementation("com.newrelic.agent.java:newrelic-weaver-api:${nrAPIVersion}")
implementation("io.vertx:vertx-core:4.0.0")
implementation("io.vertx:vertx-web:4.0.0")
testImplementation('io.vertx:vertx-web-client:4.0.0')
}

Expand All @@ -13,7 +14,9 @@ jar {
}

verifyInstrumentation {
passesOnly 'io.vertx:vertx-core:[4.0.0,)'
passesOnly ('io.vertx:vertx-core:[4.0.0,)') {
implementation('io.vertx:vertx-web:4.0.0')
}
excludeRegex '.*CR[0-9]*'
excludeRegex '.*-milestone[0-9]'
excludeRegex '.*Beta[0-9]'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.vertx.core.http;

import com.newrelic.api.agent.security.NewRelicSecurity;
import com.newrelic.api.agent.security.instrumentation.helpers.GenericHelper;
import com.newrelic.api.agent.security.instrumentation.helpers.VertxApiEndpointUtils;
import com.newrelic.api.agent.security.utils.logging.LogLevel;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;
import io.vertx.core.Handler;



@Weave(originalName = "io.vertx.core.http.HttpServer", type = MatchType.Interface)
public class HttpServer_Instrumentation {

public HttpServer_Instrumentation requestHandler(Handler<HttpServerRequest> handler){
HttpServer_Instrumentation server = Weaver.callOriginal();
try {
VertxApiEndpointUtils.getInstance().generateAPIEndpoints(handler.hashCode());
} catch (Exception e){
NewRelicSecurity.getAgent().log(LogLevel.WARNING, String.format(GenericHelper.ERROR_WHILE_GETTING_APP_ENDPOINTS, "VERTX-CORE-4.0.0", e.getMessage()), e, VertxApiEndpointUtils.class.getName());
}
return server;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.vertx.ext.web;

import com.newrelic.api.agent.security.instrumentation.helpers.ThreadLocalLockHelper;
import com.newrelic.api.agent.security.instrumentation.helpers.VertxApiEndpointUtils;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;

@Weave(originalName = "io.vertx.ext.web.Router", type = MatchType.Interface)
public class Router_Instrumentation {

public Router_Instrumentation mountSubRouter(String mountPoint, Router subRouter) {
Router_Instrumentation result;
boolean isLockAcquired = ThreadLocalLockHelper.acquireLock();
try {
result = Weaver.callOriginal();
} finally {
if (isLockAcquired) {
ThreadLocalLockHelper.releaseLock();
}
}
VertxApiEndpointUtils.getInstance().resolveSubRoutes(this.hashCode(), subRouter.hashCode(), mountPoint);
return result;
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,80 @@
package io.vertx.ext.web.impl;

import com.newrelic.api.agent.security.NewRelicSecurity;
import com.newrelic.api.agent.security.instrumentation.helpers.GenericHelper;
import com.newrelic.api.agent.security.instrumentation.helpers.ServletHelper;
import com.newrelic.api.agent.security.instrumentation.helpers.VertxApiEndpointUtils;
import com.newrelic.api.agent.security.utils.logging.LogLevel;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;
import io.vertx.core.Handler;
import io.vertx.core.http.HttpMethod;
import io.vertx.ext.web.Route;
import io.vertx.ext.web.RoutingContext;

import java.util.regex.Pattern;

@Weave(originalName = "io.vertx.ext.web.impl.RouteImpl")
public class RouteImpl_Instrumentation {
public abstract class RouteImpl_Instrumentation {

private final RouterImpl router = Weaver.callOriginal();

private String path = Weaver.callOriginal();

private Pattern pattern = Weaver.callOriginal();

RouteImpl_Instrumentation(RouterImpl router, int order){
VertxApiEndpointUtils.getInstance().addRouteImpl(router.hashCode(), this.hashCode(), null, null, null);
}

RouteImpl_Instrumentation(RouterImpl router, int order, HttpMethod method, String path) {
VertxApiEndpointUtils.getInstance().addRouteImpl(router.hashCode(), this.hashCode(), path, null, method.name());
}

RouteImpl_Instrumentation(RouterImpl router, int order, String path) {
VertxApiEndpointUtils.getInstance().addRouteImpl(router.hashCode(), this.hashCode(), path, null, null);
}

RouteImpl_Instrumentation(RouterImpl router, int order, HttpMethod method, String regex, boolean bregex) {
VertxApiEndpointUtils.getInstance().addRouteImpl(router.hashCode(), this.hashCode(), null, regex, method.name());
}

RouteImpl_Instrumentation(RouterImpl router, int order, String regex, boolean bregex) {
VertxApiEndpointUtils.getInstance().addRouteImpl(router.hashCode(), this.hashCode(), null, regex, null);
}

synchronized void handleContext(RoutingContext context) {
try {
VertxApiEndpointUtils.getInstance().generateAPIEndpointsIfNotPresent(this.hashCode());
VertxApiEndpointUtils.getInstance().routeDetection(path, pattern);
} catch (Exception e) {
NewRelicSecurity.getAgent().log(LogLevel.WARNING, String.format(GenericHelper.ERROR_WHILE_GETTING_ROUTE_FOR_INCOMING_REQUEST, "VERTX-WEB-3.2.0", e.getMessage()), e, this.getClass().getName());
}
ServletHelper.registerUserLevelCode("vertx-web");
Weaver.callOriginal();
}

public synchronized Route method(HttpMethod method) {
Route route = Weaver.callOriginal();
VertxApiEndpointUtils.getInstance().addRouteImpl(router.hashCode(), this.hashCode(), null, null, method.name());
return route;
}

public synchronized Route path(String path) {
Route route = Weaver.callOriginal();
VertxApiEndpointUtils.getInstance().addRouteImpl(router.hashCode(), this.hashCode(), path, null, null);
return route;
}

public synchronized Route pathRegex(String regex) {
Route route = Weaver.callOriginal();
VertxApiEndpointUtils.getInstance().addRouteImpl(router.hashCode(), this.hashCode(), null, regex, null);
return route;
}

public synchronized Route handler(Handler<RoutingContext> contextHandler){
Route route = Weaver.callOriginal();
VertxApiEndpointUtils.getInstance().addHandlerClass(router.hashCode(), this.hashCode(), contextHandler.getClass().getName());
return route;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.vertx.ext.web;

import com.newrelic.api.agent.security.instrumentation.helpers.ThreadLocalLockHelper;
import com.newrelic.api.agent.security.instrumentation.helpers.VertxApiEndpointUtils;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;

@Weave(originalName = "io.vertx.ext.web.Router", type = MatchType.Interface)
public class Router_Instrumentation {

public Router_Instrumentation mountSubRouter(String mountPoint, Router subRouter) {
Router_Instrumentation result;
boolean isLockAcquired = ThreadLocalLockHelper.acquireLock();
try {
result = Weaver.callOriginal();
} finally {
if (isLockAcquired) {
ThreadLocalLockHelper.releaseLock();
}
}
VertxApiEndpointUtils.getInstance().resolveSubRoutes(this.hashCode(), subRouter.hashCode(), mountPoint);
return result;
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,81 @@
package io.vertx.ext.web.impl;

import com.newrelic.api.agent.security.NewRelicSecurity;
import com.newrelic.api.agent.security.instrumentation.helpers.GenericHelper;
import com.newrelic.api.agent.security.instrumentation.helpers.ServletHelper;
import com.newrelic.api.agent.security.instrumentation.helpers.VertxApiEndpointUtils;
import com.newrelic.api.agent.security.schema.Framework;
import com.newrelic.api.agent.security.utils.logging.LogLevel;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;
import io.vertx.core.Handler;
import io.vertx.core.http.HttpMethod;
import io.vertx.ext.web.Route;
import io.vertx.ext.web.RoutingContext;

import java.util.regex.Pattern;

@Weave(originalName = "io.vertx.ext.web.impl.RouteImpl")
public class RouteImpl_Instrumentation {

private final RouterImpl router = Weaver.callOriginal();

private String path = Weaver.callOriginal();

private Pattern pattern = Weaver.callOriginal();

RouteImpl_Instrumentation(RouterImpl router, int order){
VertxApiEndpointUtils.getInstance().addRouteImpl(router.hashCode(), this.hashCode(), null, null, null);
}

RouteImpl_Instrumentation(RouterImpl router, int order, HttpMethod method, String path) {
VertxApiEndpointUtils.getInstance().addRouteImpl(router.hashCode(), this.hashCode(), path, null, method.name());
}

RouteImpl_Instrumentation(RouterImpl router, int order, String path) {
VertxApiEndpointUtils.getInstance().addRouteImpl(router.hashCode(), this.hashCode(), path, null, null);
}

RouteImpl_Instrumentation(RouterImpl router, int order, HttpMethod method, String regex, boolean bregex) {
VertxApiEndpointUtils.getInstance().addRouteImpl(router.hashCode(), this.hashCode(), null, regex, method.name());
}

RouteImpl_Instrumentation(RouterImpl router, int order, String regex, boolean bregex) {
VertxApiEndpointUtils.getInstance().addRouteImpl(router.hashCode(), this.hashCode(), null, regex, null);
}

void handleContext(RoutingContextImplBase context) {
try {
VertxApiEndpointUtils.getInstance().generateAPIEndpointsIfNotPresent(this.hashCode());
VertxApiEndpointUtils.getInstance().routeDetection(path, pattern);
} catch (Exception e) {
NewRelicSecurity.getAgent().log(LogLevel.WARNING, String.format(GenericHelper.ERROR_WHILE_GETTING_ROUTE_FOR_INCOMING_REQUEST, "VERTX-WEB-3.5.1", e.getMessage()), e, this.getClass().getName());
}
ServletHelper.registerUserLevelCode("vertx-web");
Weaver.callOriginal();
}

public synchronized Route method(HttpMethod method) {
Route route = Weaver.callOriginal();
VertxApiEndpointUtils.getInstance().addRouteImpl(router.hashCode(), this.hashCode(), null, null, method.name());
return route;
}

public synchronized Route path(String path) {
Route route = Weaver.callOriginal();
VertxApiEndpointUtils.getInstance().addRouteImpl(router.hashCode(), this.hashCode(), path, null, null);
return route;
}

public synchronized Route pathRegex(String regex) {
Route route = Weaver.callOriginal();
VertxApiEndpointUtils.getInstance().addRouteImpl(router.hashCode(), this.hashCode(), null, regex, null);
return route;
}

public synchronized Route handler(Handler<RoutingContext> contextHandler){
Route route = Weaver.callOriginal();
VertxApiEndpointUtils.getInstance().addHandlerClass(router.hashCode(), this.hashCode(), contextHandler.getClass().getName());
return route;
}
}
Loading
Loading