feat(metrics): Add histogram of mirror sync steps by labels user/repo/step#38153
Open
rremer wants to merge 1 commit into
Open
feat(metrics): Add histogram of mirror sync steps by labels user/repo/step#38153rremer wants to merge 1 commit into
rremer wants to merge 1 commit into
Conversation
ddca78f to
fe4c52d
Compare
Signed-off-by: Royce Remer <royceremer@gmail.com> Assisted-by: Claude Opus 4.6
fe4c52d to
56af4b9
Compare
Contributor
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.
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.