Uploaded image for project: 'Ignite'
  1. Ignite
  2. IGNITE-12768

MetricRegistryMBean doesn't show histogram values in case when histogram name contains underscore character

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.8.1
    • Component/s: None
    • Labels:

      Description

      MetricRegistryMBean doesn't show histogram values in case when histogram name contains underscore character.

      The problem in MetricRegistryMBean.searchHistogram() method which relies on first underscore character in the fully qualified metric name. This method also use relatively old and not effective API for string parsing (this API implementation is synchronized). It should be replaced by simple String.lastIndexOf() for example.

      Reproducer:

      package org.apache.ignite.spi.metric.jmx;
      
      import org.apache.ignite.Ignite;
      import org.apache.ignite.IgniteException;
      import org.apache.ignite.configuration.IgniteConfiguration;
      import org.apache.ignite.internal.IgniteEx;
      import org.apache.ignite.internal.processors.metric.MetricRegistry;
      import org.apache.ignite.internal.util.typedef.internal.U;
      import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
      import org.junit.Test;
      
      import javax.management.*;
      import java.lang.management.ManagementFactory;
      
      
      public class MetricRegistryMBeanTest extends GridCommonAbstractTest {
          private static final String REGISTRY_NAME = "test_registry";
          private static final String VALID_HISTOGRAM_NAME = "testhist";
          private static final String INVALID_HISTOGRAM_NAME = "test_hist";
      
          @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
              IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
      
              JmxMetricExporterSpi exporterSpi = new JmxMetricExporterSpi();
      
              cfg.setMetricExporterSpi(exporterSpi);
      
              return cfg;
          }
      
          @Test public void testBean() throws Exception {
              Ignite ignite = startGrid();
      
              MetricRegistry reg = ((IgniteEx)ignite).context().metric().registry(REGISTRY_NAME);
      
              reg.histogram(VALID_HISTOGRAM_NAME, new long[] {10, 100}, null);
              reg.histogram(INVALID_HISTOGRAM_NAME, new long[] {10, 100}, null);
      
              assertNotNull(mbean(ignite).getAttribute(VALID_HISTOGRAM_NAME + '_' + 10 + '_' + 100));
              assertEquals(0L, mbean(ignite).getAttribute(VALID_HISTOGRAM_NAME + '_' + 10 + '_' + 100));
              assertNotNull(mbean(ignite).getAttribute(INVALID_HISTOGRAM_NAME + '_' + 10 + '_' + 100));
              assertEquals(0L, mbean(ignite).getAttribute(INVALID_HISTOGRAM_NAME + '_' + 10 + '_' + 100));
          }
      
          private static DynamicMBean mbean(Ignite ignite) {
              try {
                  ObjectName mbeanName = U.makeMBeanName(ignite.name(), null, REGISTRY_NAME);
      
                  MBeanServer mbeanSrv = ManagementFactory.getPlatformMBeanServer();
      
                  if (!mbeanSrv.isRegistered(mbeanName))
                      fail("MBean is not registered: " + mbeanName.getCanonicalName());
      
                  return MBeanServerInvocationHandler.newProxyInstance(mbeanSrv, mbeanName, DynamicMBean.class, false);
              } catch (MalformedObjectNameException e) {
                  throw new IgniteException(e);
              }
          }
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                nizhikov Nikolay Izhikov
                Reporter:
                agura Andrey N. Gura
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 40m
                  40m