github.com/argoproj/argo-cd@v1.8.7/reposerver/metrics/gitwrapper.go (about) 1 package metrics 2 3 import ( 4 "time" 5 6 "github.com/argoproj/argo-cd/util/git" 7 ) 8 9 type gitClientWrapper struct { 10 repo string 11 client git.Client 12 metricsServer *MetricsServer 13 } 14 15 func WrapGitClient(repo string, metricsServer *MetricsServer, client git.Client) git.Client { 16 return &gitClientWrapper{repo: repo, client: client, metricsServer: metricsServer} 17 } 18 19 func (w *gitClientWrapper) Fetch() error { 20 startTime := time.Now() 21 w.metricsServer.IncGitRequest(w.repo, GitRequestTypeFetch) 22 defer w.metricsServer.ObserveGitRequestDuration(w.repo, GitRequestTypeFetch, time.Since(startTime)) 23 return w.client.Fetch() 24 } 25 26 func (w *gitClientWrapper) LsRemote(revision string) (string, error) { 27 startTime := time.Now() 28 sha, err := w.client.LsRemote(revision) 29 if sha != revision { 30 // This is true only if specified revision is a tag, branch or HEAD and client had to use 'ls-remote' 31 w.metricsServer.IncGitRequest(w.repo, GitRequestTypeLsRemote) 32 defer w.metricsServer.ObserveGitRequestDuration(w.repo, GitRequestTypeLsRemote, time.Since(startTime)) 33 } 34 return sha, err 35 } 36 37 func (w *gitClientWrapper) LsRefs() (*git.Refs, error) { 38 return w.client.LsRefs() 39 } 40 41 func (w *gitClientWrapper) LsFiles(path string) ([]string, error) { 42 return w.client.LsFiles(path) 43 } 44 45 func (w *gitClientWrapper) LsLargeFiles() ([]string, error) { 46 return w.client.LsLargeFiles() 47 } 48 49 func (w *gitClientWrapper) Checkout(revision string) error { 50 return w.client.Checkout(revision) 51 } 52 53 func (w *gitClientWrapper) CommitSHA() (string, error) { 54 return w.client.CommitSHA() 55 } 56 57 func (w *gitClientWrapper) Root() string { 58 return w.client.Root() 59 } 60 61 func (w *gitClientWrapper) Init() error { 62 return w.client.Init() 63 } 64 65 func (w *gitClientWrapper) RevisionMetadata(revision string) (*git.RevisionMetadata, error) { 66 return w.client.RevisionMetadata(revision) 67 } 68 69 func (w *gitClientWrapper) VerifyCommitSignature(revision string) (string, error) { 70 return w.client.VerifyCommitSignature(revision) 71 }