Commit
Author: Drew DeVault [sir@cmpwn.com]
Hash: 5d990ad87728a4b0fde29bd1b239cb04a18ddc7b
Timestamp: Wed, 08 Dec 2021 10:38:52 +0000 (3 years ago)

+9 -1 +/-1 browse
Eliminate NaN or infinite data points
1diff --git a/main.go b/main.go
2index e8fe420..2ba02e8 100644
3--- a/main.go
4+++ b/main.go
5 @@ -6,6 +6,7 @@ import (
6 "fmt"
7 "image/color"
8 "log"
9+ "math"
10 "net/http"
11 "net/url"
12 "os"
13 @@ -86,10 +87,15 @@ func Query(q string, start time.Time, end time.Time, step int) ([]PromResult, er
14 r.Metric = metricName(res.Metric)
15
16 var values []Datapoint
17+ isValid := true
18 for _, vals := range res.Values {
19 timestamp := vals[0].(float64)
20 value := vals[1].(string)
21 fv, _ := strconv.ParseFloat(value, 64)
22+ if math.IsNaN(fv) || math.IsInf(fv, 0) {
23+ isValid = false
24+ break
25+ }
26 values = append(values, Datapoint{
27 time.Unix(int64(timestamp), 0),
28 fv,
29 @@ -97,7 +103,9 @@ func Query(q string, start time.Time, end time.Time, step int) ([]PromResult, er
30 }
31 r.Values = values
32
33- results = append(results, r)
34+ if isValid {
35+ results = append(results, r)
36+ }
37 }
38 return results, nil
39 }