-
Notifications
You must be signed in to change notification settings - Fork 994
Commit
…Registry (fixes #6)
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,15 +15,16 @@ | |
*/ | ||
package org.springframework.metrics.instrument.prometheus; | ||
|
||
import io.prometheus.client.CollectorRegistry; | ||
import io.prometheus.client.*; | ||
import io.prometheus.client.Gauge; | ||
import io.prometheus.client.SimpleCollector; | ||
import io.prometheus.client.Summary; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.metrics.instrument.*; | ||
import org.springframework.metrics.instrument.Counter; | ||
import org.springframework.metrics.instrument.internal.AbstractMeterRegistry; | ||
|
||
import java.lang.ref.WeakReference; | ||
import java.lang.reflect.Field; | ||
import java.util.Map; | ||
import java.util.function.ToDoubleFunction; | ||
import java.util.function.UnaryOperator; | ||
import java.util.stream.Collectors; | ||
|
@@ -100,6 +101,21 @@ private <B extends SimpleCollector.Builder<B, C>, C extends SimpleCollector<D>, | |
|
||
collector = collectorTransform.apply(collector); | ||
|
||
// since we don't yet create Histograms, the full name will be one of the metrics registered | ||
// with the collector registry | ||
// FIXME we should expose a getter on namesToCollectors in CollectorRegistry | ||
try { | ||
Field namesToCollectorsField = registry.getClass().getDeclaredField("namesToCollectors"); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
checketts
Contributor
|
||
namesToCollectorsField.setAccessible(true); | ||
@SuppressWarnings("unchecked") Map<String, Collector> namesToCollectors = | ||
(Map<String, Collector>) namesToCollectorsField.get(registry); | ||
if(!namesToCollectors.containsKey(name)) { | ||
registry.register(collector); | ||
} | ||
} catch (NoSuchFieldException | IllegalAccessException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
return collector.labels(StreamSupport.stream(tags.spliterator(), false) | ||
.map(Tag::getValue) | ||
.collect(Collectors.toList()) | ||
|
@checketts Do you think we could get a public getter on this in
simpleclient
?