Added a last checked version I'D. Fixed error messages.

This commit is contained in:
Michael Baird 2017-10-27 16:58:00 -05:00
parent c14f72b66a
commit 030b0721c8
3 changed files with 27 additions and 14 deletions

View file

@ -30,14 +30,15 @@ type versionResponse struct {
// Diagnostics represents a client to the Pilosa cluster.
type Diagnostics struct {
mu sync.Mutex
wg sync.WaitGroup
closing chan struct{}
host string
VersionURL string
version string
startTime int64
start time.Time
mu sync.Mutex
wg sync.WaitGroup
closing chan struct{}
host string
VersionURL string
version string
lastVersion string
startTime int64
start time.Time
metrics map[string]interface{}
@ -124,6 +125,8 @@ func (d *Diagnostics) Open() {
st.Timeout = d.interval * 2
}
d.cb = gobreaker.NewCircuitBreaker(st)
d.logger().Printf("Pilosa is currently configured to send small diagnostics reports to our team every hour. More information here: https://www.pilosa.com/docs/latest/administration/")
}
// Close notify goroutine to stop.
@ -149,6 +152,12 @@ func (d *Diagnostics) CheckVersion() error {
return fmt.Errorf("json decode: %s", err)
}
// Same a version as last test
if rsp.Version == d.lastVersion {
return nil
}
d.lastVersion = rsp.Version
if err := d.CompareVersion(rsp.Version); err != nil {
d.logger().Printf("%s\n", err.Error())
}
@ -162,9 +171,9 @@ func (d *Diagnostics) CompareVersion(value string) error {
localVersion := VersionSegments(d.version)
if localVersion[0] < currentVersion[0] { //Major
return fmt.Errorf("Warning: You are running an older version of Pilosa %s. The latest Major release is %s", d.version, value)
return fmt.Errorf("Warning: You are running Pilosa %s, but a newer version is available %s", d.version, value)
} else if localVersion[1] < currentVersion[1] { // Minor
return fmt.Errorf("Warning: You are running an older version of Pilosa %s. The latest Minor release is %s", d.version, value)
return fmt.Errorf("Warning: You are running Pilosa %s. The latest Minor release is %s", d.version, value)
} else if localVersion[2] < currentVersion[2] { // Patch
return fmt.Errorf("There is a new patch relese of Pilosa availbale: %s", value)
}

View file

@ -73,12 +73,16 @@ func TestDiagnosticsVersion_Compare(t *testing.T) {
d.Open()
defer d.Close()
version := "0.1.1"
version := "v0.1.1"
d.SetVersion(version)
err := d.CompareVersion("1.7.0")
if !strings.Contains(err.Error(), "The latest Major release is") {
t.Fatalf("Expected Major Version Missmatch, actual error: %s", err)
if !strings.Contains(err.Error(), "a newer version is available ") {
t.Fatalf("Expected a newer version is available, actual error: %s", err)
}
err = d.CompareVersion("1.7.0")
if !strings.Contains(err.Error(), "a newer version is available ") {
t.Fatalf("Expected a newer version is available, actual error: %s", err)
}
err = d.CompareVersion("0.7.0")
if !strings.Contains(err.Error(), "The latest Minor release is") {

View file

@ -131,7 +131,7 @@ Each Pilosa cluster is configured by default to share anonymous usage details wi
<strong id="open_files">OpenFiles:</strong> Open file handle count.
<strong id="go_routines">GoRoutines:</strong> Go routine count.
You can opt-out of the Pilosa diagnostics reporting by setting either the `metric.diagnostics` configuration option to false, using the `PILOSA_METRIC_DIAGNOSTICS` environment variable, or the TOML configuration file `[metric]` `diagnostics` option.
You can opt-out of the Pilosa diagnostics reporting by setting either the command line configuration option `--metric.diagnostics=false`, use the `PILOSA_METRIC_DIAGNOSTICS` environment variable, or the TOML configuration file `[metric]` `diagnostics` option.
#### Metrics