Skip to content

Commit

Permalink
Add metric to track custom Log4J configs (#817)
Browse files Browse the repository at this point in the history
  • Loading branch information
labkey-jeckels authored May 8, 2024
1 parent 5d925dc commit c1088e3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 0 additions & 1 deletion server/configs/webapps/embedded/labkey_server.service
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ ExecStart=<JAVA_HOME>/bin/java \
-Xms2G \
-Xmx2G \
-XX:+HeapDumpOnOutOfMemoryError \
-XX:ErrorFile=/labkey/labkey/logs/error_%p.log \
-Djava.io.tmpdir=$LABKEY_HOME/labkey-tmp \
$JAVA_FLAGS_JAR_OPS \
$JAVA_REFLECTION_JAR_OPS \
Expand Down
27 changes: 27 additions & 0 deletions server/embedded/src/org/labkey/embedded/LabKeyServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class LabKeyServer
private static final String SERVER_GUID = "serverGUID";
public static final String SERVER_GUID_PARAMETER_NAME = "org.labkey.mothership." + SERVER_GUID;
public static final String SERVER_SSL_KEYSTORE = "org.labkey.serverSslKeystore";
public static final String CUSTOM_LOG4J_CONFIG = "org.labkey.customLog4JConfig";
static final String MAX_TOTAL_CONNECTIONS_DEFAULT = "50";
static final String MAX_IDLE_DEFAULT = "10";
static final String MAX_WAIT_MILLIS_DEFAULT = "120000";
Expand Down Expand Up @@ -187,6 +188,12 @@ public ManagementProperties managementSource()
return new ManagementProperties();
}

@Bean
public LoggingProperties loggingSource()
{
return new LoggingProperties();
}


/**
* This lets us snoop on the Spring Boot config for deploying the management endpoint on a different port, as
Expand Down Expand Up @@ -224,6 +231,26 @@ public void setPort(int port)
}
}

/**
* This lets us snoop on the Spring Boot config for log4j so we can report it via a mothership metric
*/
@Configuration
@ConfigurationProperties("logging")
public static class LoggingProperties
{
private String _config;

public String getConfig()
{
return _config;
}

public void setConfig(String config)
{
_config = config;
}
}


@Validated
@Configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Map;
import java.util.Objects;

import static org.labkey.embedded.LabKeyServer.CUSTOM_LOG4J_CONFIG;
import static org.labkey.embedded.LabKeyServer.SERVER_GUID_PARAMETER_NAME;
import static org.labkey.embedded.LabKeyServer.SERVER_SSL_KEYSTORE;

Expand Down Expand Up @@ -156,6 +157,13 @@ protected TomcatWebServer getTomcatWebServer(Tomcat tomcat)
context.addParameter("org.labkey.authentication.duo.Bypass", "true");
}

boolean customLog4J = System.getProperty("log4j.configurationFile") != null;
if (!customLog4J)
{
customLog4J = _server.loggingSource().getConfig() != null;
}
context.addParameter(CUSTOM_LOG4J_CONFIG, Boolean.toString(customLog4J));

// Add serverGUID for mothership - it tells mothership that 2 instances of a server should be considered the same for metrics gathering purposes.
if (null != contextProperties.getServerGUID())
{
Expand Down

0 comments on commit c1088e3

Please sign in to comment.