Skip to content

Commit 2de75ab

Browse files
sarangvSarang Vadali
andauthored
fix: package logging emitter resource and rename to avoid classpath issues (apache#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 <sarangvadali@salesforce.com>
1 parent c217127 commit 2de75ab

7 files changed

Lines changed: 21 additions & 14 deletions

File tree

docs/configuration/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2023,7 +2023,7 @@ log4j config to route these logs to different sources based on the feed of the e
20232023
|`druid.emitter.logging.loggerClass`|The class used for logging.|`org.apache.druid.java.util.emitter.core.LoggingEmitter`|
20242024
|`druid.emitter.logging.logLevel`|Choices: debug, info, warn, error. The log level at which message are logged.|info|
20252025
|`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|
2026-
|`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|
2026+
|`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|
20272027

20282028
#### HTTP emitter module
20292029

processing/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,12 @@
541541
</plugins>
542542

543543
<resources>
544+
<resource>
545+
<directory>src/main/resources</directory>
546+
<includes>
547+
<include>loggingEmitterAllowedMetrics.json</include>
548+
</includes>
549+
</resource>
544550
<resource>
545551
<directory>
546552
${project.build.directory}/hyperic-sigar-${sigar.base.version}/sigar-bin/lib

processing/src/main/java/org/apache/druid/java/util/emitter/core/LoggingEmitter.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
public class LoggingEmitter implements Emitter
5151
{
5252
private static final Logger LOGGER = new Logger(LoggingEmitter.class);
53-
private static final String DEFAULT_ALLOWED_METRICS_RESOURCE = "defaultMetrics.json";
53+
private static final String DEFAULT_ALLOWED_METRICS_RESOURCE = "loggingEmitterAllowedMetrics.json";
5454

5555
private final Logger log;
5656
private final Level level;
@@ -92,9 +92,9 @@ public LoggingEmitter(
9292

9393
/**
9494
* Loads the allowed metric names from a JSON file. If the path is null or empty,
95-
* loads from the bundled classpath resource (defaultMetrics.json). If a custom
96-
* path is provided but the file is missing, logs a warning and falls back to
97-
* the default classpath resource.
95+
* loads from the bundled classpath resource (loggingEmitterAllowedMetrics.json).
96+
* If a custom path is provided but the file is missing, logs a warning and falls
97+
* back to the default classpath resource.
9898
*/
9999
private static Set<String> loadAllowedMetrics(@Nullable String path, ObjectMapper jsonMapper)
100100
{
@@ -112,9 +112,10 @@ private static Set<String> loadAllowedMetrics(@Nullable String path, ObjectMappe
112112
}
113113

114114
/**
115-
* Opens the allowed metrics configuration stream. Uses classpath resource when
116-
* path is null/empty. When a custom path is specified but the file is missing,
117-
* logs a warning and falls back to the default classpath resource.
115+
* Opens the allowed metrics configuration stream. Uses the bundled
116+
* loggingEmitterAllowedMetrics.json classpath resource when path is null/empty.
117+
* When a custom path is specified but the file is missing, logs a warning and
118+
* falls back to the default classpath resource.
118119
*/
119120
private static InputStream openAllowedMetricsStream(@Nullable String path)
120121
{

processing/src/main/java/org/apache/druid/java/util/emitter/core/LoggingEmitterConfig.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public class LoggingEmitterConfig
3939
/**
4040
* When true, only metrics listed in the allowed metrics configuration are emitted.
4141
* If {@link #allowedMetricsPath} is null/empty, the bundled default allowlist
42-
* (defaultMetrics.json on the classpath) is used. If a path is provided,
43-
* it is loaded from that file instead.
42+
* (loggingEmitterAllowedMetrics.json on the classpath) is used. If a path is
43+
* provided, it is loaded from that file instead.
4444
* Defaults to false (emit all metrics, backward-compatible behavior).
4545
*/
4646
@JsonProperty("shouldFilterMetrics")
@@ -49,8 +49,8 @@ public class LoggingEmitterConfig
4949
/**
5050
* Optional path to a JSON file containing an array of allowed metric names.
5151
* Only used when {@link #shouldFilterMetrics} is true.
52-
* If null or empty, the bundled default resource (defaultMetrics.json) is loaded
53-
* from the classpath, mirroring how the Prometheus emitter loads its defaultMetrics.json.
52+
* If null or empty, the bundled default resource (loggingEmitterAllowedMetrics.json)
53+
* is loaded from the classpath.
5454
*/
5555
@JsonProperty
5656
@Nullable

processing/src/main/resources/defaultMetrics.json renamed to processing/src/main/resources/loggingEmitterAllowedMetrics.json

File renamed without changes.

processing/src/test/java/org/apache/druid/java/util/emitter/core/LoggingEmitterTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ public void testEmitAllWhenFilteringDisabled()
107107

108108
/**
109109
* With filtering enabled and no custom path, the default classpath resource
110-
* (defaultMetrics.json) should be loaded. Metrics in the default list
111-
* are emitted; unlisted metrics are dropped.
110+
* (loggingEmitterAllowedMetrics.json) should be loaded. Metrics in the default
111+
* list are emitted; unlisted metrics are dropped.
112112
*/
113113
@Test
114114
public void testFilterWithDefaultResource()

processing/src/test/resources/defaultMetrics.json renamed to processing/src/test/resources/loggingEmitterAllowedMetrics.json

File renamed without changes.

0 commit comments

Comments
 (0)