quipo / statsd

Golang StatsD client
MIT License
164 stars 51 forks source link

unable to use Incr and PrecisionTiming with the same key #28

Closed algrebe closed 8 years ago

algrebe commented 8 years ago

I want to use the same key in both Incr and PrecisionTiming. I assumed that the internal logic would take care of using prefixes like "timers" and other things like ".count", ".avg", etc. https://github.com/quipo/statsd/blob/master/bufferedclient.go#L147 is calling update because it thinks they are the same type since they are hashed only based on key and not based on type as well.

However, according to https://github.com/quipo/statsd/blob/master/event/precisiontiming.go#L23 they have to be of the same type - which makes sense here.

algrebe commented 8 years ago

a quick fix could be using key instead of k in sb.events ?


k := strings.Replace(e.Key(), "%HOST%", Hostname, 1)
e.SetKey(k)
key := fmt.Sprintf("%s|%s", e.TypeString(), k)
if e2, ok := sb.events[key]; ok {
    //sb.Logger.Println("Updating existing event")
    e2.Update(e)
    sb.events[key] = e2
} else {
    //sb.Logger.Println("Adding new event")
    sb.events[key] = e
}
algrebe commented 8 years ago

@quipo thank you!