Skip to content
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 @@ -48,10 +48,13 @@ public CollectorRegistry(boolean autoDescribe) {
*/
public void register(Collector m) {
List<String> names = collectorNames(m);
assertNoDuplicateNames(m, names);
synchronized (namesCollectorsLock) {
for (String name : names) {
if (namesToCollectors.containsKey(name)) {
throw new IllegalArgumentException("Collector already registered that provides name: " + name);
throw new IllegalArgumentException("Failed to register Collector of type " + m.getClass().getSimpleName()
+ ": " + name + " is already in use by another Collector of type "
+ namesToCollectors.get(name).getClass().getSimpleName());
}
}
for (String name : names) {
Expand All @@ -61,6 +64,16 @@ public void register(Collector m) {
}
}

private void assertNoDuplicateNames(Collector m, List<String> names) {
Set<String> uniqueNames = new HashSet<String>();
for (String name : names) {
if (!uniqueNames.add(name)) {
throw new IllegalArgumentException("Failed to register Collector of type " + m.getClass().getSimpleName()
+ ": The Collector exposes the same name multiple times: " + name);
}
}
}

/**
* Unregister a Collector.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* </pre>
* Example metrics being exported:
* <pre>
* jvm_classes_loaded{} 1000
* jvm_classes_currently_loaded{} 1000
* jvm_classes_loaded_total{} 2000
* jvm_classes_unloaded_total{} 500
* </pre>
Expand All @@ -38,7 +38,7 @@ public ClassLoadingExports(ClassLoadingMXBean clBean) {

void addClassLoadingMetrics(List<MetricFamilySamples> sampleFamilies) {
sampleFamilies.add(new GaugeMetricFamily(
"jvm_classes_loaded",
"jvm_classes_currently_loaded",
"The number of classes that are currently loaded in the JVM",
clBean.getLoadedClassCount()));
sampleFamilies.add(new CounterMetricFamily(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class ClassLoadingExportsTest {

private ClassLoadingMXBean mockClassLoadingsBean = Mockito.mock(ClassLoadingMXBean.class);
private CollectorRegistry registry = new CollectorRegistry();
private CollectorRegistry registry = new CollectorRegistry(true);
private ClassLoadingExports collectorUnderTest;

private static final String[] EMPTY_LABEL = new String[0];
Expand All @@ -31,7 +31,7 @@ public void testClassLoading() {
assertEquals(
1000,
registry.getSampleValue(
"jvm_classes_loaded", EMPTY_LABEL, EMPTY_LABEL),
"jvm_classes_currently_loaded", EMPTY_LABEL, EMPTY_LABEL),
.0000001);
assertEquals(
2000L,
Expand Down