It would be nice to order the names in the Metrics endpoint alphabetically.
Comment From: wilkinsona
Thanks for the suggestion. This is a duplicate of #6321 and #3761. I still believe that sorting should be done on the client-side when it is needed.
Comment From: marceloverdijk
I understand closing the issue. In my case the browser was the client and I cannot command it to order the list ;-) . I was looking for all metrics available and being the list not ordered made it a bit difficult to see what is exposed.
Comment From: wilkinsona
I was going to suggest that a JSON plugin for your browser will sort the response, but that's not the case (or at least it shouldn't be) for an array. I'm now wondering it we should reconsider.
The previous issues were opened in the context of Spring Boot 1.x, where things were different in comparison to 2.x in a couple of ways that are significant here. In 2.x, the metrics endpoint is really only intended for diagnostic purposes with exporting via Micrometer to a metrics backend being the recommend way to consume them. That means that it's more likely be a human accessing the endpoint and, therefore, sorting the metric names on the server side is less likely to be wasted effort. Secondly, the metrics names are now listed in an array with the option to then drill down into individual metrics to get more detailed information. Unlike maps, an array in JSON implies some ordering so clients that would automatically sort a map alphabetically won't sort an array in the same way.
In short, I think there's more benefit to sorting things now and the cost of always doing so is less of a concern than it was before.
Comment From: marceloverdijk
@wilkinsona I appreciate it to re-consider it. On a side note, other endpoints, like beans, also are not sorted, although these are not arrays as you mentioned already; maybe a different JSON plugin can help here. Personally I always like the loggers endpoint (also not an array btw) but is ordered nicely which is very nice for the eyes ;-)