Skip to content

Remove human friendly digit group separators#141

Open
zleinweber wants to merge 1 commit into
prometheus-community:masterfrom
zleinweber:sanitize_digit_separators
Open

Remove human friendly digit group separators#141
zleinweber wants to merge 1 commit into
prometheus-community:masterfrom
zleinweber:sanitize_digit_separators

Conversation

@zleinweber

@zleinweber zleinweber commented Feb 10, 2022

Copy link
Copy Markdown

Some APIs that return numeric values as a string that include commas or underscores to separate digit groups. For example, "1,000". This causes an error in SanitizeValue when the string gets passed into strconv.ParseFloat().

This fixes the problem above transparently.

Signed-off-by: Zach Leinweber <zach.leinweber@aquatic.com>
@zleinweber zleinweber force-pushed the sanitize_digit_separators branch from e392410 to c55a252 Compare February 10, 2022 20:47
Comment thread exporter/util.go
pconfig "github.com/prometheus/common/config"
)

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

Copy link
Copy Markdown
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
Copy Markdown
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(",", "", "_", "")

Comment thread exporter/util.go
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
Copy Markdown
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 {

@SuperQ SuperQ requested a review from rustycl0ck July 3, 2022 08:52

@SuperQ SuperQ left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please use strings instead of regexp.

@SuperQ

SuperQ commented Jun 6, 2023

Copy link
Copy Markdown
Contributor

Ping, please resolve requested changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants