-
Notifications
You must be signed in to change notification settings - Fork 100
Add support for DogStatsD v1.1 - value packing #762
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import ( | |
| "errors" | ||
| "math" | ||
| "strconv" | ||
| "strings" | ||
|
|
||
| "github.com/atlassian/gostatsd" | ||
| "github.com/atlassian/gostatsd/internal/pool" | ||
|
|
@@ -101,14 +102,30 @@ func (l *Lexer) Run(input []byte, namespace string) (*gostatsd.Metric, *gostatsd | |
| if l.m != nil { | ||
| l.m.Rate = l.sampling | ||
| if l.m.Type != gostatsd.SET { | ||
| v, err := strconv.ParseFloat(l.m.StringValue, 64) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| // Count number of colons to preallocate array | ||
|
||
| count := 1 | ||
| for i := 0; i < len(l.m.StringValue); i++ { | ||
| if l.m.StringValue[i] == ':' { | ||
| count++ | ||
| } | ||
| } | ||
| if math.IsNaN(v) { | ||
| return nil, nil, errNaN | ||
| values := make([]float64, 0, count) | ||
|
|
||
| for _, stringValue := range strings.Split(l.m.StringValue, ":") { | ||
| if stringValue == "" { | ||
| // SKip the value, it could be something like a.packing:1:2:|ms|#|:|c:xyz | ||
| continue | ||
| } | ||
| v, err := strconv.ParseFloat(stringValue, 64) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
| if math.IsNaN(v) { | ||
| return nil, nil, errNaN | ||
| } | ||
| values = append(values, v) | ||
| } | ||
| l.m.Value = v | ||
| l.m.Values = values | ||
| l.m.StringValue = "" | ||
| } | ||
| l.m.Tags = l.tags | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note for other reviewers: this code path is used in tests, to provide stable sorting, and making it easier to compare lists. It doesn't need to be perfect in production, just good enough in tests.