Refactor displayCountryStats
Some refactoring and clarity changes around displayCountryStats in the broker metrics code.
The function gets renamed formatAndClearCountryStats to highlight the fact
that it has a side effect of clearing the map,
which is necessary for proper daily metrics reporting (cf. !606 (merged)).
- Swap the order of the
sort.Interface.Lessfunction, to avoid a confusingsort.Reversewhen ordering the list. - Move the
recordtypes closer to the function where they are used. - Use a
strings.Builderinstead of repeatedstringconcatenation. - Don't redundantly look up the count for each country, when
sync.Map.Rangealready gives us that. - Add documentation comments.
- Add a test that the map gets cleared after the function is called.