Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
new weave status, weave status ..., and weave report
Browse files Browse the repository at this point in the history
  • Loading branch information
awh authored and rade committed Aug 11, 2015
1 parent 00ecff0 commit fc9a1c8
Show file tree
Hide file tree
Showing 27 changed files with 789 additions and 498 deletions.
5 changes: 0 additions & 5 deletions common/signals.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
// A subsystem/server/... that can be stopped or queried about the status with a signal
type SignalReceiver interface {
Stop() error
Status() string
}

func SignalHandlerLoop(ss ...SignalReceiver) {
Expand All @@ -28,10 +27,6 @@ func SignalHandlerLoop(ss ...SignalReceiver) {
case syscall.SIGQUIT:
stacklen := runtime.Stack(buf, true)
Log.Infof("=== received SIGQUIT ===\n*** goroutine dump...\n%s\n*** end", buf[:stacklen])
case syscall.SIGUSR1:
for _, subsystem := range ss {
Log.Infof("=== received SIGUSR1 ===\n*** status...\n%s\n*** end", subsystem.Status())
}
}
}
}
12 changes: 12 additions & 0 deletions common/utils.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
package common

import (
"strings"
)

// Assert test is true, panic otherwise
func Assert(test bool) {
if !test {
panic("Assertion failure")
}
}

func ErrorMessages(errors []error) string {
var result []string
for _, err := range errors {
result = append(result, err.Error())
}
return strings.Join(result, "\n")
}
4 changes: 0 additions & 4 deletions ipam/allocate.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ func (g *allocate) Cancel() {
g.resultChan <- allocateResult{0, fmt.Errorf("Allocate request for %s cancelled", g.ident)}
}

func (g *allocate) String() string {
return fmt.Sprintf("Allocate for %s", g.ident)
}

