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

include debug as env #890

Merged
merged 4 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions newrelic-agent/src/main/java/com/newrelic/agent/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.newrelic.agent.util.asm.ClassStructure;
import com.newrelic.bootstrap.BootstrapLoader;
import com.newrelic.weave.utils.Streams;
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.objectweb.asm.ClassReader;

import java.io.ByteArrayOutputStream;
Expand All @@ -32,6 +33,7 @@
import java.net.URL;
import java.text.MessageFormat;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.jar.*;
import java.util.logging.Level;
import java.util.regex.Pattern;
Expand All @@ -51,7 +53,6 @@ public final class Agent {
private static final String NEWRELIC_BOOTSTRAP = "newrelic-bootstrap";
private static final String AGENT_ENABLED_PROPERTY = "newrelic.config.agent_enabled";

private static final boolean DEBUG = Agent.setDebug();
private static final String VERSION = Agent.initVersion();

private static long agentPremainTime;
Expand All @@ -73,11 +74,7 @@ private static String initVersion() {
}

public static boolean isDebugEnabled() {
return DEBUG;
}

private static boolean setDebug(){
return Boolean.getBoolean("newrelic.debug") || Boolean.parseBoolean(System.getenv("NEWRELIC_DEBUG"));
return DebugFlag.DEBUG;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,12 @@

public class DebugFlag {
public static final AtomicBoolean tokenEnabled = new AtomicBoolean();

// This replaces a previous check that duplicated code in several places. We need to check the debug flag in AgentJarHelper before the Agent class has been loaded.
// This flag cannot be set via newrelic.yml (AgentConfigImpl) because a ServiceManager and ConfigService have not been initialized for the earliest checks
// for the debug setting.
public static final boolean DEBUG = Boolean.getBoolean("newrelic.debug") || Boolean.parseBoolean(System.getenv("NEWRELIC_DEBUG"));
;


}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import com.google.common.base.Joiner;
import com.newrelic.agent.Agent;
import com.newrelic.agent.DebugFlag;
import com.newrelic.agent.transaction.TransactionNamingScheme;
import com.newrelic.agent.transport.DataSenderImpl;

Expand Down Expand Up @@ -69,7 +70,6 @@ public class AgentConfigImpl extends BaseConfig implements AgentConfig {
public static final String MAX_STACK_TRACE_LINES = "max_stack_trace_lines";
public static final String METRIC_INGEST_URI = "metric_ingest_uri";
public static final String EVENT_INGEST_URI = "event_ingest_uri";
public static final String DEBUG = "newrelic.debug";
public static final String METRIC_DEBUG = "metric_debug";
public static final String PLATFORM_INFORMATION_ENABLED = "platform_information_enabled";
public static final String PORT = "port";
Expand Down Expand Up @@ -293,7 +293,7 @@ private AgentConfigImpl(Map<String, Object> props) {
putForDataSend = getProperty(PUT_FOR_DATA_SEND_PROPERTY, DEFAULT_PUT_FOR_DATA_SEND_ENABLED);
isApdexTSet = getProperty(APDEX_T) != null;
apdexTInMillis = (long) (getDoubleProperty(APDEX_T, DEFAULT_APDEX_T) * 1000L);
debug = Boolean.getBoolean(DEBUG) || Boolean.parseBoolean(System.getenv("NEWRELIC_DEBUG"));
debug = DebugFlag.DEBUG;
metricDebug = initMetricDebugConfig();
enabled = getProperty(ENABLED, DEFAULT_ENABLED) && getProperty(AGENT_ENABLED, DEFAULT_ENABLED);
experimentalRuntime = allowExperimentalRuntimeVersions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

package com.newrelic.agent.config;

import com.newrelic.agent.Agent;
import com.newrelic.agent.DebugFlag;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -223,12 +226,9 @@ public static String getAgentJarAttribute(String name) {
}
}

// The "newrelic.debug" flag redirects all Agent logging (prior to log init) to the standard output -after log init, log as usual. Unfortunately,
// we haven't initialized the Agent yet, so we cannot check it in the usual low-cost way by
// calling Agent.isDebugEnabled(). So we duplicate the functionality here for use in a few cases.
private static final boolean isNewRelicDebug() {
final String newrelicDebug = "newrelic.debug";
return Boolean.getBoolean(newrelicDebug) || Boolean.parseBoolean(System.getenv("NEWRELIC_DEBUG"));

return DebugFlag.DEBUG;
}

// Use of this method should be limited to serious error cases that would cause the Agent to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

package com.newrelic.agent.config;

import com.newrelic.agent.Agent;
import com.newrelic.agent.DebugFlag;

import java.io.File;
import java.text.MessageFormat;

Expand All @@ -20,9 +23,6 @@ public class ConfigFileHelper {
private static final String CONFIG_FILE_PROPERTY = "newrelic.config.file";
private static final String NEW_RELIC_HOME_DIRECTORY_PROPERTY = "newrelic.home";
private static final String NEW_RELIC_HOME_DIRECTORY_ENVIRONMENT_VARIABLE = "NEWRELIC_HOME";
private static final String NEW_RELIC_DEBUG_PROPERTY = "newrelic.debug";

private static final String NEW_RELIC_DEBUG_ENV = "NEWRELIC_DEBUG";
private static final String[] SEARCH_DIRECTORIES = { ".", "conf", "config", "etc" };

/**
Expand All @@ -38,7 +38,7 @@ public static File findConfigFile() {

File parentDir = getNewRelicDirectory();
if (parentDir != null) {
if (Boolean.getBoolean(NEW_RELIC_DEBUG_PROPERTY) || Boolean.parseBoolean(System.getenv(NEW_RELIC_DEBUG_ENV)) ) {
if (DebugFlag.DEBUG) {
System.err.println(MessageFormat.format("New Relic home directory: {0}", parentDir));
}
}
Expand Down Expand Up @@ -151,7 +151,7 @@ private static File findHomeDirectoryFromEnvironmentVariable() {
private static File findConfigFile(File parentDirectory) {
for (String searchDir : SEARCH_DIRECTORIES) {
File configDir = new File(parentDirectory, searchDir);
if (Boolean.getBoolean(NEW_RELIC_DEBUG_PROPERTY)) {
if (DebugFlag.DEBUG) {
System.err.println(MessageFormat.format("Searching for New Relic configuration in directory {0}", configDir));
}
if (configDir.exists()) {
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ include 'functional_test'
include 'functional_test:weave_test'
include 'functional_test:weave_test_impl'

// JDK 9+ module system tests
JDK 9+ module system tests
Copy link
Contributor

@meiao meiao Jun 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why uncomment this line?
Ah, guess you were uncommenting the lines below this and accidentally uncommented this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops!

if (JavaVersion.current().isJava9Compatible()) {
include 'module_test_9'
}
Expand Down