NormalizeMetricFamilies returns a MetricFamily slice with empty MetricFamilies pruned and the remaining MetricFamilies sorted by name within the slice, with the contained Metrics sorted within each MetricFamily.
(metricFamiliesByName map[string]*dto.MetricFamily)
| 83 | // MetricFamilies pruned and the remaining MetricFamilies sorted by name within |
| 84 | // the slice, with the contained Metrics sorted within each MetricFamily. |
| 85 | func NormalizeMetricFamilies(metricFamiliesByName map[string]*dto.MetricFamily) []*dto.MetricFamily { |
| 86 | for _, mf := range metricFamiliesByName { |
| 87 | sort.Sort(MetricSorter(mf.Metric)) |
| 88 | } |
| 89 | names := make([]string, 0, len(metricFamiliesByName)) |
| 90 | for name, mf := range metricFamiliesByName { |
| 91 | if len(mf.Metric) > 0 { |
| 92 | names = append(names, name) |
| 93 | } |
| 94 | } |
| 95 | sort.Strings(names) |
| 96 | result := make([]*dto.MetricFamily, 0, len(names)) |
| 97 | for _, name := range names { |
| 98 | result = append(result, metricFamiliesByName[name]) |
| 99 | } |
| 100 | return result |
| 101 | } |
no test coverage detected