Skip to content

Commit

Permalink
remove akka-http-core bindAndHandle instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-gibson committed May 12, 2022
1 parent 53ca2a3 commit f286fb0
Show file tree
Hide file tree
Showing 36 changed files with 287 additions and 618 deletions.
2 changes: 0 additions & 2 deletions instrumentation/akka-http-core-10.0/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ dependencies {
implementation("org.scala-lang:scala-library:2.11.12")
implementation("com.typesafe.akka:akka-http-core_2.11:10.0.0")
implementation("com.typesafe.akka:akka-actor_2.11:2.3.14")
testImplementation("com.typesafe.akka:akka-http-spray-json_2.11:10.0.0")
testImplementation("com.typesafe.akka:akka-http_2.11:10.0.0")
}

verifyInstrumentation {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
import akka.http.scaladsl.settings.ConnectionPoolSettings;
import akka.http.scaladsl.settings.ServerSettings;
import akka.stream.Materializer;
import akka.stream.scaladsl.Flow;
import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Segment;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.NewField;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;
import com.nr.instrumentation.akkahttpcore.AkkaHttpUtils;
Expand All @@ -27,58 +25,42 @@
@Weave(type = MatchType.ExactClass, originalName = "akka.http.scaladsl.HttpExt")
public class HttpExtInstrumentation {

@NewField
public boolean bindingInstrumented;
public Future<HttpInstrumentation.ServerBinding> bindAndHandleAsync(
Function1<HttpRequest, Future<HttpResponse>> handler,
String interfaceString, int port,
ConnectionContext connectionContext,
ServerSettings settings, int parallelism,
LoggingAdapter adapter, Materializer mat) {

public Future<HttpInstrumentation.ServerBinding> bindAndHandleAsync(
Function1<HttpRequest, Future<HttpResponse>> handler,
String interfaceString, int port,
ConnectionContext connectionContext,
ServerSettings settings, int parallelism,
LoggingAdapter adapter, Materializer mat) {
AsyncRequestHandler wrapperHandler = new AsyncRequestHandler(handler, mat.executionContext());
handler = wrapperHandler;

AsyncRequestHandler wrapperHandler = new AsyncRequestHandler(handler, mat.executionContext());
handler = wrapperHandler;
bindingInstrumented = true;
return Weaver.callOriginal();
}

public Future<HttpInstrumentation.ServerBinding> bindAndHandleSync(
Function1<HttpRequest, HttpResponse> handler,
String interfaceString, int port,
ConnectionContext connectionContext,
ServerSettings settings,
LoggingAdapter adapter, Materializer mat) {

SyncRequestHandler wrapperHandler = new SyncRequestHandler(handler);
handler = wrapperHandler;
bindingInstrumented = true;
return Weaver.callOriginal();
}

return Weaver.callOriginal();
}
public Future<HttpInstrumentation.ServerBinding> bindAndHandleSync(
Function1<HttpRequest, HttpResponse> handler,
String interfaceString, int port,
ConnectionContext connectionContext,
ServerSettings settings,
LoggingAdapter adapter, Materializer mat) {

public Future<HttpInstrumentation.ServerBinding> bindAndHandle(
Flow<HttpRequest, HttpResponse, Object> handler,
String _interface,
int port, ConnectionContext connectionContext,
ServerSettings settings, LoggingAdapter log, Materializer fm) {
SyncRequestHandler wrapperHandler = new SyncRequestHandler(handler);
handler = wrapperHandler;

if (!bindingInstrumented) {
handler = new FlowRequestHandler().instrumentFlow(handler, fm);
return Weaver.callOriginal();
}
return Weaver.callOriginal();
}

// We are weaving the singleRequestImpl method here rather than just singleRequest because the javadsl only flows through here
public Future<HttpResponse> singleRequest(HttpRequest httpRequest, HttpsConnectionContext connectionContext, ConnectionPoolSettings settings,
LoggingAdapter log, Materializer fm) {
final Segment segment = NewRelic.getAgent().getTransaction().startSegment("Akka", "singleRequest");
// We are weaving the singleRequestImpl method here rather than just singleRequest because the javadsl only flows through here
public Future<HttpResponse> singleRequest(HttpRequest httpRequest, HttpsConnectionContext connectionContext, ConnectionPoolSettings settings,
LoggingAdapter log, Materializer fm) {
final Segment segment = NewRelic.getAgent().getTransaction().startSegment("Akka", "singleRequest");

Future<HttpResponse> responseFuture = Weaver.callOriginal();
Future<HttpResponse> responseFuture = Weaver.callOriginal();

AkkaHttpUtils.finishSegmentOnComplete(httpRequest, responseFuture, segment);
AkkaHttpUtils.finishSegmentOnComplete(httpRequest, responseFuture, segment);

return responseFuture;
}
return responseFuture;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.WeaveAllConstructors;
import com.newrelic.api.agent.weaver.Weaver;
import scala.Function0;
import scala.concurrent.Future;
import scala.runtime.BoxedUnit;

import java.net.InetSocketAddress;
import java.util.logging.Level;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import akka.http.scaladsl.model.HttpRequest;
import akka.http.scaladsl.model.HttpResponse;
import akka.stream.Materializer;
import akka.stream.scaladsl.Flow;
import com.newrelic.api.agent.weaver.NewField;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;
import scala.Function1;
Expand All @@ -20,30 +18,21 @@
@Weave(originalName = "akka.http.scaladsl.Http$IncomingConnection")
public class IncomingConnection {

@NewField
public boolean bindingInstrumented;
public void handleWithSyncHandler(Function1<HttpRequest, HttpResponse> func, Materializer mat) {

public void handleWithSyncHandler(Function1<HttpRequest, HttpResponse> func, Materializer mat) {
SyncRequestHandler wrapperHandler = new SyncRequestHandler(func);
bindingInstrumented = true;
SyncRequestHandler wrapperHandler = new SyncRequestHandler(func);
func = wrapperHandler;

func = wrapperHandler;
Weaver.callOriginal();
}
Weaver.callOriginal();
}

public void handleWithAsyncHandler(Function1<HttpRequest, Future<HttpResponse>> func, int parallel, Materializer mat) {
AsyncRequestHandler wrapperHandler = new AsyncRequestHandler(func, mat.executionContext());
bindingInstrumented = true;
public void handleWithAsyncHandler(Function1<HttpRequest, Future<HttpResponse>> func, int parallel, Materializer mat) {

func = wrapperHandler;
Weaver.callOriginal();
}
AsyncRequestHandler wrapperHandler = new AsyncRequestHandler(func, mat.executionContext());
func = wrapperHandler;

public Object handleWith(Flow<HttpRequest, HttpResponse, Object> handler, final Materializer fm) {
if(!bindingInstrumented) {
handler = new FlowRequestHandler().instrumentFlow(handler, fm);
Weaver.callOriginal();
}
return Weaver.callOriginal();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -139,20 +139,6 @@ class AkkaHttpCoreTest {
Assert.assertEquals("WebTransaction/AkkaHttpCore/akkaHandler", txName)
}

@Test
def asyncHandlerPlayFlowServerTest(): Unit = {
playServer.startFromFlow(port)

Http().singleRequest(HttpRequest(uri = baseUrl + "/asyncPing"))

val introspector: Introspector = InstrumentationTestRunner.getIntrospector
awaitFinishedTx(introspector, 1)
playServer.stop()
Assert.assertEquals(1, introspector.getFinishedTransactionCount())
val txName = introspector.getTransactionNames.iterator.next
Assert.assertEquals("WebTransaction/AkkaHttpCore/akkaHandler", txName)
}

@Test
def syncHandlerAkkaServerCatTest(): Unit = {
akkaServer.start(port, async = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import akka.event.Logging
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.HttpMethods._
import akka.http.scaladsl.model._
import akka.http.scaladsl.server.Directives._
import akka.stream.ActorMaterializer
import akka.stream.scaladsl.{Source, _}
import akka.util.Timeout
Expand Down Expand Up @@ -60,19 +59,9 @@ class PlayServer() {
}, timeout.duration)
}

def startFromFlow(port: Int) = {
val routeFlow =
path("ping") {
get(onSuccess(Future("Hoops"))(complete(_)))
}

bindingFuture = Http().bindAndHandle(routeFlow, interface = "localhost", port)
Await.ready(bindingFuture, timeout.duration)
}

def stop() = {
if (bindingFuture != null) {
bindingFuture.flatMap(_.unbind()).onComplete(_ => system.terminate())
bindingFuture.flatMap(_.unbind()).onComplete(_ => system.shutdown())
}
}
}
2 changes: 0 additions & 2 deletions instrumentation/akka-http-core-10.2.0/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ dependencies {
implementation(project(":agent-bridge"))
implementation("com.typesafe.akka:akka-http-core_2.12:10.2.1")
implementation("com.typesafe.akka:akka-stream_2.12:2.6.10")
testImplementation("com.typesafe.akka:akka-http-spray-json_2.12:10.2.1")
testImplementation("com.typesafe.akka:akka-http_2.12:10.2.1")
}

verifyInstrumentation {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
import akka.http.scaladsl.settings.ConnectionPoolSettings;
import akka.http.scaladsl.settings.ServerSettings;
import akka.stream.Materializer;
import akka.stream.scaladsl.Flow;
import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Segment;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.NewField;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;
import com.nr.instrumentation.akkahttpcore.AkkaHttpUtils;
Expand All @@ -27,47 +25,31 @@
@Weave(type = MatchType.ExactClass, originalName = "akka.http.scaladsl.HttpExt")
public class HttpExtInstrumentation {

@NewField
public boolean bindingInstrumented;
public Future<HttpInstrumentation.ServerBinding> bindAndHandleAsync(
Function1<HttpRequest, Future<HttpResponse>> handler,
String interfaceString, int port,
ConnectionContext connectionContext,
ServerSettings settings, int parallelism,
LoggingAdapter adapter, Materializer mat) {

public Future<HttpInstrumentation.ServerBinding> bindAndHandleAsync(
Function1<HttpRequest, Future<HttpResponse>> handler,
String interfaceString, int port,
ConnectionContext connectionContext,
ServerSettings settings, int parallelism,
LoggingAdapter adapter, Materializer mat) {
AsyncRequestHandler wrapperHandler = new AsyncRequestHandler(handler, mat.executionContext());
handler = wrapperHandler;

AsyncRequestHandler wrapperHandler = new AsyncRequestHandler(handler, mat.executionContext());
handler = wrapperHandler;
bindingInstrumented = true;
return Weaver.callOriginal();
}

public Future<HttpInstrumentation.ServerBinding> bindAndHandleSync(
Function1<HttpRequest, HttpResponse> handler,
String interfaceString, int port,
ConnectionContext connectionContext,
ServerSettings settings,
LoggingAdapter adapter, Materializer mat) {

SyncRequestHandler wrapperHandler = new SyncRequestHandler(handler);
handler = wrapperHandler;
bindingInstrumented = true;
return Weaver.callOriginal();
}

return Weaver.callOriginal();
}
public Future<HttpInstrumentation.ServerBinding> bindAndHandleSync(
Function1<HttpRequest, HttpResponse> handler,
String interfaceString, int port,
ConnectionContext connectionContext,
ServerSettings settings,
LoggingAdapter adapter, Materializer mat) {

public Future<HttpInstrumentation.ServerBinding> bindAndHandle(
Flow<HttpRequest, HttpResponse, Object> handler,
String _interface,
int port, ConnectionContext connectionContext,
ServerSettings settings, LoggingAdapter log, Materializer fm) {
SyncRequestHandler wrapperHandler = new SyncRequestHandler(handler);
handler = wrapperHandler;

if (!bindingInstrumented) {
handler = new FlowRequestHandler().instrumentFlow(handler, fm);
return Weaver.callOriginal();
}
return Weaver.callOriginal();
}

public Future<HttpResponse> singleRequest(HttpRequest httpRequest, HttpsConnectionContext connectionContext,
ConnectionPoolSettings poolSettings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.WeaveAllConstructors;
import com.newrelic.api.agent.weaver.Weaver;
import scala.Function0;
import scala.Function1;
import scala.concurrent.Future;
import scala.concurrent.duration.FiniteDuration;
import scala.runtime.BoxedUnit;

import java.net.InetSocketAddress;
import java.util.logging.Level;
Expand All @@ -33,8 +38,8 @@ public ServerBinding() {
AgentBridge.publicApi.setAppServerPort(localAddress().getPort());
AgentBridge.publicApi.setServerInfo("Akka HTTP", ManifestUtils.getVersionFromManifest(getClass(), "akka-http-core", "10.0.11"));

AgentBridge.instrumentation.retransformUninstrumentedClass(AsyncRequestHandler.class);
AgentBridge.instrumentation.retransformUninstrumentedClass(SyncRequestHandler.class);
AgentBridge.instrumentation.retransformUninstrumentedClass(AsyncRequestHandler.class);
}
}

Expand Down
Loading

0 comments on commit f286fb0

Please sign in to comment.