Simplify metricSorter timestamp comparison and improve comment

This commit is contained in:
David Nesting 2015-11-10 09:37:58 -05:00
parent 544f65f7fc
commit b0bd184e74
1 changed files with 11 additions and 15 deletions

View File

@ -723,21 +723,17 @@ func (s metricSorter) Less(i, j int) bool {
} }
} }
// While this is not strictly supported, until we have an // We should never arrive here. Multiple metrics with the same
// import API some people are having some success getting // label set in the same scrape will lead to undefined ingestion
// data imported by supplying the same metric with different // behavior. However, as above, we have to provide stable sorting
// timestamps. At the very least we shouldn't make things // here, even for inconsistent metrics. So sort equal metrics
// more difficult, so ensure that metrics get ordered by // by their timestamp, with missing timestamps (implying "now")
// timestamp so that Prometheus doesn't complain about // coming last.
// out-of-order metrics. A missing timestamp (implies "now") if s[i].TimestampMs == nil {
// will be ordered last.
if s[i].TimestampMs == nil && s[j].TimestampMs != nil {
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()
} }
if s[j].TimestampMs == nil {
return false return true
}
return s[i].GetTimestampMs() < s[j].GetTimestampMs()
} }