github-advanced-security[bot] commented on code in PR #19026:
URL: https://github.com/apache/druid/pull/19026#discussion_r2913242345


##########
extensions-contrib/prometheus-emitter/src/main/java/org/apache/druid/emitter/prometheus/PrometheusEmitter.java:
##########
@@ -70,6 +72,23 @@
 
   public PrometheusEmitter(PrometheusEmitterConfig config)
   {
+    super(
+        config.isShouldFilterMetrics(),
+        config.isShouldFilterMetrics()
+        ? config.getMetricSpecPath()
+                .or(() -> Optional.ofNullable(config.getDimensionMapPath()))

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [PrometheusEmitterConfig.getDimensionMapPath](1) should be avoided 
because it has been deprecated.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/10871)



##########
extensions-contrib/prometheus-emitter/src/main/java/org/apache/druid/emitter/prometheus/Metrics.java:
##########
@@ -66,7 +66,7 @@
   public Metrics(PrometheusEmitterConfig config)
   {
     String namespace = config.getNamespace();
-    String path = config.getDimensionMapPath();
+    String path = 
config.getMetricSpecPath().orElse(config.getDimensionMapPath());

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [PrometheusEmitterConfig.getDimensionMapPath](1) should be avoided 
because it has been deprecated.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/10870)



##########
processing/src/main/java/org/apache/druid/java/util/emitter/core/AbstractFilteringEmitter.java:
##########
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.java.util.emitter.core;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.util.Optional;
+import java.util.Set;
+
+/**
+ * Base class for emitters that support metric-name-based filtering.
+ *
+ * <p>The base implementation provides a single filtering gate in {@link 
#emit(Event)} and then
+ * delegates actual emission to {@link #emitFilteredEvent(Event)}.
+ */
+public abstract class AbstractFilteringEmitter implements Emitter, 
MetricFilteringEmitter
+{
+  private final boolean shouldFilterMetrics;
+  private final Set<String> allowedMetricNames;
+
+  protected AbstractFilteringEmitter(final boolean shouldFilterMetrics, final 
Set<String> allowedMetricNames)
+  {
+    this.shouldFilterMetrics = shouldFilterMetrics;
+    this.allowedMetricNames = Set.copyOf(allowedMetricNames);
+  }
+
+  protected static Set<String> loadAllowedMetricNames(
+      final boolean shouldFilterMetrics,
+      final ObjectMapper objectMapper,
+      final Optional<String> metricSpecPath,
+      final String defaultMetricSpecPath,
+      final MetricAllowlistParser parser
+  )
+  {
+    if (!shouldFilterMetrics) {
+      return Set.of();
+    }
+
+    return metricSpecPath
+        .map(path -> MetricAllowlistLoader.loadAllowlistFromFile(objectMapper, 
path, parser))
+        .orElseGet(() -> 
MetricAllowlistLoader.loadAllowlistFromClasspath(objectMapper, 
defaultMetricSpecPath, parser));
+  }
+
+  @Override
+  public final void emit(final Event event)
+  {
+    preEmit(event);
+    if (shouldFilterMetrics && shouldFilterEvent(event)) {
+      return;
+    }
+    emitFilteredEvent(event);
+  }
+
+  @Override
+  public boolean shouldFilterOutMetric(final String metricName)
+  {
+    return !allowedMetricNames.contains(metricName);
+  }
+
+  protected boolean isShouldFilterMetrics()
+  {
+    return shouldFilterMetrics;
+  }
+
+  protected Set<String> getAllowedMetricNames()
+  {
+    return allowedMetricNames;
+  }
+
+  /**
+   * Returns whether this event should be dropped before emission.
+   *
+   * <p>Implementations should apply emitter-specific event handling semantics 
here.
+   */
+  protected abstract boolean shouldFilterEvent(Event event);
+
+  /**
+   * Hook for pre-emission checks that must run before metric filtering.
+   */
+  protected void preEmit(final Event event)

Review Comment:
   ## Useless parameter
   
   The parameter 'event' is never used.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/10869)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to