forked from mirror/client_golang
metricSorter stops relying on time.Now and respects nil timestamps
This commit is contained in:
parent
5fb1b89678
commit
544f65f7fc
|
@ -32,7 +32,6 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
"github.com/prometheus/common/expfmt"
|
"github.com/prometheus/common/expfmt"
|
||||||
|
@ -723,26 +722,22 @@ func (s metricSorter) Less(i, j int) bool {
|
||||||
return vi < vj
|
return vi < vj
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if s[i].GetTimestampMs() != s[j].GetTimestampMs() {
|
|
||||||
// While this is not strictly supported, until we have
|
// While this is not strictly supported, until we have an
|
||||||
// an import API some people are having some success
|
// import API some people are having some success getting
|
||||||
// getting data imported by supplying the same metric
|
// data imported by supplying the same metric with different
|
||||||
// with different timestamps. At the very least we
|
// timestamps. At the very least we shouldn't make things
|
||||||
// shouldn't make things more difficult, so ensure that
|
// more difficult, so ensure that metrics get ordered by
|
||||||
// metrics get ordered by timestamp to make it possible
|
// timestamp so that Prometheus doesn't complain about
|
||||||
// for Prometheus to import them.
|
// out-of-order metrics. A missing timestamp (implies "now")
|
||||||
ti, tj := s[i].GetTimestampMs(), s[j].GetTimestampMs()
|
// will be ordered last.
|
||||||
if ti == 0 {
|
if s[i].TimestampMs == nil && s[j].TimestampMs != nil {
|
||||||
ti = nowMillis()
|
|
||||||
} else if tj == 0 {
|
|
||||||
tj = nowMillis()
|
|
||||||
}
|
|
||||||
return ti < tj
|
|
||||||
}
|
|
||||||
return false
|
return false
|
||||||
|
} else if s[i].TimestampMs != nil && s[j].TimestampMs == nil {
|
||||||
|
return true
|
||||||
|
} else if s[i].GetTimestampMs() != s[j].GetTimestampMs() {
|
||||||
|
return s[i].GetTimestampMs() < s[j].GetTimestampMs()
|
||||||
}
|
}
|
||||||
|
|
||||||
func nowMillis() int64 {
|
return false
|
||||||
now := time.Now()
|
|
||||||
return now.Unix()*1000 + int64(now.Nanosecond())/1000000
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue