[MM-16620] Properly handle analytics client life cycle
Properly handle analytics client life cycle This change improves the life cycle management of the analytics client. It does so in two primary ways: - Move the client from being a shared pointer to belonging to the Server struct. - Expose the client.Close() method for proper shutdown of the client.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
df869e3f86
Коммит
f56a8f5a99
@@ -58,15 +58,13 @@ const (
|
||||
TRACK_PLUGINS = "plugins"
|
||||
)
|
||||
|
||||
var client *analytics.Client
|
||||
|
||||
func (a *App) SendDailyDiagnostics() {
|
||||
a.sendDailyDiagnostics(false)
|
||||
}
|
||||
|
||||
func (a *App) sendDailyDiagnostics(override bool) {
|
||||
if *a.Config().LogSettings.EnableDiagnostics && a.IsLeader() && (!strings.Contains(SEGMENT_KEY, "placeholder") || override) {
|
||||
a.initDiagnostics("")
|
||||
a.Srv.initDiagnostics("")
|
||||
a.trackActivity()
|
||||
a.trackConfig()
|
||||
a.trackLicense()
|
||||
@@ -76,24 +74,8 @@ func (a *App) sendDailyDiagnostics(override bool) {
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) initDiagnostics(endpoint string) {
|
||||
if client == nil {
|
||||
client = analytics.New(SEGMENT_KEY)
|
||||
client.Logger = a.Log.StdLog(mlog.String("source", "segment"))
|
||||
// For testing
|
||||
if endpoint != "" {
|
||||
client.Endpoint = endpoint
|
||||
client.Verbose = true
|
||||
client.Size = 1
|
||||
}
|
||||
client.Identify(&analytics.Identify{
|
||||
UserId: a.DiagnosticId(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) SendDiagnostic(event string, properties map[string]interface{}) {
|
||||
client.Track(&analytics.Track{
|
||||
a.Srv.diagnosticClient.Track(&analytics.Track{
|
||||
Event: event,
|
||||
UserId: a.DiagnosticId(),
|
||||
Properties: properties,
|
||||
|
||||
Ссылка в новой задаче
Block a user