Skip to content

Commit

Permalink
Extend version summary in the weave status report
Browse files Browse the repository at this point in the history
The extended version summary includes info about a new available
version in the case the checkpoint is enabled.
  • Loading branch information
brb committed Apr 12, 2016
1 parent b7d49cd commit f5c5788
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 16 deletions.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -58,7 +58,9 @@ Weave Net respects the environment variable `DOCKER_HOST`, so you can run
it locally to control a weave network on a remote host.

Weave Net will periodically check with our servers to see if a new version is available.
New versions are announced in the log. To disable this, run:
New versions are announced in the log and in
[the status summary](http://docs.weave.works/weave/latest_release/troubleshooting.html#weave-status).
To disable this, run:

```
CHECKPOINT_DISABLE=true weave launch
Expand Down
51 changes: 45 additions & 6 deletions prog/weaver/http.go
Expand Up @@ -7,10 +7,12 @@ import (
"net/http"
"strings"
"text/template"
"time"

"github.com/gorilla/mux"
"github.com/weaveworks/mesh"

"github.com/weaveworks/go-checkpoint"
"github.com/weaveworks/weave/ipam"
"github.com/weaveworks/weave/nameserver"
"github.com/weaveworks/weave/net/address"
Expand Down Expand Up @@ -116,6 +118,19 @@ var rootTemplate = template.New("root").Funcs(map[string]interface{}{
"trimSuffix": strings.TrimSuffix,
})

func (v *VersionCheck) String() string {
switch {
case !v.Enabled:
return "version check update disabled"
case v.NewVersion != "":
return fmt.Sprintf("version %s available - please upgrade!",
v.NewVersion)
default:
return fmt.Sprintf("up to date; next check at %s",
v.NextCheckAt.Format("2006/01/02 15:04:05"))
}
}

// Print counts in a specified order
func printCounts(counts map[string]int, keys []string) string {
var stringCounts []string
Expand All @@ -138,7 +153,7 @@ func defTemplate(name string, text string) *template.Template {
}

var statusTemplate = defTemplate("status", `\
Version: {{.Version}}
Version: {{.Version}} ({{.VersionCheck}})
Service: router
Protocol: {{.Router.Protocol}} \
Expand Down Expand Up @@ -217,17 +232,42 @@ var dnsEntriesTemplate = defTemplate("dnsEntries", `\

var ipamTemplate = defTemplate("ipamTemplate", `{{printIPAMRanges .Router .IPAM}}`)

type VersionCheck struct {
Enabled bool
NewVersion string
NextCheckAt time.Time
}

type WeaveStatus struct {
Version string
Router *weave.NetworkRouterStatus `json:"Router,omitempty"`
IPAM *ipam.Status `json:"IPAM,omitempty"`
DNS *nameserver.Status `json:"DNS,omitempty"`
Version string
VersionCheck *VersionCheck `json:"VersionCheck,omitempty"`
Router *weave.NetworkRouterStatus `json:"Router,omitempty"`
IPAM *ipam.Status `json:"IPAM,omitempty"`
DNS *nameserver.Status `json:"DNS,omitempty"`
}

func versionCheck() *VersionCheck {
v := &VersionCheck{
Enabled: true,
NewVersion: "",
}

if checkpoint.IsCheckDisabled() {
v.Enabled = false
return v
}

v.NewVersion = newVersion.Load().(string)
v.NextCheckAt = checker.NextCheckAt()

return v
}

func HandleHTTP(muxRouter *mux.Router, version string, router *weave.NetworkRouter, allocator *ipam.Allocator, defaultSubnet address.CIDR, ns *nameserver.Nameserver, dnsserver *nameserver.DNSServer) {
status := func() WeaveStatus {
return WeaveStatus{
version,
versionCheck(),
weave.NewNetworkRouterStatus(router),
ipam.NewStatus(allocator, defaultSubnet),
nameserver.NewStatus(ns, dnsserver)}
Expand Down Expand Up @@ -279,5 +319,4 @@ func HandleHTTP(muxRouter *mux.Router, version string, router *weave.NetworkRout
defHandler("/status/peers", peersTemplate)
defHandler("/status/dns", dnsEntriesTemplate)
defHandler("/status/ipam", ipamTemplate)

}
16 changes: 11 additions & 5 deletions prog/weaver/main.go
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"runtime"
"strings"
"sync/atomic"
"time"

"github.com/davecheney/profile"
Expand All @@ -27,6 +28,8 @@ import (
)

var version = "(unreleased version)"
var checker *checkpoint.Checker
var newVersion atomic.Value

var Log = common.Log

Expand All @@ -51,10 +54,15 @@ const (
)

func checkForUpdates() {
newVersion.Store("")

handleResponse := func(r *checkpoint.CheckResponse, err error) {
if err != nil {
Log.Printf("Error checking version: %v", err)
} else if r.Outdated {
return
}
if r.Outdated {
newVersion.Store(r.CurrentVersion)
Log.Printf("Weave version %s is available; please update at %s",
r.CurrentVersion, r.CurrentDownloadURL)
}
Expand All @@ -66,9 +74,7 @@ func checkForUpdates() {
Version: version,
SignatureFile: "",
}
resp, err := checkpoint.Check(&params)
handleResponse(resp, err)
checkpoint.CheckInterval(&params, updateCheckPeriod, handleResponse)
checker = checkpoint.CheckInterval(&params, updateCheckPeriod, handleResponse)
}

func (c ipamConfig) Enabled() bool {
Expand Down Expand Up @@ -183,7 +189,7 @@ func main() {

Log.Println("Command line options:", options())

go checkForUpdates()
checkForUpdates()

if prof != "" {
p := *profile.CPUProfile
Expand Down
6 changes: 4 additions & 2 deletions site/troubleshooting.md
Expand Up @@ -48,7 +48,7 @@ A status summary can be obtained using `weave status`:
````
$ weave status
Version: 1.1.0
Version: 1.1.0 (up to date; next check at 2016/04/06 12:30:00)
Service: router
Protocol: weave 1..2
Expand Down Expand Up @@ -80,7 +80,9 @@ $ weave status
The terms used here are explained further at
[How Weave Net Works](/site/router-topology/overview.md).

* **Version** - shows the Weave Net version.
* **Version** - shows the Weave Net version. If checkpoint is enabled (i.e.
`CHECKPOINT_DISABLE` is not set), information about existence of a new version
will be shown.

* **Protocol**- indicates the Weave Router inter-peer
communication protocol name and supported versions (min..max).
Expand Down
15 changes: 15 additions & 0 deletions test/700_status_and_report_test.sh
Expand Up @@ -26,4 +26,19 @@ weave_on $HOST1 connect 10.2.2.1
assert "weave_on $HOST1 status targets" "10.2.2.1"
assert "weave_on $HOST1 status connections | tr -s ' ' | cut -d ' ' -f 2" "10.2.2.1:6783"

assert "weave_on $HOST1 report -f '{{.VersionCheck.Enabled}}'" "false"
assert_raises "weave_on $HOST1 status | grep 'version check update disabled'"

weave_on $HOST1 reset

CHECKPOINT_DISABLE="" weave_on $HOST1 launch
assert "weave_on $HOST1 report -f '{{.VersionCheck.Enabled}}'" "true"

NEW_VSN=$(weave_on $HOST1 report -f "{{.VersionCheck.NewVersion}}")
if [ -z "$NEW_VSN" ]; then
assert_raises "weave_on $HOST1 status | grep 'up to date; next check at '"
else
assert_raises "weave_on $HOST1 status | grep \"version $NEW_VSN available - please upgrade!\""
fi

end_suite
4 changes: 3 additions & 1 deletion test/config.sh
Expand Up @@ -44,6 +44,8 @@ CHECK_ETHWE_MISSING="test ! -d /sys/class/net/ethwe"

DOCKER_PORT=2375

CHECKPOINT_DISABLE=true

upload_executable() {
host=$1
file=$2
Expand Down Expand Up @@ -118,7 +120,7 @@ weave_on() {
host=$1
shift 1
[ -z "$DEBUG" ] || greyly echo "Weave on $host:$DOCKER_PORT: $@" >&2
CHECKPOINT_DISABLE=true DOCKER_HOST=tcp://$host:$DOCKER_PORT $WEAVE "$@"
CHECKPOINT_DISABLE="$CHECKPOINT_DISABLE" DOCKER_HOST=tcp://$host:$DOCKER_PORT $WEAVE "$@"
}

stop_router_on() {
Expand Down
2 changes: 1 addition & 1 deletion vendor/github.com/weaveworks/go-checkpoint
Submodule go-checkpoint updated 3 files
+20 −15 README.md
+48 −11 checkpoint.go
+79 −45 checkpoint_test.go

0 comments on commit f5c5788

Please sign in to comment.