Skip to content

Commit

Permalink
initial checkin
Browse files Browse the repository at this point in the history
  • Loading branch information
dhilpipre committed Apr 4, 2024
1 parent 56de884 commit 758f0df
Show file tree
Hide file tree
Showing 51 changed files with 1,648 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.java-version
.git
.github
.classpath
.project
.settings
build
bin
30 changes: 30 additions & 0 deletions netflix-zuul-core-1.x/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

// Build.gradle generated for instrumentation module netflix-zuul-core-1.x

apply plugin: 'java'

dependencies {
implementation group: 'com.netflix.zuul', name: 'zuul-core', version: '1.2.0'
compileOnly group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'


// New Relic Java Agent dependencies
implementation 'com.newrelic.agent.java:newrelic-agent:6.4.0'
implementation 'com.newrelic.agent.java:newrelic-api:6.4.0'
implementation fileTree(include: ['*.jar'], dir: '../libs')
implementation fileTree(include: ['*.jar'], dir: '../test-lib')
}

jar {
manifest {
attributes 'Implementation-Title': 'com.newrelic.instrumentation.netflix-zuul-core-1.x'
attributes 'Implementation-Vendor': 'New Relic'
attributes 'Implementation-Vendor-Id': 'com.newrelic'
attributes 'Implementation-Version': 1.0
}
}

