SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
chore: move away from parallel usages of licenses v2 and v3 (#6527)
Vikrant Gupta24ab18d98849
diff --git a/ee/query-service/app/api/license.go b/ee/query-service/app/api/license.goindex ff1e24dfff..f0272202be 100644--- a/ee/query-service/app/api/license.go+++ b/ee/query-service/app/api/license.go@@ -84,6 +84,13 @@ func (ah *APIHandler) listLicenses(w http.ResponseWriter, r *http.Request) {}func (ah *APIHandler) applyLicense(w http.ResponseWriter, r *http.Request) {+ if ah.UseLicensesV3 {+ // if the licenses v3 is toggled on then do not apply license in v2 and run the validator!+ // TODO: remove after migration to v3 and deprecation from zeus+ zap.L().Info("early return from apply license v2 call")+ render.Success(w, http.StatusOK, nil)+ return+ }var l model.Licenseif err := json.NewDecoder(r.Body).Decode(&l); err != nil {diff --git a/ee/query-service/license/db.go b/ee/query-service/license/db.goindex eae48e266d..4bd34e232c 100644--- a/ee/query-service/license/db.go+++ b/ee/query-service/license/db.go@@ -18,13 +18,15 @@ import (// Repo is license repo. stores license keys in a secured DBtype Repo struct {- db *sqlx.DB+ db *sqlx.DB+ useLicensesV3 bool}// NewLicenseRepo initiates a new license repo-func NewLicenseRepo(db *sqlx.DB) Repo {+func NewLicenseRepo(db *sqlx.DB, useLicensesV3 bool) Repo {return Repo{- db: db,+ db: db,+ useLicensesV3: useLicensesV3,}}@@ -78,9 +80,7 @@ func (r *Repo) GetLicensesV3(ctx context.Context) ([]*model.LicenseV3, error) {return licenseV3Data, nil}-// GetActiveLicense fetches the latest active license from DB.-// If the license is not present, expect a nil license and a nil error in the output.-func (r *Repo) GetActiveLicense(ctx context.Context) (*model.License, *basemodel.ApiError) {+func (r *Repo) GetActiveLicenseV2(ctx context.Context) (*model.License, *basemodel.ApiError) {var err errorlicenses := []model.License{}@@ -109,6 +109,31 @@ func (r *Repo) GetActiveLicense(ctx context.Context) (*model.License, *basemodelreturn active, nil}+// GetActiveLicense fetches the latest active license from DB.+// If the license is not present, expect a nil license and a nil error in the output.+func (r *Repo) GetActiveLicense(ctx context.Context) (*model.License, *basemodel.ApiError) {+ if r.useLicensesV3 {+ zap.L().Info("Using licenses v3 for GetActiveLicense")+ activeLicenseV3, err := r.GetActiveLicenseV3(ctx)+ if err != nil {+ return nil, basemodel.InternalError(fmt.Errorf("failed to get active licenses from db: %v", err))+ }++ if activeLicenseV3 == nil {+ return nil, nil+ }+ activeLicenseV2 := model.ConvertLicenseV3ToLicenseV2(activeLicenseV3)+ return activeLicenseV2, nil++ }++ active, err := r.GetActiveLicenseV2(ctx)+ if err != nil {+ return nil, err+ }+ return active, nil+}+func (r *Repo) GetActiveLicenseV3(ctx context.Context) (*model.LicenseV3, error) {var err errorlicenses := []model.LicenseDB{}diff --git a/ee/query-service/license/manager.go b/ee/query-service/license/manager.goindex 337d9ecb57..0a4370de3f 100644--- a/ee/query-service/license/manager.go+++ b/ee/query-service/license/manager.go@@ -56,7 +56,7 @@ func StartManager(dbType string, db *sqlx.DB, useLicensesV3 bool, features ...bareturn LM, nil}- repo := NewLicenseRepo(db)+ repo := NewLicenseRepo(db, useLicensesV3)err := repo.InitDB(dbType)if err != nil {@@ -69,7 +69,7 @@ func StartManager(dbType string, db *sqlx.DB, useLicensesV3 bool, features ...baif useLicensesV3 {// get active license from the db- active, err := m.repo.GetActiveLicense(context.Background())+ active, err := m.repo.GetActiveLicenseV2(context.Background())if err != nil {return m, err}@@ -88,6 +88,7 @@ func StartManager(dbType string, db *sqlx.DB, useLicensesV3 bool, features ...baif apiError != nil && apiError.Typ != model.ErrorConflict {return m, apiError}+ zap.L().Info("Successfully inserted license from v2 to v3 table")}}@@ -266,6 +267,7 @@ func (lm *Manager) GetLicensesV3(ctx context.Context) (response []*model.License// Validator validates license after an epoch of timefunc (lm *Manager) Validator(ctx context.Context) {+ zap.L().Info("Validator started!")defer close(lm.terminated)tick := time.NewTicker(validationFrequency)defer tick.Stop()@@ -290,6 +292,7 @@ func (lm *Manager) Validator(ctx context.Context) {// Validator validates license after an epoch of timefunc (lm *Manager) ValidatorV3(ctx context.Context) {+ zap.L().Info("ValidatorV3 started!")defer close(lm.terminated)tick := time.NewTicker(validationFrequency)defer tick.Stop()@@ -379,7 +382,6 @@ func (lm *Manager) Validate(ctx context.Context) (reterr error) {return nil}-// todo[vikrantgupta25]: check the comparison here between old and new license!func (lm *Manager) RefreshLicense(ctx context.Context) *model.ApiError {license, apiError := validate.ValidateLicenseV3(lm.activeLicenseV3.Key)diff --git a/ee/query-service/model/license.go b/ee/query-service/model/license.goindex 2f9a0feeda..706985f027 100644--- a/ee/query-service/model/license.go+++ b/ee/query-service/model/license.go@@ -247,3 +247,24 @@ func NewLicenseV3WithIDAndKey(id string, key string, data map[string]interface{}licenseDataWithIdAndKey["key"] = keyreturn NewLicenseV3(licenseDataWithIdAndKey)}++func ConvertLicenseV3ToLicenseV2(l *LicenseV3) *License {+ planKeyFromPlanName, ok := MapOldPlanKeyToNewPlanName[l.PlanName]+ if !ok {+ planKeyFromPlanName = Basic+ }+ return &License{+ Key: l.Key,+ ActivationId: "",+ PlanDetails: "",+ FeatureSet: l.Features,+ ValidationMessage: "",+ IsCurrent: l.IsCurrent,+ LicensePlan: LicensePlan{+ PlanKey: planKeyFromPlanName,+ ValidFrom: l.ValidFrom,+ ValidUntil: l.ValidUntil,+ Status: l.Status},+ }++}