Skip to content
This repository has been archived by the owner on Jan 7, 2020. It is now read-only.

Commit

Permalink
Merge pull request #784 from sensu/concurrent-buildClients
Browse files Browse the repository at this point in the history
Add concurrency to buildClients()
  • Loading branch information
amdprophet authored Jun 5, 2018
2 parents 815ad56 + ee52a00 commit 645a3dc
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions uchiwa/daemon/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package daemon

import (
"fmt"
"sync"

"github.com/mitchellh/mapstructure"
"github.com/sensu/uchiwa/uchiwa/helpers"
Expand All @@ -11,28 +12,38 @@ import (

// buildClients constructs clients objects for frontend consumption
func (d *Daemon) buildClients() {
wg := &sync.WaitGroup{}

for _, c := range d.Data.Clients {
client, ok := c.(map[string]interface{})
if !ok {
continue
}
wg.Add(1)

dc, ok := client["dc"].(string)
if !ok {
continue
}
go d.buildClient(c, wg)
}

name, ok := client["name"].(string)
if !ok {
continue
}
wg.Wait()
}

client["_id"] = fmt.Sprintf("%s/%s", dc, name)
func (d *Daemon) buildClient(c interface{}, wg *sync.WaitGroup) {
defer wg.Done()

client = findClientEvents(client, &d.Data.Events)
client, ok := c.(map[string]interface{})
if !ok {
return
}

client["silenced"] = helpers.IsClientSilenced(name, dc, d.Data.Silenced)
dc, ok := client["dc"].(string)
if !ok {
return
}

name, ok := client["name"].(string)
if !ok {
return
}

client["_id"] = fmt.Sprintf("%s/%s", dc, name)
client = findClientEvents(client, &d.Data.Events)
client["silenced"] = helpers.IsClientSilenced(name, dc, d.Data.Silenced)
}

// findClientEvents searches for all events related to a particular client
Expand Down

0 comments on commit 645a3dc

Please sign in to comment.