Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: add org id in user identifier (#1719)

ecmadao38d1322a833a
diff --git a/enterprise/api/license.go b/enterprise/api/license.go
index 19f89c7774..657d539495 100644
--- a/enterprise/api/license.go
+++ b/enterprise/api/license.go
@@ -2,6 +2,7 @@ package api
import (
"fmt"
+ "strings"
"time"
"github.com/bytebase/bytebase/api"
@@ -50,6 +51,11 @@ func (l *License) validPlanType() error {
)
}
+// OrgID extract the organization id from license subject.
+func (l *License) OrgID() string {
+ return strings.Split(l.Subject, ".")[0]
+}
+
// LicenseService is the service for enterprise license.
type LicenseService interface {
// StoreLicense will store license into file.
diff --git a/enterprise/api/subscription.go b/enterprise/api/subscription.go
index 9f6caa5c41..9ae142c888 100644
--- a/enterprise/api/subscription.go
+++ b/enterprise/api/subscription.go
@@ -15,4 +15,5 @@ type Subscription struct {
StartedTs int64 `jsonapi:"attr,startedTs"`
Plan api.PlanType `jsonapi:"attr,plan"`
Trialing bool `jsonapi:"attr,trialing"`
+ OrgID string `jsonapi:"attr,orgId"`
}
diff --git a/server/metric_reporter.go b/server/metric_reporter.go
index cb72d3a077..df85f8909c 100644
--- a/server/metric_reporter.go
+++ b/server/metric_reporter.go
@@ -19,6 +19,8 @@ const (
metricSchedulerInterval = time.Duration(1) * time.Hour
// identifyTraitForPlan is the trait key for subscription plan.
identifyTraitForPlan = "plan"
+ // identifyTraitForOrgID is the trait key for organization id.
+ identifyTraitForOrgID = "org_id"
// identifyTraitForVersion is the trait key for Bytebase version.
identifyTraitForVersion = "version"
)
@@ -117,14 +119,18 @@ func (m *MetricReporter) Register(metricName metric.Name, collector metric.Colle
// Identify will identify the workspace and update the subscription plan.
func (m *MetricReporter) identify() {
plan := api.FREE.String()
+ orgID := ""
+
if m.subscription != nil {
plan = m.subscription.Plan.String()
+ orgID = m.subscription.OrgID
}
if err := m.reporter.Identify(&metric.Identifier{
ID: m.workspaceID,
Labels: map[string]string{
identifyTraitForPlan: plan,
identifyTraitForVersion: m.version,
+ identifyTraitForOrgID: orgID,
},
}); err != nil {
log.Debug("reporter identify failed", zap.Error(err))
diff --git a/server/subscription.go b/server/subscription.go
index 5b0c61140e..9ff5bfb626 100644
--- a/server/subscription.go
+++ b/server/subscription.go
@@ -61,6 +61,7 @@ func (s *Server) loadSubscription() enterpriseAPI.Subscription {
StartedTs: license.IssuedTs,
InstanceCount: license.InstanceCount,
Trialing: license.Trialing,
+ OrgID: license.OrgID(),
}
}