mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
Avoid +InfYs and similar, just display +Inf.
This commit is contained in:
parent
b841ae41cd
commit
941f585164
|
@ -25,8 +25,8 @@ import (
|
|||
// excludedLabels are the labels to exclude from signature calculation for
|
||||
// quantiles.
|
||||
var excludedLabels = map[clientmodel.LabelName]struct{}{
|
||||
clientmodel.MetricNameLabel: struct{}{},
|
||||
clientmodel.BucketLabel: struct{}{},
|
||||
clientmodel.MetricNameLabel: {},
|
||||
clientmodel.BucketLabel: {},
|
||||
}
|
||||
|
||||
type bucket struct {
|
||||
|
|
|
@ -140,7 +140,7 @@ func NewTemplateExpander(text string, name string, data interface{}, timestamp c
|
|||
return v
|
||||
},
|
||||
"humanize": func(v float64) string {
|
||||
if v == 0 {
|
||||
if v == 0 || math.IsNaN(v) || math.IsInf(v, 0) {
|
||||
return fmt.Sprintf("%.4g", v)
|
||||
}
|
||||
if math.Abs(v) >= 1 {
|
||||
|
@ -165,7 +165,7 @@ func NewTemplateExpander(text string, name string, data interface{}, timestamp c
|
|||
return fmt.Sprintf("%.4g%s", v, prefix)
|
||||
},
|
||||
"humanize1024": func(v float64) string {
|
||||
if math.Abs(v) <= 1 {
|
||||
if math.Abs(v) <= 1 || math.IsNaN(v) || math.IsInf(v, 0) {
|
||||
return fmt.Sprintf("%.4g", v)
|
||||
}
|
||||
prefix := ""
|
||||
|
@ -179,6 +179,9 @@ func NewTemplateExpander(text string, name string, data interface{}, timestamp c
|
|||
return fmt.Sprintf("%.4g%s", v, prefix)
|
||||
},
|
||||
"humanizeDuration": func(v float64) string {
|
||||
if math.IsNaN(v) || math.IsInf(v, 0) {
|
||||
return fmt.Sprintf("%.4g", v)
|
||||
}
|
||||
if v == 0 {
|
||||
return fmt.Sprintf("%.4gs", v)
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
package templates
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
|
||||
clientmodel "github.com/prometheus/client_golang/model"
|
||||
|
@ -122,6 +123,12 @@ func TestTemplateExpansion(t *testing.T) {
|
|||
input: []float64{.1, .0001, .12345, 60.1, 60.5, 1.2345, 12.345},
|
||||
output: "100ms:100us:123.5ms:1m 0s:1m 0s:1.234s:12.35s:",
|
||||
},
|
||||
{
|
||||
// Humanize* Inf and NaN.
|
||||
text: "{{ range . }}{{ humanize . }}:{{ humanize1024 . }}:{{ humanizeDuration . }}:{{ end }}",
|
||||
input: []float64{math.Inf(1), math.Inf(-1), math.NaN()},
|
||||
output: "+Inf:+Inf:+Inf:-Inf:-Inf:-Inf:NaN:NaN:NaN:",
|
||||
},
|
||||
{
|
||||
// Title.
|
||||
text: "{{ \"aa bb CC\" | title }}",
|
||||
|
|
Loading…
Reference in a new issue