Skip to content

Commit

Permalink
overlay: synchronize Weave status
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbourgon committed Sep 11, 2015
1 parent 86f73c4 commit 835d387
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions probe/overlay/weave.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/url"
"regexp"
"strings"
"sync"

"github.com/weaveworks/scope/common/exec"
"github.com/weaveworks/scope/probe/docker"
Expand Down Expand Up @@ -43,6 +44,8 @@ var ipMatch = regexp.MustCompile(`([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3
type Weave struct {
url string
hostID string

mtx sync.RWMutex
status weaveStatus
}

Expand Down Expand Up @@ -78,7 +81,6 @@ func NewWeave(hostID, weaveRouterAddress string) (*Weave, error) {

// Tick implements Ticker
func (w *Weave) Tick() error {
var result weaveStatus
req, err := http.NewRequest("GET", w.url, nil)
if err != nil {
return err
Expand All @@ -94,10 +96,13 @@ func (w *Weave) Tick() error {
return fmt.Errorf("Weave Tagger: got %d", resp.StatusCode)
}

var result weaveStatus
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
return err
}

w.mtx.Lock()
defer w.mtx.Unlock()
w.status = result
return nil
}
Expand Down Expand Up @@ -140,7 +145,10 @@ func (w Weave) ps() ([]psEntry, error) {
}

// Tag implements Tagger.
func (w Weave) Tag(r report.Report) (report.Report, error) {
func (w *Weave) Tag(r report.Report) (report.Report, error) {
w.mtx.RLock()
defer w.mtx.RUnlock()

// Put information from weaveDNS on the container nodes
for _, entry := range w.status.DNS.Entries {
if entry.Tombstone > 0 {
Expand Down Expand Up @@ -181,7 +189,10 @@ func (w Weave) Tag(r report.Report) (report.Report, error) {
}

// Report implements Reporter.
func (w Weave) Report() (report.Report, error) {
func (w *Weave) Report() (report.Report, error) {
w.mtx.RLock()
defer w.mtx.RUnlock()

r := report.MakeReport()
for _, peer := range w.status.Router.Peers {
r.Overlay.Nodes[report.MakeOverlayNodeID(peer.Name)] = report.MakeNodeWith(map[string]string{
Expand Down

0 comments on commit 835d387

Please sign in to comment.