Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove human friendly digit group separators #141

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion exporter/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"math"
"net/http"
"net/url"
"regexp"
"strconv"
"strings"
"text/template"
Expand All @@ -34,6 +35,8 @@ import (
pconfig "github.com/prometheus/common/config"
)

var sanitzieValueRE = regexp.MustCompile(`(,|_)`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than use a regexp, how about a string replacer?

Suggested change
var sanitzieValueRE = regexp.MustCompile(`(,|_)`)
var sanitzieValue = strings.NewReplacer(",", "", "|", "")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- var sanitzieValue = strings.NewReplacer(",", "", "|", "")
+ var sanitzieValue = strings.NewReplacer(",", "", "_", "")


func MakeMetricName(parts ...string) string {
return strings.Join(parts, "_")
}
Expand All @@ -43,7 +46,7 @@ func SanitizeValue(s string) (float64, error) {
var value float64
var resultErr string

if value, err = strconv.ParseFloat(s, 64); err == nil {
if value, err = strconv.ParseFloat(sanitzieValueRE.ReplaceAllString(s, ""), 64); err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if value, err = strconv.ParseFloat(sanitzieValueRE.ReplaceAllString(s, ""), 64); err == nil {
if value, err = strconv.ParseFloat(sanitzieValue.Replace(s), 64); err == nil {

return value, nil
}
resultErr = fmt.Sprintf("%s", err)
Expand Down
3 changes: 3 additions & 0 deletions exporter/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ func TestSanitizeValue(t *testing.T) {
}{
{"1234", 1234.0, true},
{"1234.5", 1234.5, true},
{"123,456.5", 123456.5, true},
{"123,456,789.5", 123456789.5, true},
{"123_456_789.5", 123456789.5, true},
{"true", 1.0, true},
{"TRUE", 1.0, true},
{"False", 0.0, true},
Expand Down