MCPcopy
hub / github.com/prometheus/client_golang / NormalizeMetricFamilies

Function NormalizeMetricFamilies

prometheus/internal/metric.go:85–101  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

83// MetricFamilies pruned and the remaining MetricFamilies sorted by name within
84// the slice, with the contained Metrics sorted within each MetricFamily.
85func 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}

Callers 3

GatherMethod · 0.92
GatherMethod · 0.92

Calls 2

MetricSorterTypeAlias · 0.85
StringsMethod · 0.80

Tested by

no test coverage detected