-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
Closes #77
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,11 +31,14 @@ func (m Metrics) incRequestsTotal(method string) { | |
// incErrorsTotal increases the counter for this error atomically by one. | ||
func (m Metrics) incErrorsTotal(err error) { | ||
msg := err.Error() | ||
if _, ok := ErrStatusCodes[err]; !ok { | ||
msg = "system error" | ||
} | ||
|
||
atomic.AddUint64(m.ErrorsTotal[msg], 1) | ||
if addr, ok := m.ErrorsTotal[msg]; ok { | ||
atomic.AddUint64(addr, 1) | ||
} else { | ||
addr := new(uint64) | ||
*addr = 1 | ||
m.ErrorsTotal[msg] = addr | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Acconut
Author
Member
|
||
} | ||
} | ||
|
||
// incBytesReceived increases the number of received bytes atomically be the | ||
|
@@ -78,13 +81,6 @@ func newMetrics() Metrics { | |
} | ||
|
||
func newErrorsTotalMap() map[string]*uint64 { | ||
m := make(map[string]*uint64, len(ErrStatusCodes)+1) | ||
|
||
for err := range ErrStatusCodes { | ||
m[err.Error()] = new(uint64) | ||
} | ||
|
||
m["system error"] = new(uint64) | ||
|
||
m := make(map[string]*uint64, 20) | ||
return m | ||
} |
In some corner cases, there might be a race-condition here (two threads writing to the
m.ErrorsTotal
).It's not dramatic, since it means that a couple of first errors might no be counted, but it could be solved via a buffered channel used to send all the error messages to one goroutine writer. This goroutine would be the only responsible for updating the map (you could then use a
map[string]int
for the storage).I would be happy to make a PR if you wish!