Github user tillrohrmann commented on a diff in the pull request:
https://github.com/apache/flink/pull/2112#discussion_r67870675
--- Diff:
flink-core/src/test/java/org/apache/flink/metrics/reporter/JMXReporterTest.java
---
@@ -51,4 +69,106 @@ public void testGenerateName() {
assertEquals("org.apache.flink.metrics:key0=value0,key1=value1,key2=value2_(test)------,name=TestMetric",
jmxName);
}
+
+ /**
+ * Tests that histograms are properly reported via the JMXReporter.
+ */
+ @Test
+ public void testHistogramReporting() throws
MalformedObjectNameException, IntrospectionException,
InstanceNotFoundException, ReflectionException, AttributeNotFoundException,
MBeanException {
+ MetricRegistry registry = null;
+ String histogramName = "histogram";
+
+ try {
+ Configuration config = new Configuration();
+
+ registry = new MetricRegistry(config);
+
+ TaskManagerMetricGroup metricGroup = new
TaskManagerMetricGroup(registry, "localhost", "tmId");
+
+ TestingHistogram histogram = new TestingHistogram();
+
+ registry.register(histogram, histogramName,
metricGroup);
+
+ MBeanServer mBeanServer =
ManagementFactory.getPlatformMBeanServer();
+
+ ObjectName objectName = new
ObjectName(JMXReporter.generateJmxName(histogramName,
metricGroup.getScopeComponents()));
+
+ MBeanInfo info = mBeanServer.getMBeanInfo(objectName);
+
+ MBeanAttributeInfo[] attributeInfos =
info.getAttributes();
+
+ assertEquals(11, attributeInfos.length);
+
+ for (MBeanAttributeInfo attributeInfo : attributeInfos)
{
+ Object attribute =
mBeanServer.getAttribute(objectName, attributeInfo.getName());
+
+ assertNotNull(attribute);
+
+ if (attributeInfo.getType().equals("long")) {
+ assertEquals(42L, attribute);
+ } else if
(attributeInfo.getType().equals("double")) {
+ assertEquals(42.0, attribute);
+ } else {
+ fail("Could not convert into type " +
attributeInfo.getType());
+ }
+ }
+ } finally {
+ if (registry != null) {
+ registry.shutdown();
+ }
+ }
+ }
+
+ static class TestingHistogram implements Histogram {
+
+ @Override
+ public void update(long value) {
+
+ }
+
+ @Override
+ public long getCount() {
+ return 42;
+ }
+
+ @Override
+ public HistogramStatistics getStatistics() {
+ return new HistogramStatistics() {
+ @Override
+ public double getValue(double quantile) {
+ return 42;
+ }
+
+ @Override
+ public long[] getValues() {
+ return new long[0];
+ }
+
+ @Override
+ public int size() {
+ return 42;
--- End diff --
That is true. Will fix it. Good catch :-)
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---