Skip to content

Commit

Permalink
Apply requested review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasbu committed Dec 12, 2022
1 parent cefeede commit 6733d41
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions reporters/dogstatsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type DogStatsD struct {
client dogstatsd.Client
logger *logrus.Logger
statsdClient *statsd.Client
mutex sync.Mutex
mutex sync.RWMutex
ticker *time.Ticker
region string
host string
Expand All @@ -45,15 +45,15 @@ func toMapStringString(o map[string]interface{}) map[string]string {
// Report finds a matching handler to some 'event' metric and delegates
// further actions to it
func (d *DogStatsD) Report(event string, opts map[string]interface{}) error {
d.mutex.Lock()
defer d.mutex.Unlock()
handlerI, prs := handlers.Find(event)
if prs == false {
return fmt.Errorf("reportHandler for %s doesn't exist", event)
}
opts[constants.TagRegion] = d.region
handler := handlerI.(func(dogstatsd.Client, string, map[string]string) error)
d.mutex.Lock()
err := handler(d.client, event, toMapStringString(opts))
d.mutex.Unlock()
if err != nil {
d.logger.Error(err)
}
Expand Down Expand Up @@ -117,15 +117,17 @@ func (d *DogStatsD) restartTicker() {
d.mutex.Lock()
if err := d.statsdClient.Close(); err != nil {
d.logger.Errorf("DogStatsD: failed to close statsd connection during restart: %s", err.Error())
d.mutex.Unlock()
continue
}
d.mutex.Unlock()


c, err := dogstatsd.New(d.host, d.prefix)
if err == nil {
d.statsdClient = c.Client.(*statsd.Client)
d.client = c
} else {
d.logger.Errorf("DogStatsD: failed to recreate dogstatsd client during restart. %s", err.Error())
}
d.mutex.Unlock()
}
}

0 comments on commit 6733d41

Please sign in to comment.