[MM-57071] Use bool for license_is_trial in Support Packet (#26378)

This commit is contained in:
Ben Schumacher 2024-03-21 08:55:32 +01:00 committed by GitHub
parent b20f14111c
commit 1383d51436
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 60 additions and 35 deletions

View File

@ -9,7 +9,6 @@ import (
"os"
"runtime"
"runtime/pprof"
"strconv"
"strings"
"time"
@ -74,7 +73,10 @@ func (a *App) generateSupportPacketYaml(c request.CTX) (*model.FileData, error)
/* DB */
databaseType, databaseSchemaVersion := a.Srv().DatabaseTypeAndSchemaVersion()
databaseVersion, _ := a.Srv().Store().GetDbVersion(false)
databaseVersion, err := a.Srv().Store().GetDbVersion(false)
if err != nil {
rErr = multierror.Append(errors.Wrap(err, "error while getting DB version"))
}
/* Cluster */
@ -87,7 +89,7 @@ func (a *App) generateSupportPacketYaml(c request.CTX) (*model.FileData, error)
fileDriver := a.Srv().Platform().FileBackend().DriverName()
fileStatus := model.StatusOk
err := a.Srv().Platform().FileBackend().TestConnection()
err = a.Srv().Platform().FileBackend().TestConnection()
if err != nil {
fileStatus = model.StatusFail + ": " + err.Error()
}
@ -110,22 +112,55 @@ func (a *App) generateSupportPacketYaml(c request.CTX) (*model.FileData, error)
/* License */
licenseTo := ""
supportedUsers := 0
var isTrial bool
var (
licenseTo string
supportedUsers int
isTrial bool
)
if license := a.Srv().License(); license != nil {
supportedUsers = *license.Features.Users
licenseTo = license.Customer.Company
supportedUsers = *license.Features.Users
isTrial = license.IsTrial
}
/* Jobs */
/* Server stats */
uniqueUserCount, err := a.Srv().Store().User().Count(model.UserCountOptions{})
if err != nil {
rErr = multierror.Append(errors.Wrap(err, "error while getting user count"))
}
var (
totalChannels int
totalPosts int
totalTeams int
websocketConnections int
masterDbConnections int
replicaDbConnections int
dailyActiveUsers int
monthlyActiveUsers int
inactiveUserCount int
)
analytics, appErr := a.GetAnalytics(c, "standard", "")
if appErr != nil {
rErr = multierror.Append(errors.Wrap(appErr, "error while getting analytics"))
}
if len(analytics) < 11 {
rErr = multierror.Append(errors.New("not enought analytics information found"))
} else {
totalChannels = int(analytics[0].Value) + int(analytics[1].Value)
totalPosts = int(analytics[2].Value)
totalTeams = int(analytics[4].Value)
websocketConnections = int(analytics[5].Value)
masterDbConnections = int(analytics[6].Value)
replicaDbConnections = int(analytics[7].Value)
dailyActiveUsers = int(analytics[8].Value)
monthlyActiveUsers = int(analytics[9].Value)
inactiveUserCount = int(analytics[10].Value)
}
/* Jobs */
dataRetentionJobs, err := a.Srv().Store().Job().GetAllByTypePage(c, model.JobTypeDataRetention, 0, 2)
if err != nil {
rErr = multierror.Append(errors.Wrap(err, "error while getting data retention jobs"))
@ -138,11 +173,11 @@ func (a *App) generateSupportPacketYaml(c request.CTX) (*model.FileData, error)
if err != nil {
rErr = multierror.Append(errors.Wrap(err, "error while getting ES post indexing jobs"))
}
elasticPostAggregationJobs, _ := a.Srv().Store().Job().GetAllByTypePage(c, model.JobTypeElasticsearchPostAggregation, 0, 2)
elasticPostAggregationJobs, err := a.Srv().Store().Job().GetAllByTypePage(c, model.JobTypeElasticsearchPostAggregation, 0, 2)
if err != nil {
rErr = multierror.Append(errors.Wrap(err, "error while getting ES post aggregation jobs"))
}
blevePostIndexingJobs, _ := a.Srv().Store().Job().GetAllByTypePage(c, model.JobTypeBlevePostIndexing, 0, 2)
blevePostIndexingJobs, err := a.Srv().Store().Job().GetAllByTypePage(c, model.JobTypeBlevePostIndexing, 0, 2)
if err != nil {
rErr = multierror.Append(errors.Wrap(err, "error while getting bleve post indexing jobs"))
}
@ -167,6 +202,9 @@ func (a *App) generateSupportPacketYaml(c request.CTX) (*model.FileData, error)
DatabaseType: databaseType,
DatabaseVersion: databaseVersion,
DatabaseSchemaVersion: databaseSchemaVersion,
WebsocketConnections: websocketConnections,
MasterDbConnections: masterDbConnections,
ReplicaDbConnections: replicaDbConnections,
/* Cluster */
ClusterID: clusterID,
@ -186,10 +224,16 @@ func (a *App) generateSupportPacketYaml(c request.CTX) (*model.FileData, error)
/* License */
LicenseTo: licenseTo,
LicenseSupportedUsers: supportedUsers,
LicenseIsTrial: strconv.FormatBool(isTrial),
LicenseIsTrial: isTrial,
/* Server stats */
ActiveUsers: int(uniqueUserCount),
ActiveUsers: int(uniqueUserCount),
DailyActiveUsers: dailyActiveUsers,
MonthlyActiveUsers: monthlyActiveUsers,
InactiveUserCount: inactiveUserCount,
TotalPosts: totalPosts,
TotalChannels: totalChannels,
TotalTeams: totalTeams,
/* Jobs */
DataRetentionJobs: dataRetentionJobs,
@ -201,26 +245,6 @@ func (a *App) generateSupportPacketYaml(c request.CTX) (*model.FileData, error)
MigrationJobs: migrationJobs,
}
/* Server stats */
analytics, appErr := a.GetAnalytics(c, "standard", "")
if appErr != nil {
rErr = multierror.Append(errors.Wrap(appErr, "error while getting analytics"))
}
if len(analytics) < 11 {
rErr = multierror.Append(errors.New("not enought analytics information found"))
} else {
supportPacket.TotalChannels = int(analytics[0].Value) + int(analytics[1].Value)
supportPacket.TotalPosts = int(analytics[2].Value)
supportPacket.TotalTeams = int(analytics[4].Value)
supportPacket.WebsocketConnections = int(analytics[5].Value)
supportPacket.MasterDbConnections = int(analytics[6].Value)
supportPacket.ReplicaDbConnections = int(analytics[7].Value)
supportPacket.DailyActiveUsers = int(analytics[8].Value)
supportPacket.MonthlyActiveUsers = int(analytics[9].Value)
supportPacket.InactiveUserCount = int(analytics[10].Value)
}
// Marshal to a Yaml File
supportPacketYaml, err := yaml.Marshal(&supportPacket)
if err != nil {

View File

@ -61,6 +61,7 @@ func TestGenerateSupportPacketYaml(t *testing.T) {
assert.Equal(t, 3, packet.ActiveUsers) // from InitBasic.
assert.Equal(t, licenseUsers, packet.LicenseSupportedUsers)
assert.Equal(t, false, packet.LicenseIsTrial)
assert.Empty(t, packet.ClusterID)
assert.Equal(t, "local", packet.FileDriver)
assert.Equal(t, "OK", packet.FileStatus)

View File

@ -84,7 +84,7 @@ type SupportPacket struct {
ServerOS string `yaml:"server_os"`
ServerArchitecture string `yaml:"server_architecture"`
ServerVersion string `yaml:"server_version"`
BuildHash string `yaml:"build_hash,omitempty"`
BuildHash string `yaml:"build_hash"`
/* DB */
@ -117,8 +117,8 @@ type SupportPacket struct {
/* License */
LicenseTo string `yaml:"license_to"`
LicenseSupportedUsers int `yaml:"license_supported_users,omitempty"`
LicenseIsTrial string `yaml:"license_is_trial,omitempty"`
LicenseSupportedUsers int `yaml:"license_supported_users"`
LicenseIsTrial bool `yaml:"license_is_trial,omitempty"`
/* Server stats */