Skip to content

Commit

Permalink
Remove muzzle dead code, doc cleanup, and better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Kent committed Jul 13, 2018
1 parent 2925df8 commit 23d0439
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 67 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/groovy/MuzzlePlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.gradle.api.Project
import java.lang.reflect.Method

/**
* POC muzzle task plugin which runs muzzle validation against an instrumentation's compile-time dependencies.
* muzzle task plugin which runs muzzle validation against an instrumentation's compile-time dependencies.
*
* <p/>TODO: merge this with version scan
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,16 @@ public boolean matches(
JavaModule module,
Class<?> classBeingRedefined,
ProtectionDomain protectionDomain) {
// Optimization: calling getMuzzleReferenceMatcher() inside this method prevents unnecessary loading of muzzle references during agentBuilder setup.
// Optimization: calling getInstrumentationMuzzle() inside this method prevents unnecessary loading of muzzle references during agentBuilder setup.
final ReferenceMatcher muzzle = getInstrumentationMuzzle();
if (null != muzzle) {
List<Reference.Mismatch> mismatches =
muzzle.getMismatchedReferenceSources(classLoader);
if (mismatches.size() > 0) {
log.debug(
"Instrumentation muzzled: {} on {}",
"Instrumentation muzzled: {} -- {} on {}",
instrumentationPrimaryName,
this.getClass().getName(),
classLoader);
}
for (Reference.Mismatch mismatch : mismatches) {
Expand Down Expand Up @@ -149,6 +150,8 @@ protected boolean defaultEnabled() {
return getConfigEnabled("dd.integrations.enabled", true);
}

// TODO: move common config helpers to Utils

public static String getPropOrEnv(final String name) {
return System.getProperty(name, System.getenv(propToEnvName(name)));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
package datadog.trace.agent.tooling.muzzle;

import datadog.trace.agent.tooling.Instrumenter;
import net.bytebuddy.asm.AsmVisitorWrapper;
import net.bytebuddy.build.Plugin;
import net.bytebuddy.description.field.FieldDescription;
import net.bytebuddy.description.field.FieldList;
import net.bytebuddy.description.method.MethodList;
import net.bytebuddy.description.type.TypeDefinition;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.dynamic.DynamicType.Builder;
import net.bytebuddy.implementation.Implementation;
import net.bytebuddy.jar.asm.ClassVisitor;
import net.bytebuddy.jar.asm.MethodVisitor;
import net.bytebuddy.jar.asm.Opcodes;
import net.bytebuddy.pool.TypePool;

/** Bytebuddy gradle plugin which creates muzzle-references at compile time. */
public class MuzzleGradlePlugin implements Plugin {
Expand Down Expand Up @@ -52,58 +43,4 @@ public Builder<?> apply(Builder<?> builder, TypeDescription typeDescription) {
return builder;
}
}

private static class RemoveFinalFlagVisitor implements AsmVisitorWrapper {
final String methodName;

public RemoveFinalFlagVisitor(String methodName) {
this.methodName = methodName;
}

@Override
public int mergeWriter(int flags) {
return flags;
}

@Override
public int mergeReader(int flags) {
return flags;
}

@Override
public ClassVisitor wrap(
TypeDescription instrumentedType,
ClassVisitor classVisitor,
Implementation.Context implementationContext,
TypePool typePool,
FieldList<FieldDescription.InDefinedShape> fields,
MethodList<?> methods,
int writerFlags,
int readerFlags) {
return new Visitor(classVisitor);
}

private class Visitor extends ClassVisitor {
public Visitor(ClassVisitor cv) {
super(Opcodes.ASM6, cv);
}

@Override
public MethodVisitor visitMethod(
final int access,
final String name,
final String descriptor,
final String signature,
final String[] exceptions) {
MethodVisitor methodVisitor =
super.visitMethod(access, name, descriptor, signature, exceptions);
if (name.equals(methodName) && (access & Opcodes.ACC_FINAL) != 0) {
return super.visitMethod(
access ^ Opcodes.ACC_FINAL, name, descriptor, signature, exceptions);
} else {
return super.visitMethod(access, name, descriptor, signature, exceptions);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public ElementMatcher<? super ClassLoader> classLoaderMatcher() {
public String[] helperClassNames() {
return new String[] {
"datadog.trace.instrumentation.apachehttpclient.DDTracingClientExec",
"datadog.trace.instrumentation.apachehttpclient.DDTracingClientExec$HttpHeadersInjectAdapter",
"datadog.trace.instrumentation.apachehttpclient.DDTracingClientExec$HttpHeadersInjectAdapter"
};
}

Expand Down

0 comments on commit 23d0439

Please sign in to comment.