client_java
client_java copied to clipboard
Discussion - New `PeriodicCollector` to handle a slow `Collector`?
Current Scenario:
Currently, all Collectors
are collected inline... i.e. when...
public Enumeration<Collector.MetricFamilySamples> metricFamilySamples();
... and similar methods are called. This works well for Collectors
that are performant.
However, some Collectors
have code paths that are computationally expensive to call during a scrape interval.
Solution 1 - Decrease the scrape interval/increase the scrape timeout.
This will work, but delays the collection of all metrics, simply because 1 of N Collectors
is slow.
Solution 2 - Refactor the slow Collector
Refactoring the Collector
may not be possible due to the nature of the code, timing, locks, etc. Additionally, the code may be closed source.
Solution 3 - Add a new PeriodCollector
We could create a PeriodicCollector
implementation (totally optionally to use) that can wrap an existing Collector
and perform the collection on a periodic interval (fixed rate or fix delay) and decouple the collection of metrics.
Thoughts?
Initial implementation of a PeriodicCollector
and PeridocCollectorTest
...
https://github.com/dhoard/client_java/blob/periodic_collector/simpleclient/src/main/java/io/prometheus/client/PeriodicCollector.java
https://github.com/dhoard/client_java/blob/periodic_collector/simpleclient/src/test/java/io/prometheus/client/PeriodicCollectorTest.java