Skip to content

Commit c55a252

Browse files
committed
Handle digit separators in values
Signed-off-by: Zach Leinweber <[email protected]>
1 parent 621139e commit c55a252

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

exporter/util.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"math"
2323
"net/http"
2424
"net/url"
25+
"regexp"
2526
"strconv"
2627
"strings"
2728
"text/template"
@@ -34,6 +35,8 @@ import (
3435
pconfig "github.com/prometheus/common/config"
3536
)
3637

38+
var sanitzieValueRE = regexp.MustCompile(`(,|_)`)
39+
3740
func MakeMetricName(parts ...string) string {
3841
return strings.Join(parts, "_")
3942
}
@@ -43,7 +46,7 @@ func SanitizeValue(s string) (float64, error) {
4346
var value float64
4447
var resultErr string
4548

46-
if value, err = strconv.ParseFloat(s, 64); err == nil {
49+
if value, err = strconv.ParseFloat(sanitzieValueRE.ReplaceAllString(s, ""), 64); err == nil {
4750
return value, nil
4851
}
4952
resultErr = fmt.Sprintf("%s", err)

exporter/util_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ func TestSanitizeValue(t *testing.T) {
2626
}{
2727
{"1234", 1234.0, true},
2828
{"1234.5", 1234.5, true},
29+
{"123,456.5", 123456.5, true},
30+
{"123,456,789.5", 123456789.5, true},
31+
{"123_456_789.5", 123456789.5, true},
2932
{"true", 1.0, true},
3033
{"TRUE", 1.0, true},
3134
{"False", 0.0, true},

0 commit comments

Comments
 (0)