Skip to content

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

chore: add metric for first registration (#3459)

ecmadao320a56bc73ce
diff --git a/metric/metric.go b/metric/metric.go
index 86293b0d02..8c56ff790e 100644
--- a/metric/metric.go
+++ b/metric/metric.go
@@ -30,6 +30,8 @@ const (
SQLAdviseAPIMetricName metric.Name = "bb.api.sql.advise"
// SubscriptionTrialMetricName is the metric name for trial.
SubscriptionTrialMetricName metric.Name = "bb.subscription.trial"
+ // FirstPrincipalMetricName is the metric name for the first principal.
+ FirstPrincipalMetricName metric.Name = "bb.principal.registration"
)
// InstanceCountMetric is the API message for bb.instance.count.
diff --git a/server/auth.go b/server/auth.go
index b0ea923557..56e6af94be 100644
--- a/server/auth.go
+++ b/server/auth.go
@@ -12,6 +12,8 @@ import (
"github.com/bytebase/bytebase/api"
"github.com/bytebase/bytebase/common"
+ metricAPI "github.com/bytebase/bytebase/metric"
+ "github.com/bytebase/bytebase/plugin/metric"
"github.com/bytebase/bytebase/plugin/vcs"
)
@@ -209,6 +211,18 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to generate access token").SetInternal(err)
}
+ if user.ID == principalIDForFirstUser && s.MetricReporter != nil {
+ s.MetricReporter.report(&metric.Metric{
+ Name: metricAPI.FirstPrincipalMetricName,
+ Value: 1,
+ Labels: map[string]interface{}{
+ "email": user.Email,
+ "name": user.Name,
+ "lark_notified": false,
+ },
+ })
+ }
+
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
if err := jsonapi.MarshalPayload(c.Response().Writer, user); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal sign up response").SetInternal(err)