Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leverages the interpolated help when the matching rule is cached (fixes #612) #613

Merged
merged 1 commit into from
Jun 16, 2021
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 @@ -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);
}
}