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
This commit is contained in:
Jesse Hallam 2024-10-07 12:48:03 -03:00 committed by GitHub
parent 64a6e3a120
commit e9968792b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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)
}