verifyInstrumentation {
passes 'com.netflix.zuul:zuul-core:[1.2.0,2.1.1)'
excludeRegex '.*rc.[1-9]'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.netflix.zuul;

import com.newrelic.api.agent.Trace;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;

@Weave
public abstract class FilterProcessor {

@Trace
public void preRoute() {
Weaver.callOriginal();
}

@Trace
public void route() {
Weaver.callOriginal();
}

@Trace
public void postRoute() {
Weaver.callOriginal();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.netflix.zuul;

import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Trace;
import com.newrelic.api.agent.TracedMethod;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;

@Weave(type = MatchType.Interface)
public abstract class IZuulFilter {

@Trace
public Object run() {
TracedMethod traced = NewRelic.getAgent().getTracedMethod();
traced.setMetricName("Custom","Zuul","ZuulFilter",getClass().getSimpleName(),"run");
return Weaver.callOriginal();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.netflix.zuul;

import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Trace;
import com.newrelic.api.agent.TracedMethod;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;

@Weave(type=MatchType.BaseClass)
public abstract class ZuulFilter {

public abstract String filterType();

@Trace
public ZuulFilterResult runFilter() {
TracedMethod traced = NewRelic.getAgent().getTracedMethod();
traced.setMetricName("Custom","Zuul","ZuulFilter",getClass().getSimpleName(),"runFilter");
traced.addCustomAttribute("FilterType", filterType());
ZuulFilterResult fResult = Weaver.callOriginal();
String status = fResult != null ? fResult.getStatus() != null ? fResult.getStatus().name() : null : null;
if(status != null) {
traced.addCustomAttribute("FilterResult",status);
}
Throwable t = fResult != null ? fResult.getException() : null;
if(t != null) {
NewRelic.noticeError(t);
}
return fResult;
}

}
28 changes: 28 additions & 0 deletions netflix-zuul-core-2.1.6/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

// Build.gradle generated for instrumentation module netflix-zuul-core-2.1

apply plugin: 'java'

dependencies {
implementation 'com.netflix.zuul:zuul-core:2.1.6'
implementation group: 'io.netty', name: 'netty-tcnative-boringssl-static', version: '2.0.7.Final'

// New Relic Java Agent dependencies
implementation 'com.newrelic.agent.java:newrelic-agent:6.4.0'
implementation 'com.newrelic.agent.java:newrelic-api:6.4.0'
implementation fileTree(include: ['*.jar'], dir: '../libs')
implementation fileTree(include: ['*.jar'], dir: '../test-lib')
}

jar {
manifest {
attributes 'Implementation-Title': 'com.newrelic.instrumentation.netflix-zuul-core-2.1.6'
attributes 'Implementation-Vendor': 'New Relic'
attributes 'Implementation-Vendor-Id': 'com.newrelic'
attributes 'Implementation-Version': 1.0
}
}

verifyInstrumentation {
passes 'com.netflix.zuul:zuul-core:[2.1.6,)'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.netflix.netty.common;

import com.newrelic.api.agent.Trace;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;

import io.netty.channel.ChannelHandlerContext_Instrumentation;
import io.netty.channel.ChannelPromise;

@Weave
public abstract class HttpClientLifecycleChannelHandler {

@Weave
private static class HttpClientLifecycleInboundChannelHandler {

@Trace(async = true)
public void channelRead(ChannelHandlerContext_Instrumentation ctx, Object msg) {
if(ctx.pipeline().zuul_token != null) {
ctx.pipeline().zuul_token.link();
}

Weaver.callOriginal();
}

}

@Weave
private static class HttpClientLifecycleOutboundChannelHandler {

@Trace(async = true)
public void write(ChannelHandlerContext_Instrumentation ctx, Object msg, ChannelPromise promise) {
if(ctx.pipeline().zuul_token != null) {
ctx.pipeline().zuul_token.link();
}
Weaver.callOriginal();

}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.netflix.netty.common;

import com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteReason;
import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Token;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;
import com.newrelic.instrumentation.labs.netflix_zuul.NettyRequestHeaders;
import com.newrelic.instrumentation.labs.netflix_zuul.ZuulDispatcher;

import io.netty.channel.ChannelHandlerContext_Instrumentation;
import io.netty.handler.codec.http.HttpRequest;

@Weave(originalName = "com.netflix.netty.common.HttpLifecycleChannelHandler")
public abstract class HttpLifecycleChannelHandler_instrumentation {


protected static boolean fireCompleteEventIfNotAlready(ChannelHandlerContext_Instrumentation ctx, CompleteReason reason) {
boolean b = Weaver.callOriginal();
if(b) {
if(ctx.pipeline().zuul_token != null) {
ctx.pipeline().zuul_token.expire();
ctx.pipeline().zuul_token = null;
}
}

return b;
}

protected static boolean fireStartEvent(ChannelHandlerContext_Instrumentation ctx, HttpRequest request) {
boolean b = Weaver.callOriginal();
if(b) {
ZuulDispatcher.get().channelRead(ctx, request);
NettyRequestHeaders headers = new NettyRequestHeaders(request);
NewRelic.getAgent().getTransaction().insertDistributedTraceHeaders(headers);
if(ctx.pipeline().zuul_token == null) {
Token t = NewRelic.getAgent().getTransaction().getToken();
if(t != null && t.isActive()) {
ctx.pipeline().zuul_token= t;
} else if(t != null) {
t.expire();
t = null;
}
}
}

return b;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.netflix.netty.common;

import com.newrelic.api.agent.Trace;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;

import io.netty.channel.ChannelHandlerContext_Instrumentation;
import io.netty.channel.ChannelPromise;

@Weave
public abstract class HttpServerLifecycleChannelHandler {

@Weave
public static class HttpServerLifecycleInboundChannelHandler {

@Trace(async = true)
public void channelRead(ChannelHandlerContext_Instrumentation ctx, Object msg) {
if(ctx.pipeline().zuul_token != null) {
ctx.pipeline().zuul_token.link();
}
Weaver.callOriginal();
}

}

@Weave
public static class HttpServerLifecycleOutboundChannelHandler {

@Trace(async = true)
public void write(ChannelHandlerContext_Instrumentation ctx, Object msg, ChannelPromise promise) {
if(ctx.pipeline().zuul_token != null) {
ctx.pipeline().zuul_token.link();
}
Weaver.callOriginal();
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.netflix.zuul;

import java.util.HashMap;

import com.netflix.zuul.message.http.HttpRequestInfo;
import com.netflix.zuul.message.http.HttpResponseMessage;
import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Trace;
import com.newrelic.api.agent.TracedMethod;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;
import com.newrelic.instrumentation.labs.netflix_zuul.Utils;

@Weave(type = MatchType.Interface)
public class RequestCompleteHandler {

@Trace
public void handle(HttpRequestInfo inboundRequest, HttpResponseMessage response) {
TracedMethod traced = NewRelic.getAgent().getTracedMethod();
HashMap<String, Object> attributes = new HashMap<>();
Utils.addRequestInfo(attributes, inboundRequest);
traced.addCustomAttribute("In", inboundRequest.getMethod());
traced.setMetricName("Custom","Netflix","Zuul","RequestCompleteHandler",getClass().getSimpleName(),"handle");
Weaver.callOriginal();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.netflix.zuul.filters;

import com.netflix.zuul.message.ZuulMessage;
import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Trace;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;

@Weave(type = MatchType.Interface)
public abstract class SyncZuulFilter<I extends ZuulMessage, O extends ZuulMessage> implements ZuulFilter<I, O> {

@Trace
public O apply(I input) {
String filterName = filterName();
if(filterName != null && !filterName.isEmpty()) {
NewRelic.getAgent().getTracedMethod().setMetricName("Custom","Netflix-Zuul","SyncZuulFilter",filterName,"apply");
} else {
NewRelic.getAgent().getTracedMethod().setMetricName("Custom","Netflix-Zuul","SyncZuulFilter",getClass().getSimpleName(),"apply");
}
return Weaver.callOriginal();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.netflix.zuul.filters;

import java.util.Hashtable;

import com.netflix.zuul.message.ZuulMessage;
import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Trace;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;

import rx.Observable;

@Weave(type=MatchType.Interface, originalName = "com.netflix.zuul.filters.ZuulFilter")
public abstract class ZuulFilter_instrumentation<I extends ZuulMessage, O extends ZuulMessage> {

public abstract FilterSyncType getSyncType();
public abstract String filterName();
public abstract FilterType filterType();

@Trace
public Observable<O> applyAsync(I input) {
String filterName = filterName();
if(filterName != null && !filterName.isEmpty()) {
NewRelic.getAgent().getTracedMethod().setMetricName("Custom","Netflix-Zuul","ZuulFilter",filterName,"applyAsync");
} else {
NewRelic.getAgent().getTracedMethod().setMetricName("Custom","Netflix-Zuul","ZuulFilter",getClass().getSimpleName(),"applyAsync");
}
Hashtable<String, Object> attributes = new Hashtable<>();
attributes.put("Filter-Synctype", getSyncType());
attributes.put("FilterType", filterType());
NewRelic.getAgent().getTracedMethod().addCustomAttributes(attributes);
return Weaver.callOriginal();
}
}
Loading

0 comments on commit 758f0df

Please sign in to comment.