Skip to content

Commit

Permalink
Remove unused code (#1520)
Browse files Browse the repository at this point in the history
* Simplify retrieval of app id

* Remove unused Stoppable interface

* Move test-only classes to tests

* Remove unused code

* Remove unused code

* Remove unused code

* Remove unused code

* Remove unused code

* Remove unused code

* Remove unused code

* Remove unused code

* Remove unused code

* Remove unused code

* Remove unused code

* Remove unused code

* Remove unused code

* fixup

* fixup

* Remove deprecated code

* Remove unused code

* Remove unused code

* Remove unused code

* fixup

* Add request metrics interop (so not unused)

* Remove unused code

* Remove unused code

* Remove unused code

* Comment

* Remove unused code

* Remove unused code

* Remove unused code

* fixup

* Remove unused imports

* Remove unused imports

* Remove unused code

* Remove unused code

* Seems unused

* Fix param to be used

* Remove unused param

* Remove unused code

* Fix param to be used

* Use unused local var in test

* Remove unused code

* Remove unused code

* Remove unused imports

* Intellij: unused assignment

* Intellij: replace with diamond operator

* Intellij: remove redundant throws clause

* Intellij: remove redundant cast

* Intellij: remove redundant local var

* Spotbugs

* Bring back a bit

* Fix smoke tests

* Fix test

* Remove unused code

* Bring back QuickPulse stop, will be useful later
  • Loading branch information
trask committed Mar 2, 2021
1 parent 75666ef commit 9ce9498
Show file tree
Hide file tree
Showing 224 changed files with 299 additions and 5,271 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ public static void trackTrace(String message, int severityLevel, Map<String, Str
}

public static void trackRequest(String id, String name, URL url, Date timestamp, Long duration, String responseCode, boolean success,
String source, Map<String, String> properties, Map<String, String> tags) {
String source, Map<String, String> properties, Map<String, String> tags, Map<String, Double> metrics) {
if (delegate != null) {
delegate.trackRequest(id, name, url, timestamp, duration, responseCode, success, source, properties, tags);
delegate.trackRequest(id, name, url, timestamp, duration, responseCode, success, source, properties, tags, metrics);
}
}

Expand Down Expand Up @@ -163,8 +163,9 @@ void trackPageView(String name, URI uri, long totalMillis, Map<String, String> p
void trackTrace(String message, int severityLevel, Map<String, String> properties, Map<String, String> tags);

void trackRequest(String id, String name, URL url, Date timestamp, Long duration, String responseCode, boolean success,
String source, Map<String, String> properties, Map<String, String> tags);
String source, Map<String, String> properties, Map<String, String> tags, Map<String, Double> metrics);

// TODO also handle cases where ExceptionTelemetry parsedStack is used directly instead of indirectly through Exception
void trackException(Exception exception, Map<String, String> properties, Map<String, String> tags, Map<String, Double> metrics);

void flush();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.microsoft.applicationinsights.agent.bootstrap.diagnostics;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public Thread newThread(Runnable r) {
};

private static final ThreadPoolExecutor WRITER_THREAD =
new ThreadPoolExecutor(1, 1, 750L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(),
new ThreadPoolExecutor(1, 1, 750L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(),
THREAD_FACTORY);

private static boolean enabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
import static com.microsoft.applicationinsights.agent.bootstrap.diagnostics.log.ApplicationInsightsJsonLayout.CUSTOM_FIELDS_PROP_NAME;
import static com.microsoft.applicationinsights.agent.bootstrap.diagnostics.log.ApplicationInsightsJsonLayout.FORMATTED_MESSAGE_ATTR_NAME;
import static com.microsoft.applicationinsights.agent.bootstrap.diagnostics.log.ApplicationInsightsJsonLayout.LOGGER_ATTR_NAME;
import static com.microsoft.applicationinsights.agent.bootstrap.diagnostics.log.ApplicationInsightsJsonLayout.OPERATION_NAME_PROP_NAME;
import static com.microsoft.applicationinsights.agent.bootstrap.diagnostics.log.ApplicationInsightsJsonLayout.TIMESTAMP_PROP_NAME;
import static com.microsoft.applicationinsights.agent.bootstrap.diagnostics.log.ApplicationInsightsJsonLayout.UNKNOWN_VALUE;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void tearDown() {
}

@Test
public void formatterSerializesSimpleMap() throws Exception {
public void formatterSerializesSimpleMap() {
Map<String, Object> m = new HashMap<>();
m.put("s1", "v1");
m.put("int1", 123);
Expand All @@ -31,7 +31,7 @@ public void formatterSerializesSimpleMap() throws Exception {
}

@Test
public void formatterWithPrettyPrintPrintsPretty() throws Exception {
public void formatterWithPrettyPrintPrintsPretty() {
Map<String, Object> m = new HashMap<>();
m.put("s1", "v1");
m.put("int1", 123);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public void homeEnvVarUpdatesBaseDir() {
@Test
public void siteLogDirHasPrecedenceOverHome() {
String homeDir = "/this/is/wrong";
envVars.set(StatusFile.HOME_ENV_VAR, homeDir);
String siteLogDir = "/the/correct/dir";
System.setProperty("site.logdir", siteLogDir);
StatusFile.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.microsoft.applicationinsights.agent.internal.propagator.DelegatingPropagator;
import com.microsoft.applicationinsights.agent.internal.sampling.DelegatingSampler;
import io.opentelemetry.instrumentation.api.aiconnectionstring.AiConnectionString;
import io.opentelemetry.sdk.trace.samplers.Sampler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
package com.microsoft.applicationinsights.agent.internal;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.instrument.ClassFileTransformer;
import java.security.ProtectionDomain;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public void trackTrace(String message, int severityLevel, Map<String, String> pr

@Override
public void trackRequest(String id, String name, URL url, Date timestamp, @Nullable Long duration, String responseCode, boolean success,
String source, Map<String, String> properties, Map<String, String> tags) {
String source, Map<String, String> properties, Map<String, String> tags, Map<String, Double> metrics) {
if (Strings.isNullOrEmpty(name)) {
return;
}
Expand All @@ -174,6 +174,7 @@ public void trackRequest(String id, String name, URL url, Date timestamp, @Nulla
telemetry.setSource(source);
telemetry.getProperties().putAll(properties);
telemetry.getContext().getTags().putAll(tags);
telemetry.getMetrics().putAll(metrics);

track(telemetry);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import net.bytebuddy.jar.asm.ClassVisitor;
import net.bytebuddy.jar.asm.ClassWriter;
import net.bytebuddy.jar.asm.MethodVisitor;
import org.objectweb.asm.util.ASMifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -166,11 +167,12 @@ private void writeGetTypeMethod() {
// DO NOT REMOVE
// this is used during development for generating above bytecode
public static void main(String[] args) throws Exception {
// ASMifier.main(new String[]{RDT.class.getName()});
ASMifier.main(new String[]{RDT.class.getName()});
}

// DO NOT REMOVE
// this is used during development for generating above bytecode
@SuppressWarnings("unused")
public static class RDT {

public String getResultCode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,24 @@
package com.microsoft.applicationinsights.agent.internal.instrumentation.sdk;

import java.lang.instrument.ClassFileTransformer;
import java.lang.reflect.Modifier;
import java.security.ProtectionDomain;
import java.util.Collections;
import java.util.Map;

import net.bytebuddy.jar.asm.ClassReader;
import net.bytebuddy.jar.asm.ClassVisitor;
import net.bytebuddy.jar.asm.ClassWriter;
import net.bytebuddy.jar.asm.MethodVisitor;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.objectweb.asm.util.ASMifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static net.bytebuddy.jar.asm.Opcodes.ACC_PRIVATE;
import static net.bytebuddy.jar.asm.Opcodes.ACC_PROTECTED;
import static net.bytebuddy.jar.asm.Opcodes.ACC_PUBLIC;
import static net.bytebuddy.jar.asm.Opcodes.ACONST_NULL;
import static net.bytebuddy.jar.asm.Opcodes.ARETURN;
import static net.bytebuddy.jar.asm.Opcodes.ASM7;
import static net.bytebuddy.jar.asm.Opcodes.INVOKESTATIC;

// this is used to supplement old versions of RequestTelemetry with getters from the latest version of
// RequestTelemetry
Expand Down Expand Up @@ -84,6 +85,13 @@ public MethodVisitor visitMethod(int access, String name, String descriptor, @Nu
if (name.equals("getSource") && descriptor.equals("()Ljava/lang/String;")) {
foundGetSourceMethod = true;
}
if (name.equals("getMetrics") && descriptor.equals("()Ljava/util/concurrent/ConcurrentMap;")
&& !Modifier.isPublic(access)) {
// getMetrics() was package-private prior to 2.2.0
// remove private and protected flags, add public flag
int updatedAccess = (access & ~ACC_PRIVATE & ~ACC_PROTECTED) | ACC_PUBLIC;
return super.visitMethod(updatedAccess, name, descriptor, signature, exceptions);
}
return super.visitMethod(access, name, descriptor, signature, exceptions);
}

Expand All @@ -106,11 +114,12 @@ private void writeGetSourceMethod() {
// DO NOT REMOVE
// this is used during development for generating above bytecode
public static void main(String[] args) throws Exception {
// ASMifier.main(new String[]{RDT.class.getName()});
ASMifier.main(new String[]{RDT.class.getName()});
}

// DO NOT REMOVE
// this is used during development for generating above bytecode
@SuppressWarnings("unused")
public static class RDT {

public String getSource() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,9 +607,11 @@ private void writeAgentTrackRequestTelemetryMethod() {
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEVIRTUAL, unshadedPrefix + "/telemetry/RequestTelemetry", "getContext", "()L" + unshadedPrefix + "/telemetry/TelemetryContext;", false);
mv.visitMethodInsn(INVOKEVIRTUAL, unshadedPrefix + "/telemetry/TelemetryContext", "getTags", "()Ljava/util/concurrent/ConcurrentMap;", false);
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEVIRTUAL, unshadedPrefix + "/telemetry/RequestTelemetry", "getMetrics", "()Ljava/util/concurrent/ConcurrentMap;", false);
Label label4 = new Label();
mv.visitLabel(label4);
mv.visitMethodInsn(INVOKESTATIC, BYTECODE_UTIL_INTERNAL_NAME, "trackRequest", "(Ljava/lang/String;Ljava/lang/String;Ljava/net/URL;Ljava/util/Date;Ljava/lang/Long;Ljava/lang/String;ZLjava/lang/String;Ljava/util/Map;Ljava/util/Map;)V", false);
mv.visitMethodInsn(INVOKESTATIC, BYTECODE_UTIL_INTERNAL_NAME, "trackRequest", "(Ljava/lang/String;Ljava/lang/String;Ljava/net/URL;Ljava/util/Date;Ljava/lang/Long;Ljava/lang/String;ZLjava/lang/String;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;)V", false);
mv.visitLabel(label1);
Label label5 = new Label();
mv.visitJumpInsn(GOTO, label5);
Expand All @@ -625,7 +627,7 @@ private void writeAgentTrackRequestTelemetryMethod() {
mv.visitInsn(RETURN);
Label label7 = new Label();
mv.visitLabel(label7);
mv.visitMaxs(10, 3);
mv.visitMaxs(11, 3);
mv.visitEnd();
}

Expand Down Expand Up @@ -706,6 +708,7 @@ public static void main(String[] args) throws Exception {

// DO NOT REMOVE
// this is used during development for generating above bytecode
@SuppressWarnings("unused")
public static class TC {

private TelemetryConfiguration configuration;
Expand Down Expand Up @@ -806,7 +809,7 @@ public void track(Telemetry telemetry) {
private void agent$trackRequestTelemetry(RequestTelemetry t) {
try {
BytecodeUtil.trackRequest(t.getId(), t.getName(), t.getUrl(), t.getTimestamp(), agent$toMillis(t.getDuration()),
t.getResponseCode(), t.isSuccess(), t.getSource(), t.getProperties(), t.getContext().getTags());
t.getResponseCode(), t.isSuccess(), t.getSource(), t.getProperties(), t.getContext().getTags(), t.getMetrics());
} catch (MalformedURLException e) {
BytecodeUtil.logErrorOnce(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private boolean checkAttributes(SpanData span) {
// user specified key not found
return false;
}
if (attribute.value != null && !((String)existingAttributeValue).equals(attribute.value)) {
if (attribute.value != null && !existingAttributeValue.equals(attribute.value)) {
// user specified value doesn't match
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,6 @@ private static boolean isTrimEmpty(String value) {

public static class ConfigurationException extends RuntimeException {

public ConfigurationException(String message) {
super(message);
}

ConfigurationException(String message, Exception e) {
super(message, e);
}
Expand Down Expand Up @@ -311,8 +307,7 @@ static Configuration getConfigurationFromConfigFile(Path configPath, boolean str
Buffer buffer = new Buffer();
buffer.readFrom(in);
try {
Configuration configuration = jsonAdapter.fromJson(buffer);
return configuration;
return jsonAdapter.fromJson(buffer);
} catch(JsonDataException ex) {
if(strict) {
// Try extracting the configuration without failOnUnknown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.lang.instrument.Instrumentation;
import java.net.URL;

import com.microsoft.applicationinsights.agent.internal.AiComponentInstaller;
import com.microsoft.applicationinsights.agent.internal.wasbootstrap.MainEntryPoint;

public class AgentInstallerOverride {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public static void premain(String agentArgs, Instrumentation inst) {
if (alreadyLoaded) {
return;
}
// Profiler.start();
OpenTelemetryAgent.premain(agentArgs, inst, Agent.class);
alreadyLoaded = true;
}
Expand Down

This file was deleted.

Loading

0 comments on commit 9ce9498

Please sign in to comment.