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

Cached rules does not retain help message across collections #612

Closed
davoustp opened this issue Jun 14, 2021 · 0 comments · Fixed by #613
Closed

Cached rules does not retain help message across collections #612

davoustp opened this issue Jun 14, 2021 · 0 comments · Fixed by #613

Comments

@davoustp
Copy link
Contributor

davoustp commented Jun 14, 2021

When a rule is flagged as cacheable (which is desirable for performance reasons when not machting on values themselves), then the first collection provides the provided HELP message for the collected metrics of the rule, but any additional collection looses this help message and falls back to the regular JMX bean description help message.

Unit test exhibiting the issue:

index 7952fd5..bb0593a 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 @@ package io.prometheus.jmx;
 
 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 class JmxCollectorTest {
         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);
+    }
 }

The second assertion fails:

org.junit.ComparisonFailure: expected:<[help message]> but was:<[BootClassPathSupported (java.lang<type=Runtime><>BootClassPathSupported)]>
@davoustp davoustp changed the title Cached rules does not retain the help message across collections Cached rules does not retain help message across collections Jun 14, 2021
davoustp pushed a commit to davoustp/jmx_exporter that referenced this issue Jun 14, 2021
prometheus#612)

Signed-off-by: Pascal Davoust <pascal.davoust@eptica.com>
fstab pushed a commit that referenced this issue Jun 16, 2021
#612) (#613)

Signed-off-by: Pascal Davoust <pascal.davoust@eptica.com>

Co-authored-by: Pascal Davoust <pascal.davoust@eptica.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant