This is an automated email from the ASF dual-hosted git repository.

karan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git


The following commit(s) were added to refs/heads/master by this push:
     new 90175b8927e [Prometheus Emitter] Add to code coverage and remove code 
smell (#17362)
90175b8927e is described below

commit 90175b8927eafcec97b19d4fd668c3d81271f3b9
Author: Ashwin Tumma <[email protected]>
AuthorDate: Wed Oct 16 22:19:16 2024 -0700

    [Prometheus Emitter] Add to code coverage and remove code smell (#17362)
    
    * [Prometheus Emitter] Add to code coverage and remove code smell
---
 .../org/apache/druid/emitter/prometheus/Metrics.java    |  6 +++---
 .../apache/druid/emitter/prometheus/MetricsTest.java    | 17 +++++++++++++++++
 .../src/test/resources/defaultMetricsTest.json          |  3 +++
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git 
a/extensions-contrib/prometheus-emitter/src/main/java/org/apache/druid/emitter/prometheus/Metrics.java
 
b/extensions-contrib/prometheus-emitter/src/main/java/org/apache/druid/emitter/prometheus/Metrics.java
index 50c235538be..4b9ad716cdf 100644
--- 
a/extensions-contrib/prometheus-emitter/src/main/java/org/apache/druid/emitter/prometheus/Metrics.java
+++ 
b/extensions-contrib/prometheus-emitter/src/main/java/org/apache/druid/emitter/prometheus/Metrics.java
@@ -64,7 +64,7 @@ public class Metrics
 
   public Metrics(String namespace, String path, boolean isAddHostAsLabel, 
boolean isAddServiceAsLabel, Map<String, String> extraLabels)
   {
-    Map<String, DimensionsAndCollector> registeredMetrics = new HashMap<>();
+    Map<String, DimensionsAndCollector> parsedRegisteredMetrics = new 
HashMap<>();
     Map<String, Metric> metrics = readConfig(path);
 
     if (extraLabels == null) {
@@ -116,10 +116,10 @@ public class Metrics
       }
 
       if (collector != null) {
-        registeredMetrics.put(name, new DimensionsAndCollector(dimensions, 
collector, metric.conversionFactor));
+        parsedRegisteredMetrics.put(name, new 
DimensionsAndCollector(dimensions, collector, metric.conversionFactor));
       }
     }
-    this.registeredMetrics = Collections.unmodifiableMap(registeredMetrics);
+    this.registeredMetrics = 
Collections.unmodifiableMap(parsedRegisteredMetrics);
   }
 
   private Map<String, Metric> readConfig(String path)
diff --git 
a/extensions-contrib/prometheus-emitter/src/test/java/org/apache/druid/emitter/prometheus/MetricsTest.java
 
b/extensions-contrib/prometheus-emitter/src/test/java/org/apache/druid/emitter/prometheus/MetricsTest.java
index e37e7888d21..4567c7cd069 100644
--- 
a/extensions-contrib/prometheus-emitter/src/test/java/org/apache/druid/emitter/prometheus/MetricsTest.java
+++ 
b/extensions-contrib/prometheus-emitter/src/test/java/org/apache/druid/emitter/prometheus/MetricsTest.java
@@ -20,6 +20,7 @@
 package org.apache.druid.emitter.prometheus;
 
 import io.prometheus.client.Histogram;
+import org.apache.druid.java.util.common.ISE;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -93,4 +94,20 @@ public class MetricsTest
 
     Assert.assertTrue(actualMessage.contains(expectedMessage));
   }
+
+  @Test
+  public void testMetricsConfigurationWithNonExistentMetric()
+  {
+    Metrics metrics = new Metrics("test_4", null, true, true, null);
+    DimensionsAndCollector nonExistentDimsCollector = 
metrics.getByName("non/existent", "historical");
+    Assert.assertNull(nonExistentDimsCollector);
+  }
+
+  @Test
+  public void testMetricsConfigurationWithUnSupportedType()
+  {
+    Assert.assertThrows(ISE.class, () -> {
+      new Metrics("test_5", "src/test/resources/defaultMetricsTest.json", 
true, true, null);
+    });
+  }
 }
diff --git 
a/extensions-contrib/prometheus-emitter/src/test/resources/defaultMetricsTest.json
 
b/extensions-contrib/prometheus-emitter/src/test/resources/defaultMetricsTest.json
new file mode 100644
index 00000000000..a63e2b45470
--- /dev/null
+++ 
b/extensions-contrib/prometheus-emitter/src/test/resources/defaultMetricsTest.json
@@ -0,0 +1,3 @@
+{
+  "query/nonExistent" : { "dimensions" : ["dataSource"], "type" : 
"nonExistent", "help":  "Non supported type."}
+}


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

Reply via email to