Skip to content

Commit

Permalink
Count git checkout failures
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikolaj Przybysz committed Sep 25, 2023
1 parent 129cf53 commit 1f69a9a
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 @@ -78,6 +78,7 @@ Scraped at the `argocd-repo-server:8084/metrics` endpoint.
| Metric | Type | Description |
|--------|:----:|-------------|
| `argocd_git_request_duration_seconds` | histogram | Git requests duration seconds. |
| `argocd_git_fetch_fail_total` | counter | Number of git fetch failures performed by repo server |
| `argocd_git_request_total` | counter | Number of git requests performed 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. |
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 @@ -2391,7 +2391,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 1f69a9a

Please sign in to comment.