Skip to content

Commit

Permalink
Count git checkout failures (argoproj#15657)
Browse files Browse the repository at this point in the history
Signed-off-by: Mikołaj Przybysz <[email protected]>
Co-authored-by: Mikołaj Przybysz <[email protected]>
Co-authored-by: Blake Pettersson <[email protected]>
  • Loading branch information
3 people authored and mkieweg committed Jun 11, 2024
1 parent a00fdb4 commit 51170fb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/operator-manual/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Scraped at the `argocd-repo-server:8084/metrics` endpoint.
|--------|:----:|-------------|
| `argocd_git_request_duration_seconds` | histogram | Git requests duration seconds. |
| `argocd_git_request_total` | counter | Number of git requests performed by repo server |
| `argocd_git_fetch_fail_total` | counter | Number of git fetch requests failures by repo server |
| `argocd_redis_request_duration_seconds` | histogram | Redis requests duration seconds. |
| `argocd_redis_request_total` | counter | Number of Kubernetes requests executed during application reconciliation. |
| `argocd_repo_pending_request_total` | gauge | Number of pending requests requiring repository lock |
Expand Down
15 changes: 15 additions & 0 deletions reposerver/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

type MetricsServer struct {
handler http.Handler
gitFetchFailCounter *prometheus.CounterVec
gitRequestCounter *prometheus.CounterVec
gitRequestHistogram *prometheus.HistogramVec
repoPendingRequestsGauge *prometheus.GaugeVec
Expand All @@ -32,6 +33,15 @@ func NewMetricsServer() *MetricsServer {
registry.MustRegister(collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}))
registry.MustRegister(collectors.NewGoCollector())

gitFetchFailCounter := prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "argocd_git_fetch_fail_total",
Help: "Number of git fetch requests failures by repo server",
},
[]string{"repo", "revision"},
)
registry.MustRegister(gitFetchFailCounter)

gitRequestCounter := prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "argocd_git_request_total",
Expand Down Expand Up @@ -81,6 +91,7 @@ func NewMetricsServer() *MetricsServer {

return &MetricsServer{
handler: promhttp.HandlerFor(registry, promhttp.HandlerOpts{}),
gitFetchFailCounter: gitFetchFailCounter,
gitRequestCounter: gitRequestCounter,
gitRequestHistogram: gitRequestHistogram,
repoPendingRequestsGauge: repoPendingRequestsGauge,
Expand All @@ -93,6 +104,10 @@ func (m *MetricsServer) GetHandler() http.Handler {
return m.handler
}

func (m *MetricsServer) IncGitFetchFail(repo string, revision string) {
m.gitFetchFailCounter.WithLabelValues(repo, revision).Inc()
}

// IncGitRequest increments the git requests counter
func (m *MetricsServer) IncGitRequest(repo string, requestType GitRequestType) {
m.gitRequestCounter.WithLabelValues(repo, string(requestType)).Inc()
Expand Down
6 changes: 5 additions & 1 deletion reposerver/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -2397,7 +2397,11 @@ func directoryPermissionInitializer(rootPath string) goio.Closer {
// nolint:unparam
func (s *Service) checkoutRevision(gitClient git.Client, revision string, submoduleEnabled bool) (goio.Closer, error) {
closer := s.gitRepoInitializer(gitClient.Root())
return closer, checkoutRevision(gitClient, revision, submoduleEnabled)
err := checkoutRevision(gitClient, revision, submoduleEnabled)
if err != nil {
s.metricsServer.IncGitFetchFail(gitClient.Root(), revision)
}
return closer, err
}

func checkoutRevision(gitClient git.Client, revision string, submoduleEnabled bool) error {
Expand Down

0 comments on commit 51170fb

Please sign in to comment.