Details
Description
KAFKA-5191 recently added a new MetricNameTemplate that is used to create the MetricName objects in the producer and consumer, as we as in the newly-added generation of metric documentation. The MetricNameTemplate and the Metric.toHtmlTable do not maintain the order of the tags, which means the resulting HTML documentation will order the table of MBean attributes based upon the lexicographical ordering of the MBeans, each of which uses the lexicographical ordering of its tags. This can result in the following order:
kafka.connect:type=sink-task-metrics,connector={connector},partition={partition},task={task},topic={topic} kafka.connect:type=sink-task-metrics,connector={connector},task={task}
However, if the MBeans maintained the order of the tags then the documentation would use the following order:
kafka.connect:type=sink-task-metrics,connector={connector},task={task} kafka.connect:type=sink-task-metrics,connector={connector},task={task},topic={topic},partition={partition}
This would be more readable, and the code that is creating the templates would have control over the order of the tags.
To maintain order, MetricNameTemplate should used a LinkedHashSet for the tags, and the Metrics.toHtmlTable method should also use a LinkedHashMap when building up the tags used in the MBean name.
Note that JMX MBean names use ObjectName that does not maintain order, so this change should have no impact on JMX MBean names.