Skip to content

Commit

Permalink
Add logs to reporter and watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasbu committed Dec 19, 2022
1 parent b4eb802 commit 60482f8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion metadata/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
package metadata

//Version of Maestro
var Version = "9.6.1"
var Version = "9.15.1"

//KubeVersion is the desired Kubernetes version
var KubeVersion = "v1.13.9"
9 changes: 5 additions & 4 deletions reporters/dogstatsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ func (d *DogStatsD) Report(event string, opts map[string]interface{}) error {
defer d.mutex.RUnlock()
handlerI, prs := handlers.Find(event)
if prs == false {
return fmt.Errorf("reportHandler for %s doesn't exist", event)
return fmt.Errorf("DogStatsD: reportHandler for %s doesn't exist", event)
}
opts[constants.TagRegion] = d.region
handler := handlerI.(func(dogstatsd.Client, string, map[string]string) error)
err := handler(d.client, event, toMapStringString(opts))
if err != nil {
d.logger.Error(err)
return fmt.Errorf("DogStatsD: failed to report event '%s': %w", event, err)
}
return err
return nil
}

// MakeDogStatsD adds a DogStatsD struct to the Reporters' singleton
Expand Down Expand Up @@ -116,7 +116,7 @@ func (d *DogStatsD) restartTicker() {
for range d.ticker.C {
d.mutex.Lock()
if err := d.restartDogStatsdClient(); err != nil {
d.logger.Errorf("DogStatsD: failed to close statsd connection during restart: %s", err.Error())
d.logger.WithError(err).Errorf("DogStatsD: failed to close statsd connection during restart")
}
d.mutex.Unlock()
}
Expand All @@ -133,6 +133,7 @@ func (d *DogStatsD) restartDogStatsdClient() error {
return fmt.Errorf("failed to recreate dogstatsd client: %w", err)
}

d.logger.Info("DogStatsD was restarted successfully")
d.statsdClient = c.Client.(*statsd.Client)
d.client = c
return nil
Expand Down
6 changes: 2 additions & 4 deletions reporters/dogstatsd/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ func GruStatusHandler(c dogstatsd.Client, event string,
if err != nil {
return err
}
c.Gauge(fmt.Sprintf("gru.%s", opts["status"]), gauge, tags, 1)
return nil
return c.Gauge(fmt.Sprintf("gru.%s", opts["status"]), gauge, tags, 1)
}

// GruTimingHandler calls dogstatsd.Client.Timing with tags formatted as key:value
Expand Down Expand Up @@ -135,6 +134,5 @@ func GaugeHandler(
if err != nil {
return err
}
c.Gauge(event, gauge, tags, 1)
return nil
return c.Gauge(event, gauge, tags, 1)
}
11 changes: 9 additions & 2 deletions reporters/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,15 @@ func copyOpts(src map[string]interface{}) map[string]interface{} {

// Report is Reporters' implementation of the Reporter interface
func (r *Reporters) Report(event string, opts map[string]interface{}) error {
var aggregatedErrors []error
for _, reporter := range r.reporters {
reporter.Report(event, copyOpts(opts))
if err := reporter.Report(event, copyOpts(opts)); err != nil {
aggregatedErrors = append(aggregatedErrors, err)
}
}

if len(aggregatedErrors) > 0 {
return fmt.Errorf("failed to report '%s' event: %v", event, aggregatedErrors)
}
return nil
}
Expand All @@ -80,7 +87,7 @@ func MakeReporters(config *viper.Viper, logger *logrus.Logger) {
for k := range GetInstance().reporters {
correctlySet = append(correctlySet, k)
}
logger.Info(fmt.Sprintf("Active reporters: %s", strings.Join(correctlySet, ", ")))
logger.Infof("Active reporters: %s", strings.Join(correctlySet, ", "))
}

// NewReporters ctor
Expand Down
13 changes: 11 additions & 2 deletions watcher/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,9 @@ func (w *Watcher) reportRoomsStatusesRoutine() {
case <-podStateCountTicker.C:
w.PodStatesCount()
case <-roomStatusTicker.C:
_ = w.ReportRoomsStatuses()
if err := w.ReportRoomsStatuses(); err != nil {
w.Logger.WithError(err).Error("failed to report room status")
}
}
}
}
Expand Down Expand Up @@ -461,12 +463,19 @@ func (w *Watcher) ReportRoomsStatuses() error {
}

for _, r := range roomDataSlice {
_ = reporters.Report(reportersConstants.EventGruStatus, map[string]interface{}{
err := reporters.Report(reportersConstants.EventGruStatus, map[string]interface{}{
reportersConstants.TagGame: w.GameName,
reportersConstants.TagScheduler: w.SchedulerName,
"status": r.Status,
"gauge": r.Gauge,
})
if err != nil {
w.Logger.Error(err)
} else {
w.Logger.
WithField("gauge", r.Gauge).
Infof("Metric %s has been sent!", r.Status)
}
}

return nil
Expand Down

0 comments on commit 60482f8

Please sign in to comment.