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: deprecate issue subscribers and task patch (#8222)
Danny Xufb4705b31873
diff --git a/backend/bin/server/cmd/profile.go b/backend/bin/server/cmd/profile.goindex e3bc95e712..e0fc0a1109 100644--- a/backend/bin/server/cmd/profile.go+++ b/backend/bin/server/cmd/profile.go@@ -29,7 +29,6 @@ func getBaseProfile(dataDir string) config.Profile {SaaS: flags.saas,DataDir: dataDir,ResourceDir: common.GetResourceDir(dataDir),- Debug: flags.debug,DemoName: flags.demoName,Version: version,GitCommit: gitcommit,diff --git a/backend/bin/sql-service/cmd/profile_dev.go b/backend/bin/sql-service/cmd/profile_dev.goindex 7ea2661c04..cd45dc4a1e 100644--- a/backend/bin/sql-service/cmd/profile_dev.go+++ b/backend/bin/sql-service/cmd/profile_dev.go@@ -12,7 +12,6 @@ func activeProfile() server.Profile {Mode: common.ReleaseModeDev,BackendHost: flags.host,BackendPort: flags.port,- Debug: flags.debug,Version: version,GitCommit: gitcommit,MetricConnectionKey: "",diff --git a/backend/bin/sql-service/cmd/profile_release.go b/backend/bin/sql-service/cmd/profile_release.goindex 3dceeaa0f9..88aa808147 100644--- a/backend/bin/sql-service/cmd/profile_release.go+++ b/backend/bin/sql-service/cmd/profile_release.go@@ -12,7 +12,6 @@ func activeProfile() server.Profile {Mode: common.ReleaseModeProd,BackendHost: flags.host,BackendPort: flags.port,- Debug: flags.debug,Version: version,GitCommit: gitcommit,MetricConnectionKey: "46nEgegY1APWBz4NcQp0rCRJomDnLJyE",diff --git a/backend/component/config/profile.go b/backend/component/config/profile.goindex fa184a4729..f1454895c6 100644--- a/backend/component/config/profile.go+++ b/backend/component/config/profile.go@@ -36,8 +36,6 @@ type Profile struct {DataDir string// ResourceDir is the directory stores the resources including embedded postgres, mysqlutil, mongoutil and etc.ResourceDir string- // Debug decides the log level- Debug bool// DemoName specifies the demo name. Empty string means no demo.DemoName string// AppRunnerInterval is the interval for application runner.diff --git a/backend/legacyapi/issue_subscriber.go b/backend/legacyapi/issue_subscriber.godeleted file mode 100644index 18bf99c44d..0000000000--- a/backend/legacyapi/issue_subscriber.go+++ /dev/null@@ -1,13 +0,0 @@-package api--// IssueSubscriber is the API message for an issue subscriber.-type IssueSubscriber struct {- // Domain specific fields- IssueID int `jsonapi:"attr,issueId"`- Subscriber *Principal `jsonapi:"relation,subscriber"`-}--// IssueSubscriberCreate is the API message for creating an issue subscriber.-type IssueSubscriberCreate struct {- SubscriberID int `jsonapi:"attr,subscriberId"`-}diff --git a/backend/server/legacy_issue_subscriber.go b/backend/server/legacy_issue_subscriber.godeleted file mode 100644index af7d638261..0000000000--- a/backend/server/legacy_issue_subscriber.go+++ /dev/null@@ -1,135 +0,0 @@-package server--import (- "fmt"- "net/http"- "strconv"-- "github.com/google/jsonapi"- "github.com/labstack/echo/v4"-- api "github.com/bytebase/bytebase/backend/legacyapi"- "github.com/bytebase/bytebase/backend/store"-)--func (s *Server) registerIssueSubscriberRoutes(g *echo.Group) {- g.POST("/issue/:issueID/subscriber", func(c echo.Context) error {- ctx := c.Request().Context()- issueID, err := strconv.Atoi(c.Param("issueID"))- if err != nil {- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("issueID"))).SetInternal(err)- }- issue, err := s.store.GetIssueV2(ctx, &store.FindIssueMessage{UID: &issueID})- if err != nil {- return err- }- if issue == nil {- return echo.NewHTTPError(http.StatusNotFound, "issue not found")- }-- issueSubscriberCreate := &api.IssueSubscriberCreate{}- if err := jsonapi.UnmarshalPayload(c.Request().Body, issueSubscriberCreate); err != nil {- return echo.NewHTTPError(http.StatusBadRequest, "Malformed create issueSubscriber request").SetInternal(err)- }-- newSubscriber, err := s.store.GetUserByID(ctx, issueSubscriberCreate.SubscriberID)- if err != nil {- return err- }- if newSubscriber == nil {- return echo.NewHTTPError(http.StatusNotFound, "subscriber not found")- }- newSubscribers := issue.Subscribers- newSubscribers = append(newSubscribers, newSubscriber)-- if _, err := s.store.UpdateIssueV2(ctx, issueID, &store.UpdateIssueMessage{Subscribers: &newSubscribers}, api.SystemBotID); err != nil {- return err- }-- composedSubscriber, err := s.store.GetPrincipalByID(ctx, newSubscriber.ID)- if err != nil {- return err- }- issueSubscriber := &api.IssueSubscriber{IssueID: issueID, Subscriber: composedSubscriber}- c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)- if err := jsonapi.MarshalPayload(c.Response().Writer, issueSubscriber); err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal create issue subscriber response").SetInternal(err)- }- return nil- })-- g.GET("/issue/:issueID/subscriber", func(c echo.Context) error {- ctx := c.Request().Context()- issueID, err := strconv.Atoi(c.Param("issueID"))- if err != nil {- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("issueID"))).SetInternal(err)- }- issue, err := s.store.GetIssueV2(ctx, &store.FindIssueMessage{UID: &issueID})- if err != nil {- return err- }- if issue == nil {- return echo.NewHTTPError(http.StatusNotFound, "issue not found")- }-- var issueSubscribers []*api.IssueSubscriber- for _, subscriber := range issue.Subscribers {- composedSubscriber, err := s.store.GetPrincipalByID(ctx, subscriber.ID)- if err != nil {- return err- }- issueSubscribers = append(issueSubscribers, &api.IssueSubscriber{- IssueID: issueID,- Subscriber: composedSubscriber,- })- }-- c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)- if err := jsonapi.MarshalPayload(c.Response().Writer, issueSubscribers); err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal issue subscriber list response").SetInternal(err)- }- return nil- })-- g.DELETE("/issue/:issueID/subscriber/:subscriberID", func(c echo.Context) error {- ctx := c.Request().Context()- issueID, err := strconv.Atoi(c.Param("issueID"))- if err != nil {- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Issue ID is not a number: %s", c.Param("issueID"))).SetInternal(err)- }- issue, err := s.store.GetIssueV2(ctx, &store.FindIssueMessage{UID: &issueID})- if err != nil {- return err- }- if issue == nil {- return echo.NewHTTPError(http.StatusNotFound, "issue not found")- }-- subscriberID, err := strconv.Atoi(c.Param("subscriberID"))- if err != nil {- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Subscriber ID is not a number: %s", c.Param("subscriberID"))).SetInternal(err)- }- subscriber, err := s.store.GetUserByID(ctx, subscriberID)- if err != nil {- return err- }- if subscriber == nil {- return echo.NewHTTPError(http.StatusNotFound, "subscriber not found")- }-- var newSubscribers []*store.UserMessage- for _, subscriber := range issue.Subscribers {- if subscriber.ID == subscriberID {- continue- }- newSubscribers = append(newSubscribers, subscriber)- }- if _, err := s.store.UpdateIssueV2(ctx, issueID, &store.UpdateIssueMessage{Subscribers: &newSubscribers}, api.SystemBotID); err != nil {- return err- }-- c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)- c.Response().WriteHeader(http.StatusOK)- return nil- })-}diff --git a/backend/server/legacy_task.go b/backend/server/legacy_task.godeleted file mode 100644index 1cc4dfd030..0000000000--- a/backend/server/legacy_task.go+++ /dev/null@@ -1,144 +0,0 @@-package server--import (- "context"- "encoding/json"- "fmt"- "net/http"- "strconv"-- "github.com/google/jsonapi"- "github.com/labstack/echo/v4"- "github.com/pkg/errors"-- "github.com/bytebase/bytebase/backend/common"- "github.com/bytebase/bytebase/backend/component/activity"- api "github.com/bytebase/bytebase/backend/legacyapi"- "github.com/bytebase/bytebase/backend/store"- "github.com/bytebase/bytebase/backend/utils"- storepb "github.com/bytebase/bytebase/proto/generated-go/store"-)--func (s *Server) registerTaskRoutes(g *echo.Group) {- g.PATCH("/pipeline/:pipelineID/task/:taskID", func(c echo.Context) error {- ctx := c.Request().Context()- taskID, err := strconv.Atoi(c.Param("taskID"))- if err != nil {- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Task ID is not a number: %s", c.Param("taskID"))).SetInternal(err)- }-- taskPatch := &api.TaskPatch{- ID: taskID,- UpdaterID: api.SystemBotID,- }- if err := jsonapi.UnmarshalPayload(c.Request().Body, taskPatch); err != nil {- return echo.NewHTTPError(http.StatusBadRequest, "Malformed update task request").SetInternal(err)- }- if taskPatch.SheetID != nil {- schemaVersion := common.DefaultMigrationVersion()- taskPatch.SchemaVersion = &schemaVersion- }-- task, err := s.store.GetTaskV2ByID(ctx, taskID)- if err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, "Failed to update task").SetInternal(err)- }- if task == nil {- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Task ID not found: %d", taskID))- }-- instance, err := s.store.GetInstanceV2(ctx, &store.FindInstanceMessage{UID: &task.InstanceID})- if err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to find instance %d", task.InstanceID)).SetInternal(err)- }- if instance == nil {- return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Cannot found the find instance %d", task.InstanceID))- }- if taskPatch.EarliestAllowedTs != nil {- if err := s.licenseService.IsFeatureEnabledForInstance(api.FeatureTaskScheduleTime, instance); err != nil {- return echo.NewHTTPError(http.StatusForbidden, err.Error())- }- }-- issue, err := s.store.GetIssueV2(ctx, &store.FindIssueMessage{PipelineID: &task.PipelineID})- if err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch issue with pipeline ID: %d", task.PipelineID)).SetInternal(err)- }- if issue == nil {- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Issue not found with pipelineID: %d", task.PipelineID))- }-- if taskPatch.RollbackEnabled != nil && task.Type != api.TaskDatabaseDataUpdate {- return echo.NewHTTPError(http.StatusBadRequest, "cannot generate rollback SQL statement for a non-DML task")- }-- if err := patchTask(ctx, s.store, s.activityManager, task, taskPatch, issue); err != nil {- return err- }-- // dismiss stale review, re-find the approval template- if taskPatch.SheetID != nil {- issue, err := s.store.UpdateIssueV2(ctx, issue.UID, &store.UpdateIssueMessage{- PayloadUpsert: &storepb.IssuePayload{- Approval: &storepb.IssuePayloadApproval{- ApprovalFindingDone: false,- },- },- }, api.SystemBotID)- if err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, "Failed to update issue").SetInternal(err)- }- s.stateCfg.ApprovalFinding.Store(issue.UID, issue)- }-- composedTaskPatched, err := s.store.GetTaskByID(ctx, task.ID)- if err != nil {- return err- }-- c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)- if err := jsonapi.MarshalPayload(c.Response().Writer, composedTaskPatched); err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to marshal update task \"%v\" status response", task.Name)).SetInternal(err)- }- return nil- })-}--// patchTask patches the statement for a task.-func patchTask(ctx context.Context, stores *store.Store, activityManager *activity.Manager, task *store.TaskMessage, taskPatch *api.TaskPatch, issue *store.IssueMessage) error {- taskPatched, err := stores.UpdateTaskV2(ctx, taskPatch)- if err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to update task \"%v\"", task.Name)).SetInternal(err)- }- if taskPatch.SheetID != nil {- oldSheetID, err := utils.GetTaskSheetID(task.Payload)- if err != nil {- return errors.Wrap(err, "failed to get old sheet ID")- }- newSheetID := *taskPatch.SheetID-- // create a task sheet update activity- payload, err := json.Marshal(api.ActivityPipelineTaskStatementUpdatePayload{- TaskID: taskPatched.ID,- OldSheetID: oldSheetID,- NewSheetID: newSheetID,- TaskName: task.Name,- IssueName: issue.Title,- })- if err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create activity after updating task sheet: %v", taskPatched.Name).SetInternal(err)- }- if _, err := activityManager.CreateActivity(ctx, &store.ActivityMessage{- CreatorUID: taskPatch.UpdaterID,- ContainerUID: taskPatched.PipelineID,- Type: api.ActivityPipelineTaskStatementUpdate,- Payload: string(payload),- Level: api.ActivityInfo,- }, &activity.Metadata{- Issue: issue,- }); err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to create activity after updating task statement: %v", taskPatched.Name)).SetInternal(err)- }- }- return nil-}diff --git a/backend/server/recover.go b/backend/server/recover.godeleted file mode 100644index 866b9125c4..0000000000--- a/backend/server/recover.go+++ /dev/null@@ -1,27 +0,0 @@-package server--import (- "log/slog"-- "github.com/labstack/echo/v4"- "github.com/pkg/errors"-- "github.com/bytebase/bytebase/backend/common/log"-)--func recoverMiddleware(next echo.HandlerFunc) echo.HandlerFunc {- return func(c echo.Context) error {- defer func() {- if r := recover(); r != nil {- err, ok := r.(error)- if !ok {- err = errors.Errorf("%v", r)- }- slog.Error("Middleware PANIC RECOVER", log.BBError(err), log.BBStack("panic-stack"))-- c.Error(err)- }- }()- return next(c)- }-}diff --git a/backend/server/routers.go b/backend/server/routers.gonew file mode 100644index 0000000000..8bb40777b7--- /dev/null+++ b/backend/server/routers.go@@ -0,0 +1,100 @@+package server++import (+ "log/slog"+ "net/http"+ "strings"+ "time"++ grpcRuntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"+ "github.com/improbable-eng/grpc-web/go/grpcweb"+ "github.com/labstack/echo-contrib/pprof"+ "github.com/labstack/echo-contrib/prometheus"+ "github.com/labstack/echo/v4"+ "github.com/labstack/echo/v4/middleware"+ "github.com/pkg/errors"+ "github.com/tmc/grpc-websocket-proxy/wsproxy"+ "google.golang.org/grpc"++ "github.com/bytebase/bytebase/backend/common/log"+)++func configureEchoRouters(e *echo.Echo, grpcServer *grpc.Server, mux *grpcRuntime.ServeMux) {+ // Embed frontend.+ embedFrontend(e)++ e.HideBanner = true+ e.HidePort = true+ e.Use(recoverMiddleware)+ grpcSkipper := func(c echo.Context) bool {+ // Skip grpc and webhook calls.+ return strings.HasPrefix(c.Request().URL.Path, "/bytebase.v1.") ||+ strings.HasPrefix(c.Request().URL.Path, "/v1:adminExecute") ||+ strings.HasPrefix(c.Request().URL.Path, webhookAPIPrefix)+ }+ e.Use(middleware.TimeoutWithConfig(middleware.TimeoutConfig{+ Skipper: grpcSkipper,+ Timeout: 30 * time.Second,+ }))+ e.Use(middleware.RateLimiterWithConfig(middleware.RateLimiterConfig{+ Skipper: grpcSkipper,+ Store: middleware.NewRateLimiterMemoryStoreWithConfig(+ middleware.RateLimiterMemoryStoreConfig{Rate: 30, Burst: 60, ExpiresIn: 3 * time.Minute},+ ),+ IdentifierExtractor: func(ctx echo.Context) (string, error) {+ id := ctx.RealIP()+ return id, nil+ },+ ErrorHandler: func(context echo.Context, err error) error {+ return context.JSON(http.StatusForbidden, nil)+ },+ DenyHandler: func(context echo.Context, identifier string, err error) error {+ return context.JSON(http.StatusTooManyRequests, nil)+ },+ }))+ pprof.Register(e)+ p := prometheus.NewPrometheus("api", nil)+ p.Use(e)++ e.GET("/healthz", func(c echo.Context) error {+ return c.String(http.StatusOK, "OK")+ })+ e.GET("/v1:adminExecute", echo.WrapHandler(wsproxy.WebsocketProxy(+ mux,+ wsproxy.WithTokenCookieName("access-token"),+ // 10M.+ wsproxy.WithMaxRespBodyBufferSize(10*1024*1024),+ )))+ e.Any("/v1/*", echo.WrapHandler(mux))++ // GRPC web proxy.+ options := []grpcweb.Option{+ grpcweb.WithCorsForRegisteredEndpointsOnly(false),+ grpcweb.WithOriginFunc(func(origin string) bool {+ return true+ }),+ grpcweb.WithWebsockets(true),+ grpcweb.WithWebsocketOriginFunc(func(req *http.Request) bool {+ return true+ }),+ }+ wrappedGrpc := grpcweb.WrapServer(grpcServer, options...)+ e.Any("/bytebase.v1.*", echo.WrapHandler(wrappedGrpc))+}++func recoverMiddleware(next echo.HandlerFunc) echo.HandlerFunc {+ return func(c echo.Context) error {+ defer func() {+ if r := recover(); r != nil {+ err, ok := r.(error)+ if !ok {+ err = errors.Errorf("%v", r)+ }+ slog.Error("Middleware PANIC RECOVER", log.BBError(err), log.BBStack("panic-stack"))++ c.Error(err)+ }+ }()+ return next(c)+ }+}diff --git a/backend/server/server.go b/backend/server/server.goindex 9419e11040..526bf4bddf 100644--- a/backend/server/server.go+++ b/backend/server/server.go@@ -6,24 +6,14 @@ import ("fmt""log/slog""net"- "net/http""runtime"- "strings""sync""time"- // embed will embeds the acl policy.- _ "embed"-"github.com/google/uuid"grpcRuntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"- "github.com/improbable-eng/grpc-web/go/grpcweb"- "github.com/labstack/echo-contrib/pprof"- "github.com/labstack/echo-contrib/prometheus""github.com/labstack/echo/v4"- "github.com/labstack/echo/v4/middleware""github.com/pkg/errors"- "github.com/tmc/grpc-websocket-proxy/wsproxy""google.golang.org/grpc""google.golang.org/grpc/codes""google.golang.org/grpc/credentials/insecure"@@ -201,7 +191,6 @@ func NewServer(ctx context.Context, profile config.Profile) (*Server, error) {slog.Info(fmt.Sprintf("dataDir=%s", profile.DataDir))slog.Info(fmt.Sprintf("resourceDir=%s", profile.ResourceDir))slog.Info(fmt.Sprintf("readonly=%t", profile.Readonly))- slog.Info(fmt.Sprintf("debug=%t", profile.Debug))slog.Info(fmt.Sprintf("demoName=%s", profile.DemoName))slog.Info(fmt.Sprintf("backupStorageBackend=%s", profile.BackupStorageBackend))slog.Info(fmt.Sprintf("backupBucket=%s", profile.BackupBucket))@@ -284,6 +273,7 @@ func NewServer(ctx context.Context, profile config.Profile) (*Server, error) {return nil, err}}+ s.store = storeInstances.stateCfg = &state.State{InstanceDatabaseSyncChan: make(chan *store.InstanceMessage, 100),@@ -294,7 +284,6 @@ func NewServer(ctx context.Context, profile config.Profile) (*Server, error) {PlanCheckTickleChan: make(chan int, 1000),TaskRunTickleChan: make(chan int, 1000),}- s.store = storeInstanceif err := s.store.BackfillIssueTsVector(ctx); err != nil {slog.Warn("failed to backfill issue ts vector", log.BBError(err))@@ -335,40 +324,20 @@ func NewServer(ctx context.Context, profile config.Profile) (*Server, error) {s.activityManager = activity.NewManager(storeInstance)s.dbFactory = dbfactory.New(s.mysqlBinDir, s.mongoBinDir, s.pgBinDir, profile.DataDir, s.secret)- e := echo.New()- e.Debug = profile.Debug- e.HideBanner = true- e.HidePort = true- e.Use(recoverMiddleware)- grpcSkipper := func(c echo.Context) bool {- // Skip grpc and webhook calls.- return strings.HasPrefix(c.Request().URL.Path, "/bytebase.v1.") ||- strings.HasPrefix(c.Request().URL.Path, "/v1:adminExecute") ||- strings.HasPrefix(c.Request().URL.Path, webhookAPIPrefix)- }- e.Use(middleware.TimeoutWithConfig(middleware.TimeoutConfig{- Skipper: grpcSkipper,- Timeout: 30 * time.Second,- }))- e.Use(middleware.RateLimiterWithConfig(middleware.RateLimiterConfig{- Skipper: grpcSkipper,- Store: middleware.NewRateLimiterMemoryStoreWithConfig(- middleware.RateLimiterMemoryStoreConfig{Rate: 30, Burst: 60, ExpiresIn: 3 * time.Minute},- ),- IdentifierExtractor: func(ctx echo.Context) (string, error) {- id := ctx.RealIP()- return id, nil- },- ErrorHandler: func(context echo.Context, err error) error {- return context.JSON(http.StatusForbidden, nil)- },- DenyHandler: func(context echo.Context, identifier string, err error) error {- return context.JSON(http.StatusTooManyRequests, nil)- },- }))-- embedFrontend(e)- s.e = e++ // Configure echo server.+ s.e = echo.New()++ webhookGroup := s.e.Group(webhookAPIPrefix)+ s.registerWebhookRoutes(webhookGroup)+ apiGroup := s.e.Group(internalAPIPrefix)+ s.registerDatabaseRoutes(apiGroup)+ s.registerIssueRoutes(apiGroup)++ // Note: the gateway response modifier takes the external url on server startup. If the external URL is changed,+ // the user has to restart the server to take the latest value.+ gatewayModifier := auth.GatewayResponseModifier{ExternalURL: externalURL, TokenDuration: tokenDuration}+ mux := grpcRuntime.NewServeMux(grpcRuntime.WithForwardResponseOption(gatewayModifier.Modify))if profile.BackupBucket != "" {credentials, err := bbs3.GetCredentialsFromFile(ctx, profile.BackupCredentialFile)@@ -426,20 +395,6 @@ func NewServer(ctx context.Context, profile config.Profile) (*Server, error) {s.initMetricReporter()}- webhookGroup := e.Group(webhookAPIPrefix)- s.registerWebhookRoutes(webhookGroup)-- apiGroup := e.Group(internalAPIPrefix)- s.registerDatabaseRoutes(apiGroup)- s.registerIssueRoutes(apiGroup)- s.registerIssueSubscriberRoutes(apiGroup)- s.registerTaskRoutes(apiGroup)-- // Register healthz endpoint.- e.GET("/healthz", func(c echo.Context) error {- return c.String(http.StatusOK, "OK")- })-// Setup the gRPC and grpc-gateway.authProvider := auth.New(s.store, s.secret, tokenDuration, s.licenseService, profile.Mode)aclProvider := v1.NewACLInterceptor(s.store, s.secret, s.licenseService, profile.Mode)@@ -472,6 +427,8 @@ func NewServer(ctx context.Context, profile config.Profile) (*Server, error) {recoveryStreamInterceptor,),)+ configureEchoRouters(s.e, s.grpcServer, mux)+v1pb.RegisterAuthServiceServer(s.grpcServer, v1.NewAuthService(s.store, s.secret, tokenDuration, s.licenseService, s.metricReporter, &profile,func(ctx context.Context, user *store.UserMessage, firstEndUser bool) error {if s.profile.TestOnlySkipOnboardingData {@@ -532,10 +489,6 @@ func NewServer(ctx context.Context, profile config.Profile) (*Server, error) {return nil, err}- // Note: the gateway response modifier takes the external url on server startup. If the external URL is changed,- // the user has to restart the server to take the latest value.- gatewayModifier := auth.GatewayResponseModifier{ExternalURL: externalURL, TokenDuration: tokenDuration}- mux := grpcRuntime.NewServeMux(grpcRuntime.WithForwardResponseOption(gatewayModifier.Modify))if err := v1pb.RegisterAuthServiceHandler(ctx, mux, grpcConn); err != nil {return nil, err}@@ -599,32 +552,6 @@ func NewServer(ctx context.Context, profile config.Profile) (*Server, error) {if err := v1pb.RegisterInboxServiceHandler(ctx, mux, grpcConn); err != nil {return nil, err}- e.GET("/v1:adminExecute", echo.WrapHandler(wsproxy.WebsocketProxy(- mux,- wsproxy.WithTokenCookieName("access-token"),- // 10M.- wsproxy.WithMaxRespBodyBufferSize(10*1024*1024),- )))- e.Any("/v1/*", echo.WrapHandler(mux))- // GRPC web proxy.- options := []grpcweb.Option{- grpcweb.WithCorsForRegisteredEndpointsOnly(false),- grpcweb.WithOriginFunc(func(origin string) bool {- return true- }),- grpcweb.WithWebsockets(true),- grpcweb.WithWebsocketOriginFunc(func(req *http.Request) bool {- return true- }),- }- wrappedGrpc := grpcweb.WrapServer(s.grpcServer, options...)- e.Any("/bytebase.v1.*", echo.WrapHandler(wrappedGrpc))-- // Register pprof endpoints.- pprof.Register(e)- // Register prometheus metrics endpoint.- p := prometheus.NewPrometheus("api", nil)- p.Use(e)serverStarted = truereturn s, nildiff --git a/backend/server/webhook.go b/backend/server/webhook.goindex 4b4c2c7d25..0ecffaad1b 100644--- a/backend/server/webhook.go+++ b/backend/server/webhook.go@@ -1591,14 +1591,14 @@ func (s *Server) createIssueFromMigrationDetailsV2(ctx context.Context, project},})if err != nil {- return errors.Wrapf(err, "failed to create plan for sample project")+ return errors.Wrapf(err, "failed to create plan")}rollout, err := s.rolloutService.CreateRollout(childCtx, &v1pb.CreateRolloutRequest{Parent: fmt.Sprintf("projects/%s", project.ResourceID),Plan: plan.Name,})if err != nil {- return errors.Wrapf(err, "failed to create rollout for sample project")+ return errors.Wrapf(err, "failed to create rollout")}issue, err := s.issueService.CreateIssue(childCtx, &v1pb.CreateIssueRequest{Parent: fmt.Sprintf("projects/%s", project.ResourceID),@@ -1612,7 +1612,7 @@ func (s *Server) createIssueFromMigrationDetailsV2(ctx context.Context, project},})if err != nil {- return errors.Wrapf(err, "failed to create issue for sample project")+ return errors.Wrapf(err, "failed to create issue")}issueUID, err := strconv.Atoi(issue.Uid)if err != nil {@@ -2154,6 +2154,45 @@ func (s *Server) tryUpdateTasksFromModifiedFile(ctx context.Context, databases [return nil}+// patchTask patches the statement for a task.+func patchTask(ctx context.Context, stores *store.Store, activityManager *activity.Manager, task *store.TaskMessage, taskPatch *api.TaskPatch, issue *store.IssueMessage) error {+ taskPatched, err := stores.UpdateTaskV2(ctx, taskPatch)+ if err != nil {+ return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to update task \"%v\"", task.Name)).SetInternal(err)+ }+ if taskPatch.SheetID != nil {+ oldSheetID, err := utils.GetTaskSheetID(task.Payload)+ if err != nil {+ return errors.Wrap(err, "failed to get old sheet ID")+ }+ newSheetID := *taskPatch.SheetID++ // create a task sheet update activity+ payload, err := json.Marshal(api.ActivityPipelineTaskStatementUpdatePayload{+ TaskID: taskPatched.ID,+ OldSheetID: oldSheetID,+ NewSheetID: newSheetID,+ TaskName: task.Name,+ IssueName: issue.Title,+ })+ if err != nil {+ return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create activity after updating task sheet: %v", taskPatched.Name).SetInternal(err)+ }+ if _, err := activityManager.CreateActivity(ctx, &store.ActivityMessage{+ CreatorUID: taskPatch.UpdaterID,+ ContainerUID: taskPatched.PipelineID,+ Type: api.ActivityPipelineTaskStatementUpdate,+ Payload: string(payload),+ Level: api.ActivityInfo,+ }, &activity.Metadata{+ Issue: issue,+ }); err != nil {+ return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to create activity after updating task statement: %v", taskPatched.Name)).SetInternal(err)+ }+ }+ return nil+}+// convertSQLAdviceToGitLabCIResult will convert SQL advice map to GitLab test output format.// GitLab test report: https://docs.gitlab.com/ee/ci/testing/unit_test_reports.html// junit XML format: https://llg.cubic.org/docs/junit/diff --git a/backend/tests/rollout.go b/backend/tests/rollout.goindex f7a737517e..f2f7aee8f1 100644--- a/backend/tests/rollout.go+++ b/backend/tests/rollout.go@@ -70,7 +70,7 @@ func (ctl *controller) changeDatabaseWithConfig(ctx context.Context, project *v1// waitRollout waits for pipeline to finish and approves tasks when necessary.func (ctl *controller) waitRollout(ctx context.Context, issueName, rolloutName string) error {- ticker := time.NewTicker(100 * time.Millisecond)+ ticker := time.NewTicker(300 * time.Millisecond)defer ticker.Stop()for range ticker.C {