monitoring: fix metric value NaN

Signed-off-by: huanggze <loganhuang@yunify.com>
This commit is contained in:
huanggze
2020-05-18 21:38:52 +08:00
parent af341f6fbe
commit 14069b95f2
21 changed files with 1220 additions and 175 deletions

View File

@@ -50,9 +50,22 @@ func (w wrapper) Less(i, j int) bool {
p := w.MetricValues[i]
q := w.MetricValues[j]
if p.Sample.Value() == q.Sample.Value() {
// Place Nil to the tail.
if p.Sample == nil && q.Sample != nil {
return false
}
if p.Sample != nil && q.Sample == nil {
return true
}
// If both Samples are Nil or have the same metric value, sort by resource name
if p.Sample == q.Sample || p.Sample[1] == q.Sample[1] {
return p.Metadata[w.identifier] < q.Metadata[w.identifier]
}
// Place NaN to the tail (NaN takes precedence over Nil).
if math.IsNaN(p.Sample[1]) != math.IsNaN(q.Sample[1]) {
return !math.IsNaN(p.Sample[1])
}
switch w.order {
case OrderAscending: