diff --git a/collector/src/main/java/io/prometheus/jmx/JmxCollector.java b/collector/src/main/java/io/prometheus/jmx/JmxCollector.java index e49a3dc8..7758bd5f 100644 --- a/collector/src/main/java/io/prometheus/jmx/JmxCollector.java +++ b/collector/src/main/java/io/prometheus/jmx/JmxCollector.java @@ -523,7 +523,7 @@ public void recordBean( // Add to samples. LOGGER.fine("add metric sample: " + matchedRule.name + " " + matchedRule.labelNames + " " + matchedRule.labelValues + " " + value.doubleValue()); - addSample(new MetricFamilySamples.Sample(matchedRule.name, matchedRule.labelNames, matchedRule.labelValues, value.doubleValue()), matchedRule.type, help); + addSample(new MetricFamilySamples.Sample(matchedRule.name, matchedRule.labelNames, matchedRule.labelValues, value.doubleValue()), matchedRule.type, matchedRule.help); } } diff --git a/collector/src/test/java/io/prometheus/jmx/JmxCollectorTest.java b/collector/src/test/java/io/prometheus/jmx/JmxCollectorTest.java index 7952fd55..bb0593a1 100644 --- a/collector/src/test/java/io/prometheus/jmx/JmxCollectorTest.java +++ b/collector/src/test/java/io/prometheus/jmx/JmxCollectorTest.java @@ -2,11 +2,15 @@ import io.prometheus.client.Collector; import io.prometheus.client.CollectorRegistry; +import io.prometheus.client.Collector.MetricFamilySamples; + import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import java.lang.management.ManagementFactory; +import java.util.List; + import javax.management.MBeanServer; import static org.junit.Assert.assertEquals; @@ -284,4 +288,14 @@ public void testCachedBeansEnabled() throws Exception { assertTrue(registry.getSampleValue("jmx_scrape_cached_beans", new String[]{}, new String[]{}) > 0); assertEquals(4.0, registry.getSampleValue("foo", new String[]{}, new String[]{}), .001); } + + @Test + public void testCachedBeansEnabledRetainsHelpAcrossCollections() throws Exception { + JmxCollector jc = new JmxCollector("\n---\nrules:\n- pattern: `.*`\n name: foo\n value: 1\n valueFactor: 4\n cache: true\n help: help message".replace('`','"')) + .register(registry); + List samples = jc.collect(); + assertEquals("help message", samples.get(0).help); + samples = jc.collect(); + assertEquals("help message", samples.get(0).help); + } }