Skip to content

Commit

Permalink
feat(metrics): add migration counters
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFox0x7 committed Jan 16, 2025
1 parent 2b51415 commit bf12d56
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions services/migrations/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ import (
base "code.gitea.io/gitea/modules/migration"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)

var (
repoMigrationsInflightGauge = promauto.NewGauge(prometheus.GaugeOpts{Namespace: "gitea", Subsystem: "repository", Name: "inflight_migrations", Help: "Number of inflight repository migrations"})
repoMigrationsCounter = promauto.NewGaugeVec(prometheus.GaugeOpts{Namespace: "gitea", Subsystem: "repository", Name: "migrations", Help: "Total migrations"}, []string{"result"})
)

// MigrateOptions is equal to base.MigrateOptions
Expand Down Expand Up @@ -124,6 +132,9 @@ func MigrateRepository(ctx context.Context, doer *user_model.User, ownerName str
return nil, err
}

repoMigrationsInflightGauge.Inc()
defer repoMigrationsInflightGauge.Dec()

uploader := NewGiteaLocalUploader(ctx, doer, ownerName, opts.RepoName)
uploader.gitServiceType = opts.GitServiceType

Expand All @@ -134,8 +145,10 @@ func MigrateRepository(ctx context.Context, doer *user_model.User, ownerName str
if err2 := system_model.CreateRepositoryNotice(fmt.Sprintf("Migrate repository from %s failed: %v", opts.OriginalURL, err)); err2 != nil {
log.Error("create respotiry notice failed: ", err2)
}
repoMigrationsCounter.WithLabelValues("fail").Inc()
return nil, err
}
repoMigrationsCounter.WithLabelValues("success").Inc()
return uploader.repo, nil
}

Expand Down

0 comments on commit bf12d56

Please sign in to comment.