Skip to content

Commit fc5d429

Browse files
authored
Merge pull request #65 from utilitywarehouse/as-metrics
clear metrics when repo is removed
2 parents eb1f7e4 + 0bc9c99 commit fc5d429

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

repository/metrics.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,23 @@ func updateMirrorLatency(repo string, start time.Time) {
9595
}
9696
mirrorLatency.WithLabelValues(repo).Observe(time.Since(start).Seconds())
9797
}
98+
99+
// deleteMetrics will remove all metrics corresponding to given repository
100+
func deleteMetrics(repo string) {
101+
// if metrics not enabled return
102+
if lastMirrorTimestamp == nil || mirrorCount == nil || mirrorLatency == nil {
103+
return
104+
}
105+
lastMirrorTimestamp.Delete(prometheus.Labels{
106+
"repo": repo,
107+
})
108+
mirrorCount.Delete(prometheus.Labels{
109+
"repo": repo, "success": "true",
110+
})
111+
mirrorCount.Delete(prometheus.Labels{
112+
"repo": repo, "success": "false",
113+
})
114+
mirrorLatency.Delete(prometheus.Labels{
115+
"repo": repo,
116+
})
117+
}

repository/repository.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ func (r *Repository) QueueMirrorRun() {
489489
func (r *Repository) StopLoop() {
490490
r.stop <- true
491491
<-r.stopped
492+
deleteMetrics(r.gitURL.Repo)
492493
r.log.Info("repository mirror loop stopped")
493494
}
494495

0 commit comments

Comments
 (0)