Thanks Siddharth Wagle for reporting the issue and posting the patch. The latest patch v2 with the JMXGet issue fixed looks good to me overall.
Here are a few minor issues:
1. In TopMetrics#getMetrics(), should we check if top metrics is enabled or not like we do in FSNamesystem#getTopUserOpCounts. Or have a unit test verify that the metrics source works as expected when top metrics is not enabled.
2. I notice that the patch added a metric record per window. So there would be multiple record per getMetrics() call for each window. Can we elaborate this in the description of the comments?
3. Checkstyle issue from Jenkins.
4. You may also add context info into this ticket.
HDFS-6982 has a Metrics2 source implemented but was removed as part of HDFS-7426 "Change nntop JMX format to be a JSON blob".