Merge pull request #2131 from weaveworks/issues/2089-vsn-check

2089: Add info about new available versions to the `weave status` report
This commit is contained in:
Bryan Boreham committed 2016-04-13 12:20:57 +01:00
commit 6b08f97910
7 files changed
+79 -17

No files matched your search

+4 -2
View File
@@ -58,8 +58,10 @@ 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
[periodically contacts Weaveworks servers for available versions](https://github.com/weaveworks/go-checkpoint)
and announces new versions in the log. To disable this check, run:
[periodically contacts Weaveworks servers for available versions](https://github.com/weaveworks/go-checkpoint).
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 check, run:
```
export CHECKPOINT_DISABLE=1
+41 -6
View File
@@ -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"
@@ -138,7 +140,7 @@ func defTemplate(name string, text string) *template.Template {
}
var statusTemplate = defTemplate("status", `\
Version: {{.Version}}
Version: {{.Version}} ({{.VersionCheck}})
Service: router
Protocol: {{.Router.Protocol}} \
@@ -221,17 +223,51 @@ var dnsEntriesTemplate = defTemplate("dnsEntries", `\
var ipamTemplate = defTemplate("ipamTemplate", `{{printIPAMRanges .Router .IPAM}}`)
type VersionCheck struct {
Enabled bool
NewVersion string
NextCheckAt time.Time
}
func versionCheck() *VersionCheck {
v := &VersionCheck{}
if checkpoint.IsCheckDisabled() {
return v
}
v.Enabled = true
v.NewVersion = newVersion.Load().(string)
v.NextCheckAt = checker.NextCheckAt()
return v
}
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"))
}
}
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 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)}
@@ -283,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)
}
+11 -5
View File
@@ -8,6 +8,7 @@ import (
"os"
"runtime"
"strings"
"sync/atomic"
"time"
"github.com/davecheney/profile"
@@ -27,6 +28,8 @@ import (
)
var version = "(unreleased version)"
var checker *checkpoint.Checker
var newVersion atomic.Value
var Log = common.Log
@@ -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)
}
@@ -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 {
@@ -183,7 +189,7 @@ func main() {
Log.Println("Command line options:", options())
go checkForUpdates()
checkForUpdates()
if prof != "" {
p := *profile.CPUProfile
+4 -2
View File
@@ -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
@@ -80,7 +80,9 @@ $ weave status
The terms used here are explained further at
[How Weave Net Works](/site/router-topology.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).
+15
View File
@@ -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
+3 -1
View File
@@ -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
@@ -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_weave_on() {