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: add more metrics (#5532)
ecmadao884e41ffc1f8
diff --git a/backend/api/v1/auth_service.go b/backend/api/v1/auth_service.goindex 525d4f77a7..09d177d7a5 100644--- a/backend/api/v1/auth_service.go+++ b/backend/api/v1/auth_service.go@@ -578,6 +578,14 @@ func (s *AuthService) Login(ctx context.Context, request *v1pb.LoginRequest) (*vreturn nil, status.Errorf(codes.Internal, "failed to set grpc header, error: %v", err)}}++ s.metricReporter.Report(ctx, &metric.Metric{+ Name: metricAPI.PrincipalLoginMetricName,+ Value: 1,+ Labels: map[string]any{+ "email": loginUser.Email,+ },+ })return &v1pb.LoginResponse{Token: accessToken,}, nildiff --git a/backend/api/v1/instance_service.go b/backend/api/v1/instance_service.goindex 41e0d92df3..b17a9a76b3 100644--- a/backend/api/v1/instance_service.go+++ b/backend/api/v1/instance_service.go@@ -14,7 +14,10 @@ import ("github.com/bytebase/bytebase/backend/component/state"enterpriseAPI "github.com/bytebase/bytebase/backend/enterprise/api"api "github.com/bytebase/bytebase/backend/legacyapi"+ metricAPI "github.com/bytebase/bytebase/backend/metric""github.com/bytebase/bytebase/backend/plugin/db"+ "github.com/bytebase/bytebase/backend/plugin/metric"+ "github.com/bytebase/bytebase/backend/runner/metricreport""github.com/bytebase/bytebase/backend/store"v1pb "github.com/bytebase/bytebase/proto/generated-go/v1")@@ -24,15 +27,17 @@ type InstanceService struct {v1pb.UnimplementedInstanceServiceServerstore *store.StorelicenseService enterpriseAPI.LicenseService+ metricReporter *metricreport.Reportersecret stringstateCfg *state.State}// NewInstanceService creates a new InstanceService.-func NewInstanceService(store *store.Store, licenseService enterpriseAPI.LicenseService, secret string, stateCfg *state.State) *InstanceService {+func NewInstanceService(store *store.Store, licenseService enterpriseAPI.LicenseService, metricReporter *metricreport.Reporter, secret string, stateCfg *state.State) *InstanceService {return &InstanceService{store: store,licenseService: licenseService,+ metricReporter: metricReporter,secret: secret,stateCfg: stateCfg,}@@ -104,6 +109,14 @@ func (s *InstanceService) CreateInstance(ctx context.Context, request *v1pb.Creareturn nil, status.Errorf(codes.Internal, err.Error())}+ s.metricReporter.Report(ctx, &metric.Metric{+ Name: metricAPI.InstanceCreateMetricName,+ Value: 1,+ Labels: map[string]any{+ "engine": instance.Engine,+ },+ })+// TODO(d): sync instance databases.return convertToInstance(instance), nil}diff --git a/backend/metric/metric.go b/backend/metric/metric.goindex 0633b9b51f..1fb0f670bd 100644--- a/backend/metric/metric.go+++ b/backend/metric/metric.go@@ -32,6 +32,8 @@ const (SubscriptionTrialMetricName metric.Name = "bb.subscription.trial"// PrincipalRegistrationMetricName is the metric name for the principal registration event.PrincipalRegistrationMetricName metric.Name = "bb.principal.registration"+ // PrincipalLoginMetricName is the metric name for principal login event.+ PrincipalLoginMetricName metric.Name = "bb.principal.login"// IssueCreateMetricName is the metric name for issue creation event.IssueCreateMetricName metric.Name = "bb.issue.create"// TaskStatusMetricName is the metric name for task status update event.@@ -42,6 +44,8 @@ const (PrincipalCreateMetricName metric.Name = "bb.principal.create"// APIRequestMetricName is the metric name for api request.APIRequestMetricName metric.Name = "bb.api.request"+ // InstanceCreateMetricName is the metric name for instance creation event.+ InstanceCreateMetricName metric.Name = "bb.instance.create")// InstanceCountMetric is the API message for bb.instance.count.diff --git a/backend/server/instance.go b/backend/server/instance.goindex 3de67d1dcf..cee162e39c 100644--- a/backend/server/instance.go+++ b/backend/server/instance.go@@ -15,7 +15,9 @@ import ("github.com/bytebase/bytebase/backend/common""github.com/bytebase/bytebase/backend/common/log"api "github.com/bytebase/bytebase/backend/legacyapi"+ metricAPI "github.com/bytebase/bytebase/backend/metric""github.com/bytebase/bytebase/backend/plugin/db"+ "github.com/bytebase/bytebase/backend/plugin/metric""github.com/bytebase/bytebase/backend/plugin/parser""github.com/bytebase/bytebase/backend/plugin/parser/transform""github.com/bytebase/bytebase/backend/resources/postgres"@@ -104,6 +106,14 @@ func (s *Server) registerInstanceRoutes(g *echo.Group) {s.stateCfg.InstanceDatabaseSyncChan <- composedInstance}+ s.MetricReporter.Report(ctx, &metric.Metric{+ Name: metricAPI.InstanceCreateMetricName,+ Value: 1,+ Labels: map[string]any{+ "engine": composedInstance.Engine,+ },+ })+c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)if err := jsonapi.MarshalPayload(c.Response().Writer, composedInstance); err != nil {return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal create instance response").SetInternal(err)diff --git a/backend/server/server.go b/backend/server/server.goindex 233efa41d8..6a0d00d9ed 100644--- a/backend/server/server.go+++ b/backend/server/server.go@@ -559,6 +559,7 @@ func NewServer(ctx context.Context, profile config.Profile) (*Server, error) {v1pb.RegisterInstanceServiceServer(s.grpcServer, v1.NewInstanceService(s.store,s.licenseService,+ s.MetricReporter,s.secret,s.stateCfg))v1pb.RegisterProjectServiceServer(s.grpcServer, v1.NewProjectService(s.store))