Merge pull request #900 from mattermost/PLT-462
PLT-462 Adding diagnostic info
Этот коммит содержится в:
@@ -75,7 +75,8 @@
|
|||||||
},
|
},
|
||||||
"PrivacySettings": {
|
"PrivacySettings": {
|
||||||
"ShowEmailAddress": true,
|
"ShowEmailAddress": true,
|
||||||
"ShowFullName": true
|
"ShowFullName": true,
|
||||||
|
"EnableDiagnostic": false
|
||||||
},
|
},
|
||||||
"GitLabSettings": {
|
"GitLabSettings": {
|
||||||
"Enable": false,
|
"Enable": false,
|
||||||
|
|||||||
@@ -75,7 +75,8 @@
|
|||||||
},
|
},
|
||||||
"PrivacySettings": {
|
"PrivacySettings": {
|
||||||
"ShowEmailAddress": true,
|
"ShowEmailAddress": true,
|
||||||
"ShowFullName": true
|
"ShowFullName": true,
|
||||||
|
"EnableDiagnostic": false
|
||||||
},
|
},
|
||||||
"GitLabSettings": {
|
"GitLabSettings": {
|
||||||
"Enable": false,
|
"Enable": false,
|
||||||
|
|||||||
@@ -75,7 +75,8 @@
|
|||||||
},
|
},
|
||||||
"PrivacySettings": {
|
"PrivacySettings": {
|
||||||
"ShowEmailAddress": true,
|
"ShowEmailAddress": true,
|
||||||
"ShowFullName": true
|
"ShowFullName": true,
|
||||||
|
"EnableDiagnostic": false
|
||||||
},
|
},
|
||||||
"GitLabSettings": {
|
"GitLabSettings": {
|
||||||
"Enable": false,
|
"Enable": false,
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"runtime"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
@@ -61,6 +63,8 @@ func main() {
|
|||||||
manualtesting.InitManualTesting()
|
manualtesting.InitManualTesting()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
diagnosticsJob()
|
||||||
|
|
||||||
// wait for kill signal before attempting to gracefully shutdown
|
// wait for kill signal before attempting to gracefully shutdown
|
||||||
// the running service
|
// the running service
|
||||||
c := make(chan os.Signal)
|
c := make(chan os.Signal)
|
||||||
@@ -71,6 +75,53 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func diagnosticsJob() {
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
if utils.Cfg.PrivacySettings.EnableDiagnostic && !model.IsOfficalBuild() {
|
||||||
|
if result := <-api.Srv.Store.System().Get(); result.Err == nil {
|
||||||
|
props := result.Data.(model.StringMap)
|
||||||
|
lastTime, _ := strconv.ParseInt(props["LastDiagnosticTime"], 10, 0)
|
||||||
|
currentTime := model.GetMillis()
|
||||||
|
|
||||||
|
if (currentTime - lastTime) > 1000*60*60*24*7 {
|
||||||
|
l4g.Info("Sending error and diagnostic information to mattermost")
|
||||||
|
|
||||||
|
id := props["DiagnosticId"]
|
||||||
|
if len(id) == 0 {
|
||||||
|
id = model.NewId()
|
||||||
|
systemId := &model.System{Name: "DiagnosticId", Value: id}
|
||||||
|
<-api.Srv.Store.System().Save(systemId)
|
||||||
|
}
|
||||||
|
|
||||||
|
systemLastTime := &model.System{Name: "LastDiagnosticTime", Value: strconv.FormatInt(currentTime, 10)}
|
||||||
|
if lastTime == 0 {
|
||||||
|
<-api.Srv.Store.System().Save(systemLastTime)
|
||||||
|
} else {
|
||||||
|
<-api.Srv.Store.System().Update(systemLastTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
m := make(map[string]string)
|
||||||
|
m[utils.PROP_DIAGNOSTIC_ID] = id
|
||||||
|
m[utils.PROP_DIAGNOSTIC_BUILD] = model.CurrentVersion + "." + model.BuildNumber
|
||||||
|
m[utils.PROP_DIAGNOSTIC_DATABASE] = utils.Cfg.SqlSettings.DriverName
|
||||||
|
m[utils.PROP_DIAGNOSTIC_OS] = runtime.GOOS
|
||||||
|
m[utils.PROP_DIAGNOSTIC_CATEGORY] = utils.VAL_DIAGNOSTIC_CATEGORY_DEFALUT
|
||||||
|
|
||||||
|
if ucr := <-api.Srv.Store.User().GetTotalUsersCount(); ucr.Err == nil {
|
||||||
|
m[utils.PROP_DIAGNOSTIC_USER_COUNT] = strconv.FormatInt(ucr.Data.(int64), 10)
|
||||||
|
}
|
||||||
|
|
||||||
|
utils.SendDiagnostic(m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(time.Hour * 24)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
func parseCmds() {
|
func parseCmds() {
|
||||||
flag.Usage = func() {
|
flag.Usage = func() {
|
||||||
fmt.Fprintln(os.Stderr, usage)
|
fmt.Fprintln(os.Stderr, usage)
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ type RateLimitSettings struct {
|
|||||||
type PrivacySettings struct {
|
type PrivacySettings struct {
|
||||||
ShowEmailAddress bool
|
ShowEmailAddress bool
|
||||||
ShowFullName bool
|
ShowFullName bool
|
||||||
|
EnableDiagnostic bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type TeamSettings struct {
|
type TeamSettings struct {
|
||||||
|
|||||||
@@ -67,6 +67,10 @@ func GetPreviousVersion(currentVersion string) (int64, int64) {
|
|||||||
return 0, 0
|
return 0, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsOfficalBuild() bool {
|
||||||
|
return BuildNumber != "_BUILD_NUMBER_"
|
||||||
|
}
|
||||||
|
|
||||||
func IsCurrentVersion(versionToCheck string) bool {
|
func IsCurrentVersion(versionToCheck string) bool {
|
||||||
currentMajor, currentMinor, _ := SplitVersion(CurrentVersion)
|
currentMajor, currentMinor, _ := SplitVersion(CurrentVersion)
|
||||||
toCheckMajor, toCheckMinor, _ := SplitVersion(versionToCheck)
|
toCheckMajor, toCheckMinor, _ := SplitVersion(versionToCheck)
|
||||||
|
|||||||
45
utils/diagnostic.go
Обычный файл
45
utils/diagnostic.go
Обычный файл
@@ -0,0 +1,45 @@
|
|||||||
|
// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
|
||||||
|
// See License.txt for license information.
|
||||||
|
|
||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
l4g "code.google.com/p/log4go"
|
||||||
|
|
||||||
|
"github.com/mattermost/platform/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
PROP_DIAGNOSTIC_ID = "id"
|
||||||
|
PROP_DIAGNOSTIC_CATEGORY = "c"
|
||||||
|
VAL_DIAGNOSTIC_CATEGORY_DEFALUT = "d"
|
||||||
|
PROP_DIAGNOSTIC_BUILD = "b"
|
||||||
|
PROP_DIAGNOSTIC_DATABASE = "db"
|
||||||
|
PROP_DIAGNOSTIC_OS = "os"
|
||||||
|
PROP_DIAGNOSTIC_USER_COUNT = "uc"
|
||||||
|
)
|
||||||
|
|
||||||
|
func SendDiagnostic(data model.StringMap) *model.AppError {
|
||||||
|
if Cfg.PrivacySettings.EnableDiagnostic && !model.IsOfficalBuild() {
|
||||||
|
|
||||||
|
query := "?"
|
||||||
|
for name, value := range data {
|
||||||
|
if len(query) > 1 {
|
||||||
|
query += "&"
|
||||||
|
}
|
||||||
|
|
||||||
|
query += name + "=" + UrlEncode(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := http.Get("http://d7zmvsa9e04kk.cloudfront.net/i" + query)
|
||||||
|
if err != nil {
|
||||||
|
l4g.Error("Failed to send diagnostics %v", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
res.Body.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -30,6 +30,7 @@ export default class PrivacySettings extends React.Component {
|
|||||||
var config = this.props.config;
|
var config = this.props.config;
|
||||||
config.PrivacySettings.ShowEmailAddress = React.findDOMNode(this.refs.ShowEmailAddress).checked;
|
config.PrivacySettings.ShowEmailAddress = React.findDOMNode(this.refs.ShowEmailAddress).checked;
|
||||||
config.PrivacySettings.ShowFullName = React.findDOMNode(this.refs.ShowFullName).checked;
|
config.PrivacySettings.ShowFullName = React.findDOMNode(this.refs.ShowFullName).checked;
|
||||||
|
config.PrivacySettings.EnableDiagnostic = React.findDOMNode(this.refs.EnableDiagnostic).checked;
|
||||||
|
|
||||||
Client.saveConfig(
|
Client.saveConfig(
|
||||||
config,
|
config,
|
||||||
@@ -136,6 +137,39 @@ export default class PrivacySettings extends React.Component {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className='form-group'>
|
||||||
|
<label
|
||||||
|
className='control-label col-sm-4'
|
||||||
|
htmlFor='EnableDiagnostic'
|
||||||
|
>
|
||||||
|
{'Send Error and Diagnostic: '}
|
||||||
|
</label>
|
||||||
|
<div className='col-sm-8'>
|
||||||
|
<label className='radio-inline'>
|
||||||
|
<input
|
||||||
|
type='radio'
|
||||||
|
name='EnableDiagnostic'
|
||||||
|
value='true'
|
||||||
|
ref='EnableDiagnostic'
|
||||||
|
defaultChecked={this.props.config.PrivacySettings.EnableDiagnostic}
|
||||||
|
onChange={this.handleChange}
|
||||||
|
/>
|
||||||
|
{'true'}
|
||||||
|
</label>
|
||||||
|
<label className='radio-inline'>
|
||||||
|
<input
|
||||||
|
type='radio'
|
||||||
|
name='EnableDiagnostic'
|
||||||
|
value='false'
|
||||||
|
defaultChecked={!this.props.config.PrivacySettings.EnableDiagnostic}
|
||||||
|
onChange={this.handleChange}
|
||||||
|
/>
|
||||||
|
{'false'}
|
||||||
|
</label>
|
||||||
|
<p className='help-text'>{'When true, The server will periodically send error and diagnostic information to Mattermost.'}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className='form-group'>
|
<div className='form-group'>
|
||||||
<div className='col-sm-12'>
|
<div className='col-sm-12'>
|
||||||
{serverError}
|
{serverError}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user