feat(metrics): Add histogram of mirror sync steps by labels user/repo/step#38153
feat(metrics): Add histogram of mirror sync steps by labels user/repo/step#38153rremer wants to merge 1 commit into
Conversation
ddca78f to
fe4c52d
Compare
fe4c52d to
56af4b9
Compare
There was a problem hiding this comment.
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
runSyncwith 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.
| 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"}) |
| 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"}) |
There was a problem hiding this comment.
I chose not to implement this suggestion since it would make the metric not very useful anymore. Even for my extremely large repositories, most steps take less than 5 seconds.
| 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, |
There was a problem hiding this comment.
sure, default disabled everything
| ;; Enable mirror sync duration metrics; default is true | ||
| ;ENABLED_MIRROR_SYNC_DURATION = true |
| setting.Metrics.Enabled = false | ||
| setting.Metrics.EnabledMirrorSyncDuration = true |
There was a problem hiding this comment.
a fair observation, although still not a threadsafe suggestion. I opted to just have a separate struct passed into the function, and by default it's constructed with the values from the global canfig, but in my tests I pass in special instances.
| setting.Metrics.Enabled = true | ||
| setting.Metrics.EnabledMirrorSyncDuration = true |
| setting.Metrics.Enabled = true | ||
| setting.Metrics.EnabledMirrorSyncDuration = true |
| setting.Metrics.Enabled = true | ||
| setting.Metrics.EnabledMirrorSyncDuration = true |
| setting.Metrics.Enabled = true | ||
| setting.Metrics.EnabledMirrorSyncDuration = true |
| setting.Metrics.Enabled = false | ||
| setting.Metrics.EnabledMirrorSyncDuration = true |
Signed-off-by: Royce Remer <royceremer@gmail.com> Assisted-by: Claude Opus 4.6
56af4b9 to
e0c02e8
Compare
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.