Skip to content

Commit

Permalink
Leverages the interpolated help when the matching rule is cached (fixes
Browse files Browse the repository at this point in the history
#612)

Signed-off-by: Pascal Davoust <[email protected]>
  • Loading branch information
Pascal Davoust committed Jun 14, 2021
1 parent 116a1c4 commit b21410d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Expand Down
14 changes: 14 additions & 0 deletions collector/src/test/java/io/prometheus/jmx/JmxCollectorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<MetricFamilySamples> samples = jc.collect();
assertEquals("help message", samples.get(0).help);
samples = jc.collect();
assertEquals("help message", samples.get(0).help);
}
}

0 comments on commit b21410d

Please sign in to comment.