Skip to content

Commit

Permalink
Merge pull request prometheus#616 from brian-brazil/yotta-infinity
Browse files Browse the repository at this point in the history
Avoid +InfYs and similar, just display +Inf.
  • Loading branch information
juliusv committed Mar 28, 2015
2 parents 7793651 + 941f585 commit 52d89b2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions rules/ast/quantile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 5 additions & 2 deletions templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 := ""
Expand All @@ -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)
}
Expand Down
7 changes: 7 additions & 0 deletions templates/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package templates

import (
"math"
"testing"

clientmodel "github.com/prometheus/client_golang/model"
Expand Down Expand Up @@ -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 }}",
Expand Down

0 comments on commit 52d89b2

Please sign in to comment.