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

Relative gauges #40

Merged
merged 1 commit into from
Dec 14, 2014
Merged

Conversation

JamesCohen-awin
Copy link
Contributor

The etsy statsd implementation includes support for relative operations on gauges (see https://github.com/etsy/statsd/blob/master/docs/metric_types.md#gauges). I've attempted to duplicate this functionality.

I followed the statsd specs and retained the gauges as uint64 values.

This is my first attempt at coding in Go. Please be gentle!

@mreiferson
Copy link
Contributor

I need to comb through the actual code, but it looks like it could use a little go fmt in the meantime.

Thanks for all these contributions @JamesCohen-awin

@JamesCohen-awin
Copy link
Contributor Author

Thanks - didn't know about go fmt

@JamesCohen-awin
Copy link
Contributor Author

rebased to current HEAD 1ac36f2

@@ -349,6 +397,32 @@ func parseMessage(data []byte) []*Packet {
log.Printf("ERROR: failed to ParseInt %s - %s", string(val), err)
continue
}
} else if mtypeStr[0] == 'g' {

var (
Copy link
Contributor

Choose a reason for hiding this comment

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

style 👮

We don't normally use this style of var declarations, would you mind using one per line?

Also, can you remove any instances of vertical whitespace after the start of a block? (like above the start of var here)

Thanks!

@mreiferson
Copy link
Contributor

@JamesCohen-awin thanks again, this looks good functionally - just had a few style/go idiom nitpicks

JamesCohen-awin pushed a commit to JamesCohen-awin/statsdaemon that referenced this pull request Dec 14, 2014
@JamesCohen-awin
Copy link
Contributor Author

Thanks - all of the suggestions made perfect sense

switch val[0] {
case '+', '-':
relative = true
negative = string(val[0]) == "-"
Copy link
Contributor

Choose a reason for hiding this comment

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

missed this the first time around, don't need the string(), use the "rune check" from my previous comment

@JamesCohen-awin
Copy link
Contributor Author

give me a sec and I'll squash all of this down into a single commit

for g, c := range gauges {
if c == math.MaxUint64 {

var lastValue uint64
Copy link
Contributor

Choose a reason for hiding this comment

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

you can drop this var declaration, the next line is all that's necessary (it uses :=)

@@ -122,7 +129,39 @@ func packetHandler(s *Packet) {
}
timers[s.Bucket] = append(timers[s.Bucket], s.Value.(uint64))
} else if s.Modifier == "g" {
gauges[s.Bucket] = s.Value.(uint64)
var gaugeValue uint64 = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

all int types have a default value of 0, so you can drop the = 0

@JamesCohen-awin
Copy link
Contributor Author

I can't fix/squash/push fast enough ;)

Going to wait until you're done and re-push

@mreiferson
Copy link
Contributor

P.S. in the future you don't have to squash as we're going through code review... What we normally do is wait for a PR to get to a "LGTM" stage and then squash.

Not only is this an easier back-and-forth, but it allows the reviewer to see the changes as individual commits as they're happening, rather than losing context.

@mreiferson
Copy link
Contributor

and I think I got everything now 😁

@JamesCohen-awin
Copy link
Contributor Author

All sorted and thanks for the education

edit: just saw the bit about the LGTM too. Noted for next time.

@mreiferson
Copy link
Contributor

awesome, nice work and thanks again for all your contributions!

mreiferson added a commit that referenced this pull request Dec 14, 2014
@mreiferson mreiferson merged commit a2b98e3 into bitly:master Dec 14, 2014
@JamesCohen-awin JamesCohen-awin deleted the relative-gauges branch December 14, 2014 19:08
@JamesCohen-awin JamesCohen-awin mentioned this pull request Dec 14, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants