Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Prometheus Emitter] Add to code coverage and remove code smell #17362

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public DimensionsAndCollector getByName(String name, String service)

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) {
Expand Down Expand Up @@ -116,10 +116,10 @@ public Metrics(String namespace, String path, boolean isAddHostAsLabel, boolean
}

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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -93,4 +94,20 @@ public void testMetricsConfigurationWithBadExtraLabels()

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);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"query/nonExistent" : { "dimensions" : ["dataSource"], "type" : "nonExistent", "help": "Non supported type."}
}
Loading