Skip to content

Commit

Permalink
mozzle: Fix Riemann emitter race condition
Browse files Browse the repository at this point in the history
Fixes #11.
  • Loading branch information
Bo0mer committed Jan 31, 2017
1 parent 73268b0 commit 00c793d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion riemann.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ func (r *RiemannEmitter) Emit(m Metric) {
e.Service = m.Service
e.Metric = m.Metric
e.State = m.State
e.Attributes = m.Attributes
// Since we're modifying the map, we need a copy.
e.Attributes = copyMap(m.Attributes)
if e.Attributes == nil {
e.Attributes = make(map[string]string)
}
Expand Down Expand Up @@ -128,3 +129,15 @@ func (r *riemann) Close() error {
func (r *riemann) SendEvent(e *raidman.Event) error {
return r.client.Send(e)
}

// copyMap returns a copy of m. If m is nil, copyMap returns nil.
func copyMap(m map[string]string) map[string]string {
if m == nil {
return nil
}
cpy := make(map[string]string)
for k, v := range m {
cpy[k] = v
}
return cpy
}

0 comments on commit 00c793d

Please sign in to comment.