diff --git a/cmd/nginx/main.go b/cmd/nginx/main.go index 0018b435e..58efb26c7 100644 --- a/cmd/nginx/main.go +++ b/cmd/nginx/main.go @@ -121,7 +121,10 @@ func main() { reg := prometheus.NewRegistry() reg.MustRegister(prometheus.NewGoCollector()) - reg.MustRegister(prometheus.NewProcessCollector(os.Getpid(), "")) + reg.MustRegister(prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{ + PidFn: func() (int, error) { return os.Getpid(), nil }, + ReportErrors: true, + })) mc, err := metric.NewCollector(conf.ListenPorts.Status, reg) if err != nil { diff --git a/internal/ingress/metric/collectors/testutils.go b/internal/ingress/metric/collectors/testutils.go index b00940336..912e454d6 100644 --- a/internal/ingress/metric/collectors/testutils.go +++ b/internal/ingress/metric/collectors/testutils.go @@ -137,8 +137,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) @@ -181,3 +181,19 @@ func normalizeMetricFamilies(metricFamiliesByName map[string]*dto.MetricFamily) } return result } + +// 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() +}