mirror of https://github.com/apache/druid.git
[Prometheus Emitter] Add to code coverage and remove code smell (#17362)
* [Prometheus Emitter] Add to code coverage and remove code smell
This commit is contained in:
parent
26e2ca66d7
commit
90175b8927
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"query/nonExistent" : { "dimensions" : ["dataSource"], "type" : "nonExistent", "help": "Non supported type."}
|
||||
}
|
Loading…
Reference in New Issue