Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: metric update (#3392)
ecmadao3002196e07a8
diff --git a/metric/collector/database_count.go b/metric/collector/database_count.goindex 19821f5354..37ae353188 100644--- a/metric/collector/database_count.go+++ b/metric/collector/database_count.go@@ -33,7 +33,7 @@ func (c *databaseCountCollector) Collect(ctx context.Context) ([]*metric.Metric,}for _, databaseCountMetric := range databaseCountMetricList {- labels := map[string]string{+ labels := map[string]interface{}{"backup_schedule": "null","backup_enabled": "null",}diff --git a/metric/collector/instance_count.go b/metric/collector/instance_count.goindex 3e6590c9c9..9818b76ec6 100644--- a/metric/collector/instance_count.go+++ b/metric/collector/instance_count.go@@ -44,7 +44,7 @@ func (c *instanceCountCollector) Collect(ctx context.Context) ([]*metric.Metric,res = append(res, &metric.Metric{Name: metricAPI.InstanceCountMetricName,Value: instanceCountMetric.Count,- Labels: map[string]string{+ Labels: map[string]interface{}{"engine": string(instanceCountMetric.Engine),"environment": env.Name,"status": string(instanceCountMetric.RowStatus),diff --git a/metric/collector/issue_count.go b/metric/collector/issue_count.goindex 38cba6a2b1..7403f81d1a 100644--- a/metric/collector/issue_count.go+++ b/metric/collector/issue_count.go@@ -35,7 +35,7 @@ func (c *issueCountCollector) Collect(ctx context.Context) ([]*metric.Metric, erres = append(res, &metric.Metric{Name: metricAPI.IssueCountMetricName,Value: issueCountMetric.Count,- Labels: map[string]string{+ Labels: map[string]interface{}{"type": string(issueCountMetric.Type),"status": string(issueCountMetric.Status),},diff --git a/metric/collector/member_count.go b/metric/collector/member_count.goindex 2ce6acc413..20e0d78ffc 100644--- a/metric/collector/member_count.go+++ b/metric/collector/member_count.go@@ -35,7 +35,7 @@ func (c *memberCountCollector) Collect(ctx context.Context) ([]*metric.Metric, eres = append(res, &metric.Metric{Name: metricAPI.MemberCountMetricName,Value: memberCountMetric.Count,- Labels: map[string]string{+ Labels: map[string]interface{}{"role": string(memberCountMetric.Role),"status": string(memberCountMetric.Status),"row_status": string(memberCountMetric.RowStatus),diff --git a/metric/collector/policy_count.go b/metric/collector/policy_count.goindex 4abb812c61..1cb3f33316 100644--- a/metric/collector/policy_count.go+++ b/metric/collector/policy_count.go@@ -79,7 +79,7 @@ func (c *policyCountCollector) Collect(ctx context.Context) ([]*metric.Metric, eres = append(res, &metric.Metric{Name: metricAPI.PolicyCountMetricName,Value: policyCountMetric.Count,- Labels: map[string]string{+ Labels: map[string]interface{}{"type": string(policyCountMetric.Type),"environment": policyCountMetric.EnvironmentName,"value": policyCountMetric.Value,diff --git a/metric/collector/project_count.go b/metric/collector/project_count.goindex 260630e212..c1de0e69b3 100644--- a/metric/collector/project_count.go+++ b/metric/collector/project_count.go@@ -35,7 +35,7 @@ func (c *projectCountCollector) Collect(ctx context.Context) ([]*metric.Metric,res = append(res, &metric.Metric{Name: metricAPI.ProjectCountMetricName,Value: projectCountMetric.Count,- Labels: map[string]string{+ Labels: map[string]interface{}{"tenant_mode": string(projectCountMetric.TenantMode),"workflow": string(projectCountMetric.WorkflowType),"status": string(projectCountMetric.RowStatus),diff --git a/metric/collector/sheet_count.go b/metric/collector/sheet_count.goindex 1adc1d8ec7..e5416341e6 100644--- a/metric/collector/sheet_count.go+++ b/metric/collector/sheet_count.go@@ -35,7 +35,7 @@ func (c *sheetCountCollector) Collect(ctx context.Context) ([]*metric.Metric, erres = append(res, &metric.Metric{Name: metricAPI.SheetCountMetricName,Value: sheetCountMetric.Count,- Labels: map[string]string{+ Labels: map[string]interface{}{"row_status": string(sheetCountMetric.RowStatus),"visibility": string(sheetCountMetric.Visibility),"source": string(sheetCountMetric.Source),diff --git a/metric/collector/task_count.go b/metric/collector/task_count.goindex 97b288284b..68fe4d7463 100644--- a/metric/collector/task_count.go+++ b/metric/collector/task_count.go@@ -35,7 +35,7 @@ func (c *taskCountCollector) Collect(ctx context.Context) ([]*metric.Metric, errres = append(res, &metric.Metric{Name: metricAPI.TaskCountMetricName,Value: taskCountMetric.Count,- Labels: map[string]string{+ Labels: map[string]interface{}{"type": string(taskCountMetric.Type),"status": string(taskCountMetric.Status),},diff --git a/metric/metric.go b/metric/metric.goindex 8ca7643484..86293b0d02 100644--- a/metric/metric.go+++ b/metric/metric.go@@ -28,6 +28,8 @@ const (OpenAPIMetricName metric.Name = "bb.api.call"// SQLAdviseAPIMetricName is the metric name for SQL check API.SQLAdviseAPIMetricName metric.Name = "bb.api.sql.advise"+ // SubscriptionTrialMetricName is the metric name for trial.+ SubscriptionTrialMetricName metric.Name = "bb.subscription.trial")// InstanceCountMetric is the API message for bb.instance.count.diff --git a/plugin/metric/metric.go b/plugin/metric/metric.goindex 2e3b0f8fcf..80c6581500 100644--- a/plugin/metric/metric.go+++ b/plugin/metric/metric.go@@ -8,7 +8,7 @@ type Name stringtype Metric struct {Name NameValue int- Labels map[string]string+ Labels map[string]interface{}}// Identifier is the identifier for metric.diff --git a/server/metric_reporter.go b/server/metric_reporter.goindex 6629251ad7..d02bd7bdd8 100644--- a/server/metric_reporter.go+++ b/server/metric_reporter.go@@ -24,6 +24,8 @@ const (identifyTraitForPlan = "plan"// identifyTraitForOrgID is the trait key for organization id.identifyTraitForOrgID = "org_id"+ // identifyTraitForOrgName is the trait key for organization name.+ identifyTraitForOrgName = "org_name"// identifyTraitForVersion is the trait key for Bytebase version.identifyTraitForVersion = "version"// principalIDForFirstUser is the principal id for the first user in workspace.@@ -140,11 +142,12 @@ func (m *MetricReporter) identify(ctx context.Context) {if err := m.reporter.Identify(&metric.Identifier{ID: m.workspaceID,Email: email,- Name: orgName,+ Name: principal.Name,Labels: map[string]string{identifyTraitForPlan: plan,identifyTraitForVersion: m.version,identifyTraitForOrgID: orgID,+ identifyTraitForOrgName: orgName,},}); err != nil {log.Debug("reporter identify failed", zap.Error(err))diff --git a/server/openapi.go b/server/openapi.goindex 0ea9bb446c..0dda1eff37 100644--- a/server/openapi.go+++ b/server/openapi.go@@ -157,7 +157,7 @@ func (s *Server) sqlCheckController(c echo.Context) error {s.MetricReporter.report(&metric.Metric{Name: metricAPI.SQLAdviseAPIMetricName,Value: 1,- Labels: map[string]string{+ Labels: map[string]interface{}{"database_type": databaseType,"environment": request.EnvironmentName,},diff --git a/server/openapi_metric.go b/server/openapi_metric.goindex 1e01c04605..88cf147b8c 100644--- a/server/openapi_metric.go+++ b/server/openapi_metric.go@@ -24,7 +24,7 @@ func openAPIMetricMiddleware(s *Server, next echo.HandlerFunc) echo.HandlerFuncs.MetricReporter.report(&metric.Metric{Name: metricAPI.OpenAPIMetricName,Value: 1,- Labels: map[string]string{+ Labels: map[string]interface{}{"latency_ns": strconv.FormatInt(duration.Nanoseconds(), 10),"request_method": requestMethod,"request_path": requestPath,diff --git a/server/subscription.go b/server/subscription.goindex 889cd971c1..1d93fe8c22 100644--- a/server/subscription.go+++ b/server/subscription.go@@ -16,6 +16,8 @@ import ("github.com/bytebase/bytebase/common""github.com/bytebase/bytebase/common/log"enterpriseAPI "github.com/bytebase/bytebase/enterprise/api"+ metricAPI "github.com/bytebase/bytebase/metric"+ "github.com/bytebase/bytebase/plugin/metric")func (s *Server) registerSubscriptionRoutes(g *echo.Group) {@@ -125,7 +127,21 @@ func (s *Server) registerSubscriptionRoutes(g *echo.Group) {}}+ basePlan := s.subscription.Plans.subscription = s.loadSubscription(ctx)+ currentPlan := s.subscription.Plan++ if s.MetricReporter != nil {+ s.MetricReporter.report(&metric.Metric{+ Name: metricAPI.SubscriptionTrialMetricName,+ Value: 1,+ Labels: map[string]interface{}{+ "trial_plan": currentPlan.String(),+ "from_plan": basePlan.String(),+ "lark_notified": false,+ },+ })+ }c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)if err := jsonapi.MarshalPayload(c.Response().Writer, &s.subscription); err != nil {diff --git a/sql-server/advise.go b/sql-server/advise.goindex 88cdfbd56a..d6a9948672 100644--- a/sql-server/advise.go+++ b/sql-server/advise.go@@ -118,7 +118,7 @@ func (s *Server) sqlCheckController(c echo.Context) error {s.metricReporter.Report(&metric.Metric{Name: metricAPI.SQLAdviseAPIMetricName,Value: 1,- Labels: map[string]string{+ Labels: map[string]interface{}{"database_type": string(advisorDBType),"platform": c.Request().Header.Get("X-Platform"),"repository": c.Request().Header.Get("X-Repository"),diff --git a/sql-server/metric.go b/sql-server/metric.goindex b39743044c..331e841663 100644--- a/sql-server/metric.go+++ b/sql-server/metric.go@@ -44,7 +44,7 @@ func metricMiddleware(s *Server, next echo.HandlerFunc) echo.HandlerFunc {s.metricReporter.Report(&metric.Metric{Name: metricAPI.OpenAPIMetricName,Value: 1,- Labels: map[string]string{+ Labels: map[string]interface{}{"latency_ns": strconv.FormatInt(duration.Nanoseconds(), 10),"request_method": requestMethod,"request_path": requestPath,