Merge pull request #180 from dnesting/dnesting-sort-metrics

Make metric sort stable and sort by timestamp
This commit is contained in:
Björn Rabenstein 2015-11-10 22:31:22 +01:00
commit cfd904193d
1 changed files with 14 additions and 1 deletions

View File

@ -722,5 +722,18 @@ func (s metricSorter) Less(i, j int) bool {
return vi < vj
}
}
return true
// 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 s[i].TimestampMs == nil {
return false
}
if s[j].TimestampMs == nil {
return true
}
return s[i].GetTimestampMs() < s[j].GetTimestampMs()
}