Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,23 @@ public enum ConfigurationKey {
LOGGING_FILE_MAX_ARCHIVES("logging.file.max_archives", "1"),

/**
* Adds a hashed (SHA-256) session_id to each log line. Useful for tracking which user is
* responsible for the logging line.
* Adds a hashed (SHA-256) session ID to the MDC ({@code sessionId} key). Include it in log output
* via {@code %X{sessionId}} in the log4j2 pattern layout.
*/
LOGGING_REQUEST_ID_ENABLED("logging.request_id.enabled", Constants.ON, false),
LOGGING_SESSION_ID("logging.session_id", Constants.ON, false),

/**
* Enables SQL query logging via a datasource proxy. All {@code logging.query.*} keys below
* require this to be enabled.
*/
LOGGING_QUERY("logging.query", Constants.OFF, false),

/** Threshold in milliseconds for logging slow queries at WARN level. */
LOGGING_QUERY_SLOW_THRESHOLD(
"logging.query.slow_threshold", String.valueOf(SECONDS.toMillis(1)), false),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@netroms is that not a pretty low default? 😅 at least from what I see our queries take

Copy link
Contributor

Choose a reason for hiding this comment

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

Great! 🙏


/** Logs the calling method and class for each query. */
LOGGING_QUERY_METHOD("logging.query.method", Constants.OFF, false),

/** Base URL to the DHIS 2 instance. */
SERVER_BASE_URL("server.base.url", "", false),
Expand Down Expand Up @@ -660,19 +673,6 @@ public enum ConfigurationKey {
/** WSO2 IdP specific parameters. Enable logout */
OIDC_PROVIDER_WSO2_ENABLE_LOGOUT("oidc.provider.wso2.enable_logout", Constants.ON, false),

/** Database debugging feature. Defines threshold for logging of slow queries in the log. */
SLOW_QUERY_LOGGING_THRESHOLD_TIME_MS(
"slow.query.logging.threshold.time", String.valueOf(SECONDS.toMillis(1)), false),

/** Database debugging feature. Enables logging of all SQL queries to the log. */
ENABLE_QUERY_LOGGING("enable.query.logging", Constants.OFF, false),

/** Database debugging feature. Defines database logging before/after methods */
METHOD_QUERY_LOGGING_ENABLED("method.query.logging.enabled", Constants.OFF, false),

/** Database debugging feature. Enable time query logging. */
ELAPSED_TIME_QUERY_LOGGING_ENABLED("elapsed.time.query.logging.enabled", Constants.OFF, false),

/**
* Database datasource pool type. Supported pool types are: hikari (default), c3p0 (deprecated),
* unpooled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ void getDefault() {
void isEnabled() {
assertFalse(configProvider.isEnabled(ConfigurationKey.REDIS_ENABLED));
assertFalse(configProvider.isEnabled(ConfigurationKey.MONITORING_API_ENABLED));
assertTrue(configProvider.isEnabled(ConfigurationKey.ENABLE_QUERY_LOGGING));
assertFalse(configProvider.isEnabled(ConfigurationKey.METHOD_QUERY_LOGGING_ENABLED));
assertTrue(configProvider.isEnabled(ConfigurationKey.LOGGING_QUERY));
assertFalse(configProvider.isEnabled(ConfigurationKey.LOGGING_QUERY_METHOD));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
monitoring.api.enabled = off
enable.query.logging = true
method.query.logging.enabled = false
logging.query = true
logging.query.method = false
system.remote_servers_allowed = https://validtesturl.com/,https://validtesturl2.com/
connection.pool.min_size = 10
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private DataSource actualDataSource(DhisConfigurationProvider config) {

static DataSource createLoggingDataSource(
DhisConfigurationProvider dhisConfig, DataSource actualDataSource) {
boolean enableQueryLogging = dhisConfig.isEnabled(ConfigurationKey.ENABLE_QUERY_LOGGING);
boolean enableQueryLogging = dhisConfig.isEnabled(ConfigurationKey.LOGGING_QUERY);

if (!enableQueryLogging) {
return actualDataSource;
Expand All @@ -148,27 +148,18 @@ static DataSource createLoggingDataSource(
+ CodeGenerator.generateCode(5))
.logSlowQueryBySlf4j(
Integer.parseInt(
dhisConfig.getProperty(ConfigurationKey.SLOW_QUERY_LOGGING_THRESHOLD_TIME_MS)),
dhisConfig.getProperty(ConfigurationKey.LOGGING_QUERY_SLOW_THRESHOLD)),
TimeUnit.MILLISECONDS,
SLF4JLogLevel.WARN)
.listener(listener)
.proxyResultSet();

boolean elapsedTimeLogging =
dhisConfig.isEnabled(ConfigurationKey.ELAPSED_TIME_QUERY_LOGGING_ENABLED);
boolean methodLoggingEnabled =
dhisConfig.isEnabled(ConfigurationKey.METHOD_QUERY_LOGGING_ENABLED);
boolean methodLoggingEnabled = dhisConfig.isEnabled(ConfigurationKey.LOGGING_QUERY_METHOD);

if (methodLoggingEnabled) {
builder.afterMethod(DataSourceConfig::executeAfterMethod);
}

if (elapsedTimeLogging) {
builder.afterQuery(
(execInfo, queryInfoList) ->
log.info("Query took " + execInfo.getElapsedTime() + "msec"));
}

return builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/
package org.hisp.dhis.webapi.filter;

import static org.hisp.dhis.external.conf.ConfigurationKey.LOGGING_REQUEST_ID_ENABLED;
import static org.hisp.dhis.external.conf.ConfigurationKey.LOGGING_SESSION_ID;
import static org.hisp.dhis.webapi.filter.SessionIdFilter.hashToBase64;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
Expand Down Expand Up @@ -110,7 +110,7 @@ private void doFilter(Consumer<HttpServletRequest> withRequest) throws Exception
}

private void init(boolean enabled) {
when(dhisConfigurationProvider.isEnabled(LOGGING_REQUEST_ID_ENABLED)).thenReturn(enabled);
when(dhisConfigurationProvider.isEnabled(LOGGING_SESSION_ID)).thenReturn(enabled);
subject = new SessionIdFilter(dhisConfigurationProvider);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/
package org.hisp.dhis.webapi.filter;

import static org.hisp.dhis.external.conf.ConfigurationKey.LOGGING_REQUEST_ID_ENABLED;
import static org.hisp.dhis.external.conf.ConfigurationKey.LOGGING_SESSION_ID;

import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
Expand All @@ -53,7 +53,7 @@
* via {@code %X{sessionId}} in log4j2 pattern layouts.
*
* <p>The session ID is hashed using SHA-256 and base64-encoded for security. Only enabled when
* {@code logging.request_id.enabled} is true.
* {@code logging.session_id} is true.
*
* @author Luciano Fiandesio
* @see <a href="https://logback.qos.ch/manual/mdc.html">MDC Documentation</a>
Expand All @@ -74,7 +74,7 @@ public class SessionIdFilter extends OncePerRequestFilter {
private final boolean enabled;

public SessionIdFilter(DhisConfigurationProvider dhisConfig) {
this.enabled = dhisConfig.isEnabled(LOGGING_REQUEST_ID_ENABLED);
this.enabled = dhisConfig.isEnabled(LOGGING_SESSION_ID);
}

@Override
Expand Down