Skip to content

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

Log message cleanup

天舟6264698ee465
diff --git a/db/mysql.go b/db/mysql.go
index cddf3da73c..887029d9a3 100644
--- a/db/mysql.go
+++ b/db/mysql.go
@@ -107,7 +107,6 @@ func (driver *MySQLDriver) SyncSchema(ctx context.Context) ([]*DBSchema, error)
&table.DataSize,
&table.IndexSize,
); err != nil {
- driver.l.Info(fmt.Sprintf("%v", err))
return nil, err
}
diff --git a/server/jwt.go b/server/jwt.go
index 38cc68d21c..d70578f8b2 100644
--- a/server/jwt.go
+++ b/server/jwt.go
@@ -176,7 +176,6 @@ func JWTMiddleware(l *zap.Logger, p api.PrincipalService, next echo.HandlerFunc,
}
generateToken := time.Until(time.Unix(claims.ExpiresAt, 0)) < refreshThresholdDuration
- generateReason := "Token about to expire, generate new token..."
if err != nil {
var ve *jwt.ValidationError
if errors.As(err, &ve) {
@@ -185,7 +184,6 @@ func JWTMiddleware(l *zap.Logger, p api.PrincipalService, next echo.HandlerFunc,
if ve.Errors == jwt.ValidationErrorExpired {
err = nil
generateToken = true
- generateReason = "Token has expired, generate new token..."
}
}
}
@@ -248,7 +246,6 @@ func JWTMiddleware(l *zap.Logger, p api.PrincipalService, next echo.HandlerFunc,
// If we have a valid refresh token, we will generate new access token and refresh token
if refreshToken != nil && refreshToken.Valid {
- l.Info(generateReason)
if err := GenerateTokensAndSetCookies(c, user, mode, secret); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Server error to refresh expired token. User Id %d", principalId)).SetInternal(err)
}
diff --git a/server/project.go b/server/project.go
index ef151e3a74..a45bf40076 100644
--- a/server/project.go
+++ b/server/project.go
@@ -261,7 +261,7 @@ func (s *Server) registerProjectRoutes(g *echo.Group) {
// Just emits a warning since we have already updated the repository entry. We will have a separate process to reconcile the state.
if resp.StatusCode >= 300 {
- s.l.Error(("failed to update gitlab webhook when updating repository for project"),
+ s.l.Error(("Failed to update gitlab webhook when updating repository for project"),
zap.Int("status_code", resp.StatusCode),
zap.String("status", resp.Status),
zap.Int("project_id", projectId),
@@ -335,7 +335,7 @@ func (s *Server) registerProjectRoutes(g *echo.Group) {
// Just emits a warning since we have already removed the repository entry. We will have a separate process to cleanup the orphaned webhook.
if resp.StatusCode >= 300 {
- s.l.Error(("failed to delete gitlab webhook when unlinking repository from project"),
+ s.l.Error(("Failed to delete gitlab webhook when unlinking repository from project"),
zap.Int("status_code", resp.StatusCode),
zap.Int("project_id", projectId),
zap.Int("repository_id", repository.ID),
diff --git a/server/schema_syncer.go b/server/schema_syncer.go
index 46c6949942..05ab116f7c 100644
--- a/server/schema_syncer.go
+++ b/server/schema_syncer.go
@@ -45,13 +45,14 @@ func (s *SchemaSyncer) Run() error {
}
list, err := s.server.InstanceService.FindInstanceList(context.Background(), instanceFind)
if err != nil {
- s.l.Info(fmt.Sprintf("Failed to retrieve instances: %v\n", err))
+ s.l.Error("Failed to retrieve instances", zap.Error(err))
}
for _, instance := range list {
if err := s.server.ComposeInstanceAdminDataSource(context.Background(), instance); err != nil {
s.l.Error("Failed to sync instance",
- zap.String("instance_name", instance.Name),
+ zap.Int("id", instance.ID),
+ zap.String("name", instance.Name),
zap.String("error", err.Error()))
continue
}
@@ -59,7 +60,8 @@ func (s *SchemaSyncer) Run() error {
resultSet := s.server.SyncSchema(instance)
if resultSet.Error != "" {
s.l.Error("Failed to sync instance",
- zap.String("instance_name", instance.Name),
+ zap.Int("id", instance.ID),
+ zap.String("name", instance.Name),
zap.String("error", resultSet.Error))
}
}(instance)
diff --git a/server/task.go b/server/task.go
index 3ada6a87cc..1655858971 100644
--- a/server/task.go
+++ b/server/task.go
@@ -161,8 +161,8 @@ func (s *Server) ChangeTaskStatusWithPatch(ctx context.Context, task *api.Task,
defer func() {
if err != nil {
s.l.Error("Failed to change task status.",
- zap.Int("task_id", task.ID),
- zap.String("task_name", task.Name),
+ zap.Int("id", task.ID),
+ zap.String("name", task.Name),
zap.String("old_status", string(task.Status)),
zap.String("new_status", string(taskStatusPatch.Status)),
zap.Error(err))
@@ -246,9 +246,9 @@ func (s *Server) ChangeTaskStatusWithPatch(ctx context.Context, task *api.Task,
// Just emits an error instead of failing, since we have another periodic job to sync db info.
// Though the db will be assigned to the default project instead of the desired project in that case.
s.l.Error("failed to record database after creating database",
- zap.Error(err),
zap.String("database_name", payload.DatabaseName),
zap.Int("instance_id", task.InstanceId),
+ zap.Error(err),
)
}
}
diff --git a/server/task_executor_default.go b/server/task_executor_default.go
index db602852f1..28c0e2207f 100644
--- a/server/task_executor_default.go
+++ b/server/task_executor_default.go
@@ -18,7 +18,7 @@ type DefaultTaskExecutor struct {
}
func (exec *DefaultTaskExecutor) RunOnce(ctx context.Context, server *Server, task *api.Task) (terminated bool, err error) {
- exec.l.Info("Default task executor", zap.String("task", task.Name))
+ exec.l.Info("Run default task type", zap.String("task", task.Name))
return true, nil
}
diff --git a/server/task_scheduler.go b/server/task_scheduler.go
index 0eb8e44324..e7d9093b62 100644
--- a/server/task_scheduler.go
+++ b/server/task_scheduler.go
@@ -49,11 +49,15 @@ func (s *TaskScheduler) Run() error {
}
pipelineList, err := s.server.PipelineService.FindPipelineList(context.Background(), pipelineFind)
if err != nil {
- s.l.Error(fmt.Sprintf("Failed to retrieve open pipelines: %v\n", err))
+ s.l.Error("Failed to retrieve open pipelines", zap.Error(err))
}
for _, pipeline := range pipelineList {
if err := s.server.ComposePipelineRelationship(context.Background(), pipeline); err != nil {
- s.l.Error(fmt.Sprintf("Failed to fetch stage info for pipeline: %v. Error: %v", pipeline.Name, err))
+ s.l.Error("Failed to fetch pipeline relationship",
+ zap.Int("id", pipeline.ID),
+ zap.String("name", pipeline.Name),
+ zap.Error(err),
+ )
continue
}
@@ -63,7 +67,11 @@ func (s *TaskScheduler) Run() error {
if task.Status == api.TaskPending {
_, err = s.Schedule(context.Background(), task)
if err != nil {
- s.l.Error(fmt.Sprintf("Failed to schedule next running task: %v. Error: %v", task.Name, err))
+ s.l.Error("Failed to schedule next running task",
+ zap.Int("id", task.ID),
+ zap.String("name", task.Name),
+ zap.Error(err),
+ )
}
}
goto PIPELINE_END
@@ -80,20 +88,23 @@ func (s *TaskScheduler) Run() error {
}
taskList, err := s.server.TaskService.FindTaskList(context.Background(), taskFind)
if err != nil {
- s.l.Error(fmt.Sprintf("Failed to retrieve running tasks: %v\n", err))
+ s.l.Error("Failed to retrieve running tasks", zap.Error(err))
}
for _, task := range taskList {
executor, ok := s.executors[string(task.Type)]
if !ok {
- s.l.Error(fmt.Sprintf("Unknown task type: %v. Skip", task.Type))
+ s.l.Error("Skip running task with unknown type",
+ zap.Int("id", task.ID),
+ zap.String("name", task.Name),
+ zap.String("type", string(task.Type)),
+ )
continue
}
done, err := executor.RunOnce(context.Background(), s.server, task)
if done {
if err != nil {
- s.l.Info(fmt.Sprintf("Task failed '%v(%v)': %v\n", task.Name, task.ID, err))
taskStatusPatch := &api.TaskStatusPatch{
ID: task.ID,
UpdaterId: api.SYSTEM_BOT_ID,
@@ -104,13 +115,12 @@ func (s *TaskScheduler) Run() error {
continue
}
- s.l.Info(fmt.Sprintf("Task completed '%v(%v)'\n", task.Name, task.ID))
_, err = s.server.ChangeTaskStatus(context.Background(), task, api.TaskDone, api.SYSTEM_BOT_ID)
if err != nil {
s.l.Error("Failed to mark task as DONE",
+ zap.Int("id", task.ID),
+ zap.String("name", task.Name),
zap.Error(err),
- zap.Int("task_id", task.ID),
- zap.String("task_name", task.Name),
)
}
}
@@ -135,7 +145,6 @@ func (s *TaskScheduler) Register(taskType string, executor TaskExecutor) {
}
func (s *TaskScheduler) Schedule(ctx context.Context, task *api.Task) (*api.Task, error) {
- s.l.Info(fmt.Sprintf("Try to change task '%v(%v)' to RUNNING\n", task.Name, task.ID))
updatedTask, err := s.server.ChangeTaskStatus(ctx, task, api.TaskRunning, api.SYSTEM_BOT_ID)
if err != nil {
return nil, err
diff --git a/server/webhook.go b/server/webhook.go
index 6e4ad190f2..5add8164d9 100644
--- a/server/webhook.go
+++ b/server/webhook.go
@@ -37,7 +37,6 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
if err := json.Unmarshal(b, pushEvent); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted push event").SetInternal(err)
}
- s.l.Info((fmt.Sprintf("Push event: %+v", *pushEvent)))
// This shouldn't happen as we only setup webhook to receive push event, just in case.
if pushEvent.ObjectKind != gitlab.WebhookPush {
@@ -74,7 +73,7 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
if strings.HasPrefix(added, repository.BaseDirectory) && filepath.Ext(added) == ".sql" {
mi, err := db.ParseMigrationInfo(added, repository.BaseDirectory)
if err != nil {
- s.l.Warn("Invalid migration filename. Ignored", zap.Error(err))
+ s.l.Warn("Invalid migration filename. Skip", zap.String("file", added), zap.Error(err))
continue
}
@@ -85,13 +84,13 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
repository.VCS.AccessToken,
)
if err != nil {
- s.l.Warn("Failed to read file. Ignored", zap.String("file", added), zap.Error(err))
+ s.l.Warn("Failed to read added repository file. Skip", zap.String("file", added), zap.Error(err))
continue
}
b, err := io.ReadAll(resp.Body)
if err != nil {
- s.l.Warn("Failed to read file response. Ignored", zap.String("file", added), zap.Error(err))
+ s.l.Warn("Failed to read added repository file response. Skip", zap.String("file", added), zap.Error(err))
continue
}
@@ -102,11 +101,12 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
}
databaseList, err := s.ComposeDatabaseListByFind(context.Background(), databaseFind)
if err != nil {
- s.l.Warn("Failed to find database. Ignored", zap.String("file", added), zap.Error(err))
+ s.l.Warn("Failed to find database matching added repository file. Skip", zap.String("file", added), zap.Error(err))
continue
} else if len(databaseList) == 0 {
- s.l.Warn(fmt.Sprintf("Project ID %d does not contain database %s. Ignored", repository.ProjectId, mi.Database),
+ s.l.Warn(fmt.Sprintf("Project does not own database. Skip", repository.ProjectId, mi.Database),
zap.Int("project_id", repository.ProjectId),
+ zap.String("database_name", mi.Database),
zap.String("file", added),
)
continue
@@ -133,7 +133,7 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
}
}
if len(filterdDatabaseList) == 0 {
- s.l.Warn(fmt.Sprintf("Project ID %d does not contain database %s for environment %s. Ignored", repository.ProjectId, mi.Database, mi.Environment),
+ s.l.Warn(fmt.Sprintf("Project ID %d does not contain database %s for environment %s. Skip", repository.ProjectId, mi.Database, mi.Environment),
zap.Int("project_id", repository.ProjectId),
zap.String("environment", mi.Environment),
zap.String("file", added),
@@ -147,7 +147,7 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
// Compose the new issue
createdTime, err := time.Parse(time.RFC3339, commit.Timestamp)
if err != nil {
- s.l.Warn("Failed to parse timestamp. Ignored", zap.String("file", added), zap.Error(err))
+ s.l.Warn("Failed to parse timestamp. Skip", zap.String("file", added), zap.Error(err))
}
vcsPushEvent := api.VCSPushEvent{
VCSType: repository.VCS.Type,
@@ -201,7 +201,7 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
issue, err := s.CreateIssue(context.Background(), issueCreate, api.SYSTEM_BOT_ID)
if err != nil {
- s.l.Warn(fmt.Sprintf("Failed to create update schema task after adding %s", added), zap.Error(err),
+ s.l.Warn("Failed to create update schema task for added repository file", zap.Error(err),
zap.String("file", added))
continue
}
diff --git a/store/issue.go b/store/issue.go
index 1ce26c2cbe..f97c3839cc 100644
--- a/store/issue.go
+++ b/store/issue.go
@@ -172,7 +172,10 @@ func (s *IssueService) createIssue(ctx context.Context, tx *Tx, create *api.Issu
for _, item := range strings.Split(idList, ",") {
oneId, err := strconv.Atoi(item)
if err != nil {
- s.l.Error(fmt.Sprintf("Issue Id %d contains invalid subscriber id: %s", issue.ID, item))
+ s.l.Error("Issue contains invalid subscriber id",
+ zap.Int("issue_id", issue.ID),
+ zap.String("subscriber_id", item),
+ )
}
issue.SubscriberIdList = append(issue.SubscriberIdList, oneId)
}
@@ -261,7 +264,10 @@ func (s *IssueService) findIssueList(ctx context.Context, tx *Tx, find *api.Issu
for _, item := range strings.Split(idList, ",") {
oneId, err := strconv.Atoi(item)
if err != nil {
- s.l.Error(fmt.Sprintf("Issue Id %d contains invalid subscriber id: %s", issue.ID, item))
+ s.l.Error("Issue contains invalid subscriber id",
+ zap.Int("issue_id", issue.ID),
+ zap.String("subscriber_id", item),
+ )
}
issue.SubscriberIdList = append(issue.SubscriberIdList, oneId)
}
@@ -346,7 +352,10 @@ func (s *IssueService) patchIssue(ctx context.Context, tx *Tx, patch *api.IssueP
for _, item := range strings.Split(idList, ",") {
oneId, err := strconv.Atoi(item)
if err != nil {
- s.l.Error(fmt.Sprintf("Issue Id %d contains invalid subscriber id: %s", issue.ID, item))
+ s.l.Error("Issue contains invalid subscriber id",
+ zap.Int("issue_id", issue.ID),
+ zap.String("subscriber_id", item),
+ )
}
issue.SubscriberIdList = append(issue.SubscriberIdList, oneId)
}