func (g *allocate) ForContainer(ident string) bool {
return g.ident == ident
}
35 changes: 0 additions & 35 deletions ipam/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ type operation interface {

Cancel()

String() string

// Does this operation pertain to the given container id?
// Used for tidying up pending operations when containers die.
ForContainer(ident string) bool
Expand Down Expand Up @@ -275,15 +273,6 @@ func (alloc *Allocator) Free(ident string, addrToFree address.Address) error {
return <-errChan
}

// Sync.
func (alloc *Allocator) String() string {
resultChan := make(chan string)
alloc.actionChan <- func() {
resultChan <- alloc.string()
}
return <-resultChan
}

// Shutdown (Sync)
func (alloc *Allocator) Shutdown() {
alloc.infof("Shutdown")
Expand Down Expand Up @@ -493,30 +482,6 @@ func (alloc *Allocator) actorLoop(actionChan <-chan func()) {

// Helper functions

func (alloc *Allocator) string() string {
var buf bytes.Buffer
fmt.Fprintf(&buf, "Allocator range %s", alloc.universe)

if alloc.ring.Empty() {
if alloc.paxosTicker != nil {
fmt.Fprintf(&buf, " awaiting consensus: %s", alloc.paxos.String())
}
} else {
fmt.Fprint(&buf, "\nOwned Ranges:")
alloc.ring.FprintWithNicknames(&buf, alloc.nicknames)
}
if len(alloc.pendingAllocates)+len(alloc.pendingClaims) > 0 {
fmt.Fprintf(&buf, "\nPending requests:")
for _, op := range alloc.pendingAllocates {
fmt.Fprintf(&buf, "\n %s", op.String())
}
for _, op := range alloc.pendingClaims {
fmt.Fprintf(&buf, "\n %s", op.String())
}
}
return buf.String()
}

// Ensure we are making progress towards an established ring
func (alloc *Allocator) establishRing() {
if !alloc.ring.Empty() || alloc.paxosTicker != nil {
Expand Down
4 changes: 0 additions & 4 deletions ipam/claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ func (c *claim) Cancel() {
c.sendResult(fmt.Errorf("Operation cancelled."))
}

func (c *claim) String() string {
return fmt.Sprintf("Claim %s -> %s", c.ident, c.addr.String())
}

func (c *claim) ForContainer(ident string) bool {
return c.ident == ident
}
15 changes: 9 additions & 6 deletions ipam/paxos/paxos.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package paxos

import (
"fmt"

"github.com/weaveworks/weave/router"
)

Expand Down Expand Up @@ -252,9 +250,14 @@ func (node *Node) Consensus() (bool, AcceptedValue) {
return false, AcceptedValue{}
}

func (node *Node) String() string {
if ok, val := node.Consensus(); ok {
return fmt.Sprintf("Consensus reached with size %d", len(val.Value))
type Status struct {
KnownNodes int
Quorum uint
}

func NewStatus(node *Node) *Status {
if node == nil {
return nil
}
return fmt.Sprintf("Nodes known: %d, Quorum size: %d", len(node.knows), node.quorum)
return &Status{len(node.knows), node.quorum}
}
82 changes: 82 additions & 0 deletions ipam/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package ipam

import (
"github.com/weaveworks/weave/ipam/paxos"
"github.com/weaveworks/weave/net/address"
)

type Status struct {
Paxos *paxos.Status
Range string
DefaultSubnet string
Entries []EntryStatus
PendingClaims []ClaimStatus
PendingAllocates []string
}

type EntryStatus struct {
Token string
Peer string
Version uint32
}

type ClaimStatus struct {
Ident string
Address address.Address
}

func NewStatus(allocator *Allocator, defaultSubnet address.CIDR) *Status {
if allocator == nil {
return nil
}

var paxosStatus *paxos.Status
if allocator.paxosTicker != nil {
paxosStatus = paxos.NewStatus(allocator.paxos)
}

resultChan := make(chan *Status)
allocator.actionChan <- func() {
resultChan <- &Status{
paxosStatus,
allocator.universe.String(),
defaultSubnet.String(),
newEntryStatusSlice(allocator),
newClaimStatusSlice(allocator),
newAllocateIdentSlice(allocator)}
}

return <-resultChan
}

func newEntryStatusSlice(allocator *Allocator) []EntryStatus {
var slice []EntryStatus

if allocator.ring.Empty() {
return slice
}

for _, entry := range allocator.ring.Entries {
slice = append(slice, EntryStatus{entry.Token.String(), entry.Peer.String(), entry.Version})
}

return slice
}

func newClaimStatusSlice(allocator *Allocator) []ClaimStatus {
var slice []ClaimStatus
for _, op := range allocator.pendingClaims {
claim := op.(*claim)
slice = append(slice, ClaimStatus{claim.ident, claim.addr})
}
return slice
}

func newAllocateIdentSlice(allocator *Allocator) []string {
var slice []string
for _, op := range allocator.pendingAllocates {
allocate := op.(*allocate)
slice = append(slice, allocate.ident)
}
return slice
}
17 changes: 0 additions & 17 deletions nameserver/nameserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,23 +185,6 @@ func (n *Nameserver) deleteTombstones() {
})
}

func (n *Nameserver) String() string {
n.RLock()
defer n.RUnlock()
var buf bytes.Buffer
for _, entry := range n.entries {
if entry.Tombstone > 0 {
continue
}
containerid := entry.ContainerID
if len(containerid) > 12 {
containerid = containerid[:12]
}
fmt.Fprintf(&buf, "%s: %s [%s]\n", containerid, entry.Hostname, entry.Addr.String())
}
return buf.String()
}

func (n *Nameserver) Gossip() router.GossipData {
n.RLock()
defer n.RUnlock()
Expand Down
43 changes: 43 additions & 0 deletions nameserver/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package nameserver

type Status struct {
Domain string
Address string
TTL uint32
Entries []EntryStatus
}

type EntryStatus struct {
Hostname string
Origin string
ContainerID string
Address string
Version int
Tombstone int64
}

func NewStatus(ns *Nameserver, dnsServer *DNSServer) *Status {
if dnsServer == nil {
return nil
}

ns.RLock()
defer ns.RUnlock()

var entryStatusSlice []EntryStatus
for _, entry := range ns.entries {
entryStatusSlice = append(entryStatusSlice, EntryStatus{
entry.Hostname,
entry.Origin.String(),
entry.ContainerID,
entry.Addr.String(),
entry.Version,
entry.Tombstone})
}

return &Status{
dnsServer.domain,
dnsServer.address,
dnsServer.ttl,
entryStatusSlice}
}
Loading

0 comments on commit fc9a1c8

Please sign in to comment.