Skip to content
Snippets Groups Projects
Commit df0be2c4 authored by Jacob Vosmaer (GitLab)'s avatar Jacob Vosmaer (GitLab)
Browse files

Add git archive cache hit/miss counter

parent eacd5b7a
No related branches found
No related tags found
1 merge request!163Prometheus metrics for senddata and git archive cache
Loading
Loading
@@ -19,6 +19,8 @@ import (
 
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/senddata"
"github.com/prometheus/client_golang/prometheus"
)
 
type archive struct{ senddata.Prefix }
Loading
Loading
@@ -29,7 +31,20 @@ type archiveParams struct {
CommitId string
}
 
var SendArchive = &archive{"git-archive:"}
var (
SendArchive = &archive{"git-archive:"}
gitArchiveCache = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "gitlab_workhorse_git_archive_cache",
Help: "Cache hits and misses for 'git archive' streaming",
},
[]string{"result"},
)
)
func init() {
prometheus.MustRegister(gitArchiveCache)
}
 
func (a *archive) Inject(w http.ResponseWriter, r *http.Request, sendData string) {
var params archiveParams
Loading
Loading
@@ -50,6 +65,7 @@ func (a *archive) Inject(w http.ResponseWriter, r *http.Request, sendData string
 
if cachedArchive, err := os.Open(params.ArchivePath); err == nil {
defer cachedArchive.Close()
gitArchiveCache.WithLabelValues("hit").Inc()
log.Printf("Serving cached file %q", params.ArchivePath)
setArchiveHeaders(w, format, archiveFilename)
// Even if somebody deleted the cachedArchive from disk since we opened
Loading
Loading
@@ -59,6 +75,8 @@ func (a *archive) Inject(w http.ResponseWriter, r *http.Request, sendData string
return
}
 
gitArchiveCache.WithLabelValues("miss").Inc()
// We assume the tempFile has a unique name so that concurrent requests are
// safe. We create the tempfile in the same directory as the final cached
// archive we want to create so that we can use an atomic link(2) operation
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment