Blob Blame History Raw
diff --git a/pkg/kubelet/metrics/collectors/helper_test.go b/pkg/kubelet/metrics/collectors/helper_test.go
index a63f80b932f6b..f209b87a6b8aa 100644
--- a/pkg/kubelet/metrics/collectors/helper_test.go
+++ b/pkg/kubelet/metrics/collectors/helper_test.go
@@ -120,7 +120,27 @@ func removeUnusedWhitespace(s string) string {
 	return strings.Join(trimmedLines, "\n") + "\n"
 }
 
-// The below sorting code is copied form the Prometheus client library modulo the added
+// The below code is copied from the Prometheus client library in order to work around the fact that LabelPairSorter is now unexported.
+// https://github.com/prometheus/client_golang/pull/453
+// https://github.com/prometheus/client_golang/blob/v0.9.0/prometheus/metric.go#L116-L130
+
+// labelPairSorter implements sort.Interface. It is used to sort a slice of
+// dto.LabelPair pointers.
+type labelPairSorter []*dto.LabelPair
+
+func (s labelPairSorter) Len() int {
+	return len(s)
+}
+
+func (s labelPairSorter) Swap(i, j int) {
+	s[i], s[j] = s[j], s[i]
+}
+
+func (s labelPairSorter) Less(i, j int) bool {
+	return s[i].GetName() < s[j].GetName()
+}
+
+// The below sorting code is copied from the Prometheus client library modulo the added
 // label pair sorting.
 // https://github.com/prometheus/client_golang/blob/ea6e1db4cb8127eeb0b6954f7320363e5451820f/prometheus/registry.go#L642-L684
 
@@ -136,8 +156,8 @@ func (s metricSorter) Swap(i, j int) {
 }
 
 func (s metricSorter) Less(i, j int) bool {
-	sort.Sort(prometheus.LabelPairSorter(s[i].Label))
-	sort.Sort(prometheus.LabelPairSorter(s[j].Label))
+	sort.Sort(labelPairSorter(s[i].Label))
+	sort.Sort(labelPairSorter(s[j].Label))
 
 	if len(s[i].Label) != len(s[j].Label) {
 		return len(s[i].Label) < len(s[j].Label)