Skip to content

Commit

Permalink
New status codes
Browse files Browse the repository at this point in the history
  • Loading branch information
jtduffy committed Nov 8, 2024
1 parent 39746f4 commit ba8dea0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,18 @@ public static ConfigService createConfigServiceUsingSettings(Map<String, Object>

public static ConfigService createConfigService(Logger log, boolean checkConfig) throws ConfigurationException, ForceDisconnectException {
File configFile = getConfigFile(log);
Map<String, Object> configSettings = getConfigurationFileSettings(configFile, log);
Map<String, Object> configSettings = null;
ConfigurationException fileParseException = null;
try {
configSettings = getConfigurationFileSettings(configFile, log);
} catch (ConfigurationException ce) {
fileParseException = ce;
}
Map<String, Object> deObfuscatedSettings = new ObscuringConfig(
configSettings, AgentConfigImpl.SYSTEM_PROPERTY_ROOT).getDeobscuredProperties();
AgentConfig config = AgentConfigImpl.createAgentConfig(deObfuscatedSettings);
validateConfig(config);

validateConfig(config, fileParseException);
return new ConfigServiceImpl(config, configFile, deObfuscatedSettings, checkConfig);
}

Expand Down Expand Up @@ -73,7 +80,11 @@ private static File getConfigFile(Logger log) {
}

@VisibleForTesting
public static void validateConfig(AgentConfig config) throws ConfigurationException, ForceDisconnectException {
public static void validateConfig(AgentConfig config, ConfigurationException fileParseException) throws ConfigurationException, ForceDisconnectException {
if (fileParseException != null) {
SuperAgentIntegrationUtils.reportUnhealthyStatusPriorToServiceStart(config, AgentHealth.Status.CONFIG_FILE_PARSE_ERROR);
throw fileParseException;
}
if (config.getApplicationName() == null) {
SuperAgentIntegrationUtils.reportUnhealthyStatusPriorToServiceStart(config, AgentHealth.Status.MISSING_APP_NAME);
throw new ConfigurationException("The agent requires an application name. Check the app_name setting in newrelic.yml");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public enum Status {
MAX_APP_NAMES_EXCEEDED("NR-APM-006", "The maximum number of configured app names (3) exceeded", Category.CONFIG),
PROXY_ERROR("NR-APM-007", "HTTP Proxy configuration error; response code [%s]", Category.HARVEST),
AGENT_DISABLED("NR-APM-008", "Agent is disabled via configuration", Category.CONFIG),
INITIAL_CONNECT_FAILURE("NR-APM-009", "Failed to connect to New Relic data collector", Category.HARVEST),
CONFIG_FILE_PARSE_ERROR("NR-APM-010", "Agent config file is not able to be parsed", Category.CONFIG),
SHUTDOWN("NR-APM-099", "Agent has shutdown", Category.AGENT),
GC_CIRCUIT_BREAKER("NR-APM-100", "Garbage collection circuit breaker triggered: Percent free memory %s; GC CPU time: %s", Category.CIRCUIT_BREAKER),;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void laspAndHsmEnabled() throws ConfigurationException {
assertTrue(agentConfig.laspEnabled());
assertTrue(agentConfig.isHighSecurity());
try {
ConfigServiceFactory.validateConfig(agentConfig);
ConfigServiceFactory.validateConfig(agentConfig, null);
fail();
} catch (ForceDisconnectException ex) {
}
Expand Down

0 comments on commit ba8dea0

Please sign in to comment.