From 0ff261d69e375637d5ac61b43d825e60b3307f20 Mon Sep 17 00:00:00 2001 From: sarangv Date: Tue, 21 Apr 2026 21:33:00 -0700 Subject: [PATCH] fix: package logging emitter resource and rename to avoid classpath issues (#19359) The previous fix broadly added src/main/resources as a resource directory, which inadvertently packaged log4j2.xml, log4j2.debug.xml, and the services/javax.annotation.processing.Processor file into druid-processing.jar. The packaged log4j2.xml (console-only) ends up on the classpath of dependent modules like indexing-service and shadows processing's test log4j2.xml that contains the RoutingAppender used to route task logs to per-task files. This caused ThreadingTaskRunnerTest#test_streamTaskLogs_ofRunningTask_readsFromTaskLogFile to fail because the per-task log file was never written. Narrow the include to only loggingEmitterAllowedMetrics.json so behavior for every other file in processing/src/main/resources matches pre-PR state. Co-authored-by: Sarang Vadali (cherry picked from commit 2de75ab1d74c8ba6c9623654cb69f9cd71442007) --- docs/configuration/index.md | 2 +- processing/pom.xml | 6 ++++++ .../java/util/emitter/core/LoggingEmitter.java | 15 ++++++++------- .../util/emitter/core/LoggingEmitterConfig.java | 8 ++++---- ...ics.json => loggingEmitterAllowedMetrics.json} | 0 .../util/emitter/core/LoggingEmitterTest.java | 4 ++-- ...ics.json => loggingEmitterAllowedMetrics.json} | 0 7 files changed, 21 insertions(+), 14 deletions(-) rename processing/src/main/resources/{defaultMetrics.json => loggingEmitterAllowedMetrics.json} (100%) rename processing/src/test/resources/{defaultMetrics.json => loggingEmitterAllowedMetrics.json} (100%) diff --git a/docs/configuration/index.md b/docs/configuration/index.md index 172d8062a5e8..08486e21a529 100644 --- a/docs/configuration/index.md +++ b/docs/configuration/index.md @@ -2022,7 +2022,7 @@ log4j config to route these logs to different sources based on the feed of the e |`druid.emitter.logging.loggerClass`|The class used for logging.|`org.apache.druid.java.util.emitter.core.LoggingEmitter`| |`druid.emitter.logging.logLevel`|Choices: debug, info, warn, error. The log level at which message are logged.|info| |`druid.emitter.logging.shouldFilterMetrics`|When true, only metrics listed in the allow list are emitted; non-metric events (e.g. alerts) are always emitted. When false, all events are logged (backward-compatible).|false| -|`druid.emitter.logging.allowedMetricsPath`|Path to a JSON file whose keys are the allowed metric names. Only used when `shouldFilterMetrics` is true. If null or empty, the bundled classpath resource `defaultMetrics.json` is used. If a path is set but the file is missing, a warning is logged and the emitter falls back to the default classpath resource.|null| +|`druid.emitter.logging.allowedMetricsPath`|Path to a JSON file whose keys are the allowed metric names. Only used when `shouldFilterMetrics` is true. If null or empty, the bundled classpath resource `loggingEmitterAllowedMetrics.json` is used. If a path is set but the file is missing, a warning is logged and the emitter falls back to the default classpath resource.|null| #### HTTP emitter module diff --git a/processing/pom.xml b/processing/pom.xml index dcc9da8a5de6..424591dea2f7 100644 --- a/processing/pom.xml +++ b/processing/pom.xml @@ -531,6 +531,12 @@ + + src/main/resources + + loggingEmitterAllowedMetrics.json + + ${project.build.directory}/hyperic-sigar-${sigar.base.version}/sigar-bin/lib diff --git a/processing/src/main/java/org/apache/druid/java/util/emitter/core/LoggingEmitter.java b/processing/src/main/java/org/apache/druid/java/util/emitter/core/LoggingEmitter.java index 17392515dd64..e53977adc8ca 100644 --- a/processing/src/main/java/org/apache/druid/java/util/emitter/core/LoggingEmitter.java +++ b/processing/src/main/java/org/apache/druid/java/util/emitter/core/LoggingEmitter.java @@ -50,7 +50,7 @@ public class LoggingEmitter implements Emitter { private static final Logger LOGGER = new Logger(LoggingEmitter.class); - private static final String DEFAULT_ALLOWED_METRICS_RESOURCE = "defaultMetrics.json"; + private static final String DEFAULT_ALLOWED_METRICS_RESOURCE = "loggingEmitterAllowedMetrics.json"; private final Logger log; private final Level level; @@ -92,9 +92,9 @@ public LoggingEmitter( /** * Loads the allowed metric names from a JSON file. If the path is null or empty, - * loads from the bundled classpath resource (defaultMetrics.json). If a custom - * path is provided but the file is missing, logs a warning and falls back to - * the default classpath resource. + * loads from the bundled classpath resource (loggingEmitterAllowedMetrics.json). + * If a custom path is provided but the file is missing, logs a warning and falls + * back to the default classpath resource. */ private static Set loadAllowedMetrics(@Nullable String path, ObjectMapper jsonMapper) { @@ -112,9 +112,10 @@ private static Set loadAllowedMetrics(@Nullable String path, ObjectMappe } /** - * Opens the allowed metrics configuration stream. Uses classpath resource when - * path is null/empty. When a custom path is specified but the file is missing, - * logs a warning and falls back to the default classpath resource. + * Opens the allowed metrics configuration stream. Uses the bundled + * loggingEmitterAllowedMetrics.json classpath resource when path is null/empty. + * When a custom path is specified but the file is missing, logs a warning and + * falls back to the default classpath resource. */ private static InputStream openAllowedMetricsStream(@Nullable String path) { diff --git a/processing/src/main/java/org/apache/druid/java/util/emitter/core/LoggingEmitterConfig.java b/processing/src/main/java/org/apache/druid/java/util/emitter/core/LoggingEmitterConfig.java index 7aa3d5797498..8f7be9f6bdb1 100644 --- a/processing/src/main/java/org/apache/druid/java/util/emitter/core/LoggingEmitterConfig.java +++ b/processing/src/main/java/org/apache/druid/java/util/emitter/core/LoggingEmitterConfig.java @@ -39,8 +39,8 @@ public class LoggingEmitterConfig /** * When true, only metrics listed in the allowed metrics configuration are emitted. * If {@link #allowedMetricsPath} is null/empty, the bundled default allowlist - * (defaultMetrics.json on the classpath) is used. If a path is provided, - * it is loaded from that file instead. + * (loggingEmitterAllowedMetrics.json on the classpath) is used. If a path is + * provided, it is loaded from that file instead. * Defaults to false (emit all metrics, backward-compatible behavior). */ @JsonProperty("shouldFilterMetrics") @@ -49,8 +49,8 @@ public class LoggingEmitterConfig /** * Optional path to a JSON file containing an array of allowed metric names. * Only used when {@link #shouldFilterMetrics} is true. - * If null or empty, the bundled default resource (defaultMetrics.json) is loaded - * from the classpath, mirroring how the Prometheus emitter loads its defaultMetrics.json. + * If null or empty, the bundled default resource (loggingEmitterAllowedMetrics.json) + * is loaded from the classpath. */ @JsonProperty @Nullable diff --git a/processing/src/main/resources/defaultMetrics.json b/processing/src/main/resources/loggingEmitterAllowedMetrics.json similarity index 100% rename from processing/src/main/resources/defaultMetrics.json rename to processing/src/main/resources/loggingEmitterAllowedMetrics.json diff --git a/processing/src/test/java/org/apache/druid/java/util/emitter/core/LoggingEmitterTest.java b/processing/src/test/java/org/apache/druid/java/util/emitter/core/LoggingEmitterTest.java index b29cf44ef41b..6aef81b04551 100644 --- a/processing/src/test/java/org/apache/druid/java/util/emitter/core/LoggingEmitterTest.java +++ b/processing/src/test/java/org/apache/druid/java/util/emitter/core/LoggingEmitterTest.java @@ -108,8 +108,8 @@ public void testEmitAllWhenFilteringDisabled() /** * With filtering enabled and no custom path, the default classpath resource - * (defaultMetrics.json) should be loaded. Metrics in the default list - * are emitted; unlisted metrics are dropped. + * (loggingEmitterAllowedMetrics.json) should be loaded. Metrics in the default + * list are emitted; unlisted metrics are dropped. */ @Test public void testFilterWithDefaultResource() diff --git a/processing/src/test/resources/defaultMetrics.json b/processing/src/test/resources/loggingEmitterAllowedMetrics.json similarity index 100% rename from processing/src/test/resources/defaultMetrics.json rename to processing/src/test/resources/loggingEmitterAllowedMetrics.json