From e9968792b0d4a29bf56c98725b232fe32be6fe04 Mon Sep 17 00:00:00 2001 From: Jesse Hallam Date: Mon, 7 Oct 2024 12:48:03 -0300 Subject: [PATCH] Emit license details to logs when added or removed (#28333) * log when changing the license * handle test licenses without features or customer data * skip logLicense if logger not setup --- server/channels/app/platform/license.go | 39 +++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/server/channels/app/platform/license.go b/server/channels/app/platform/license.go index 1e162cf15e7..e879521db7f 100644 --- a/server/channels/app/platform/license.go +++ b/server/channels/app/platform/license.go @@ -227,9 +227,18 @@ func (ps *PlatformService) SetLicense(license *model.License) bool { ps.licenseValue.Store(license) ps.clientLicenseValue.Store(utils.GetClientLicense(license)) + + if oldLicense == nil || oldLicense.Id != license.Id { + ps.logLicense("Set license", license) + } + return true } + if oldLicense != nil { + ps.logLicense("Cleared license", oldLicense) + } + ps.licenseValue.Store((*model.License)(nil)) ps.clientLicenseValue.Store(map[string]string(nil)) @@ -344,3 +353,33 @@ func (ps *PlatformService) RequestTrialLicense(trialRequest *model.TrialLicenseR func (ps *PlatformService) getRequestTrialURL() string { return fmt.Sprintf("%s/api/v1/trials", *ps.Config().CloudSettings.CWSURL) } + +func (ps *PlatformService) logLicense(message string, license *model.License) { + if ps.logger == nil { + return + } + + logger := ps.logger.With( + mlog.String("id", license.Id), + mlog.Time("issued_at", model.GetTimeForMillis(license.IssuedAt)), + mlog.Time("starts_at", model.GetTimeForMillis(license.StartsAt)), + mlog.Time("expires_at", model.GetTimeForMillis(license.ExpiresAt)), + mlog.String("sku_name", license.SkuName), + mlog.String("sku_short_name", license.SkuShortName), + mlog.Bool("is_trial", license.IsTrial), + mlog.Bool("is_gov_sku", license.IsGovSku), + ) + + if license.Customer != nil { + logger = logger.With(mlog.String("customer_id", license.Customer.Id)) + } + + if license.Features != nil { + logger = logger.With( + mlog.Int("features.users", *license.Features.Users), + mlog.Map("features", license.Features.ToMap()), + ) + } + + logger.Info(message) +}