Skip to content

feat(metrics): Add histogram of mirror sync steps by labels user/repo/step#38153

Open
rremer wants to merge 1 commit into
go-gitea:mainfrom
rremer:mirror-sync-metrics
Open

feat(metrics): Add histogram of mirror sync steps by labels user/repo/step#38153
rremer wants to merge 1 commit into
go-gitea:mainfrom
rremer:mirror-sync-metrics

Conversation

@rremer

@rremer rremer commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

I had need of some visibility into mirror sync timings, so this adds a prometheus histogram for each of the mirror_pull steps as well as a general success/failure and total time. They are labelled by user/repository so folks can drill down into which repos might be taking longer.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jun 17, 2026
@github-actions github-actions Bot added the docs-update-needed The document needs to be updated synchronously label Jun 17, 2026
@rremer rremer force-pushed the mirror-sync-metrics branch from ddca78f to fe4c52d Compare June 19, 2026 22:38
@rremer rremer changed the title Add histogram of mirror sync steps by labels user/repo/step feat(metrics) Add histogram of mirror sync steps by labels user/repo/step Jun 19, 2026
@rremer rremer changed the title feat(metrics) Add histogram of mirror sync steps by labels user/repo/step feat(metrics): Add histogram of mirror sync steps by labels user/repo/step Jun 19, 2026
@github-actions github-actions Bot added the type/feature Completely new functionality. Can only be merged if feature freeze is not active. label Jun 19, 2026
Signed-off-by: Royce Remer <royceremer@gmail.com>
Assisted-by: Claude Opus 4.6

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Prometheus instrumentation for pull-mirror synchronization to improve visibility into where time is spent per mirror sync run, with per-step timing and overall success/failure labeling.

Changes:

  • Instrument runSync with per-step and total duration observations.
  • Add new Prometheus metrics (duration histogram + completion status metric) and corresponding unit tests.
  • Introduce a new metrics config toggle (ENABLED_MIRROR_SYNC_DURATION) and document it in the example config.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
services/mirror/mirror_pull.go Adds timing probes around mirror sync steps and records overall completion status.
services/mirror/mirror_pull_metrics.go Introduces new Prometheus metric definitions and recording helpers for mirror sync instrumentation.
services/mirror/mirror_pull_metrics_test.go Adds unit tests validating metric recording and config gating behavior.
modules/setting/metrics.go Adds a new metrics toggle to the global metrics settings struct and defaults.
go.mod Promotes github.com/prometheus/client_model to a direct dependency for tests.
custom/conf/app.example.ini Documents the new ENABLED_MIRROR_SYNC_DURATION setting in the example config.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +38 to +44
var mirrorSyncStatus = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "gitea",
Subsystem: "mirror",
Name: "sync_status",
Help: "Count of mirror pull sync completions, labeled by success/failure.",
Buckets: []float64{0, 1},
}, []string{"owner", "repo", "success"})
Comment on lines +30 to +36
var mirrorSyncDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "gitea",
Subsystem: "mirror",
Name: "sync_duration_ms",
Help: "Duration in milliseconds of mirror pull sync steps.",
Buckets: []float64{5, 1000, 5000, 10000, 30000, 60000, 300000},
}, []string{"owner", "repo", "step"})
Comment on lines +8 to +18
Enabled bool
Token string
EnabledIssueByLabel bool
EnabledIssueByRepository bool
EnabledMirrorSyncDuration bool
}{
Enabled: false,
Token: "",
EnabledIssueByLabel: false,
EnabledIssueByRepository: false,
Enabled: false,
Token: "",
EnabledIssueByLabel: false,
EnabledIssueByRepository: false,
EnabledMirrorSyncDuration: true,
Comment on lines +2710 to +2711
;; Enable mirror sync duration metrics; default is true
;ENABLED_MIRROR_SYNC_DURATION = true
Comment on lines +49 to +50
setting.Metrics.Enabled = false
setting.Metrics.EnabledMirrorSyncDuration = true
Comment on lines +93 to +94
setting.Metrics.Enabled = true
setting.Metrics.EnabledMirrorSyncDuration = true
Comment on lines +119 to +120
setting.Metrics.Enabled = true
setting.Metrics.EnabledMirrorSyncDuration = true
Comment on lines +131 to +132
setting.Metrics.Enabled = true
setting.Metrics.EnabledMirrorSyncDuration = true
Comment on lines +143 to +144
setting.Metrics.Enabled = true
setting.Metrics.EnabledMirrorSyncDuration = true
Comment on lines +159 to +160
setting.Metrics.Enabled = false
setting.Metrics.EnabledMirrorSyncDuration = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-update-needed The document needs to be updated synchronously lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. type/feature Completely new functionality. Can only be merged if feature freeze is not active.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants