Copyright 2018 The Prometheus Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

package internal

import (
	

	dto 
)
metricSorter is a sortable slice of *dto.Metric.
type metricSorter []*dto.Metric

func ( metricSorter) () int {
	return len()
}

func ( metricSorter) (,  int) {
	[], [] = [], []
}

func ( metricSorter) (,  int) bool {
This should not happen. The metrics are inconsistent. However, we have to deal with the fact, as people might use custom collectors or metric family injection to create inconsistent metrics. So let's simply compare the number of labels in this case. That will still yield reproducible sorting.
		return len([].Label) < len([].Label)
	}
	for ,  := range [].Label {
		 := .GetValue()
		 := [].Label[].GetValue()
		if  !=  {
			return  < 
		}
	}
We should never arrive here. Multiple metrics with the same label set in the same scrape will lead to undefined ingestion behavior. However, as above, we have to provide stable sorting here, even for inconsistent metrics. So sort equal metrics by their timestamp, with missing timestamps (implying "now") coming last.
	if [].TimestampMs == nil {
		return false
	}
	if [].TimestampMs == nil {
		return true
	}
	return [].GetTimestampMs() < [].GetTimestampMs()
}
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.
func ( map[string]*dto.MetricFamily) []*dto.MetricFamily {
	for ,  := range  {
		sort.Sort(metricSorter(.Metric))
	}
	 := make([]string, 0, len())
	for ,  := range  {
		if len(.Metric) > 0 {
			 = append(, )
		}
	}
	sort.Strings()
	 := make([]*dto.MetricFamily, 0, len())
	for ,  := range  {
		 = append(, [])
	}
	return