Skip to content

Commit 2adf668

Browse files
kevinfengQianChenglong
authored andcommitted
fix: get metrics failed if values contain NaN
feat: set retention time to 2h to reduce memory usage of prometheus Signed-off-by: Feng Kun <[email protected]>
1 parent 8609e2f commit 2adf668

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

pkg/monitor/storage/thanos/metric/metric.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package metric
2121
import (
2222
"context"
2323
"fmt"
24+
"math"
2425
"strings"
2526
"time"
2627
"tkestack.io/tke/api/monitor"
@@ -222,7 +223,9 @@ func MergeResult(results model.Matrix, timestamp string, groupByWithoutTimestamp
222223
}
223224
}
224225
values[index].([]interface{})[0] = sp.Timestamp.Unix() * 1000
225-
values[index].([]interface{})[fieldIndex+1] = float64(sp.Value)
226+
if !math.IsNaN(float64(sp.Value)) {
227+
values[index].([]interface{})[fieldIndex+1] = float64(sp.Value)
228+
}
226229
for j, tag := range tags {
227230
values[index].([]interface{})[len(fieldIndexes)+1+j] = tag
228231
}

pkg/platform/controller/addon/prometheus/controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,7 @@ func createPrometheusCRD(components images.Components, clusterName string, remot
11661166
ScrapeInterval: "60s",
11671167
RemoteRead: remoteReadSpecs,
11681168
RemoteWrite: remoteWriteSpecs,
1169+
Retention: "2h",
11691170
EvaluationInterval: "1m",
11701171
AdditionalScrapeConfigs: &corev1.SecretKeySelector{
11711172
LocalObjectReference: corev1.LocalObjectReference{Name: prometheusSecret},

0 commit comments

Comments
 (0)