Skip to content

Commit

Permalink
add metrics for gitlab (trufflesecurity#2190)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahrav authored Dec 8, 2023
1 parent 4b31b39 commit 2a78139
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/sources/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ func (s *Source) Chunks(ctx context.Context, chunksChan chan *sources.Chunk, _ .
if err != nil {
return errors.New(err)
}

gitlabReposScanned.WithLabelValues(s.name).Set(0)
// Get repo within target.
repos, errs := normalizeRepos(s.repos)
for _, repoErr := range errs {
Expand Down Expand Up @@ -409,6 +411,8 @@ func (s *Source) getReposFromGitlab(ctx context.Context, apiClient *gitlab.Clien
if len(repos) == 0 {
return nil, errors.Errorf("unable to discover any repos"), true
}

gitlabReposEnumerated.WithLabelValues(s.name).Set(float64(len(repos)))
return repos, nil, false
}

Expand Down Expand Up @@ -467,6 +471,7 @@ func (s *Source) scanRepos(ctx context.Context, chunksChan chan *sources.Chunk)
scanErrs.Add(err)
return nil
}
gitlabReposScanned.WithLabelValues(s.name).Inc()

logger.V(2).Info(fmt.Sprintf("Completed scanning repo %d/%d", i+1, len(s.repos)))
return nil
Expand Down
26 changes: 26 additions & 0 deletions pkg/sources/gitlab/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package gitlab

import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"

"github.com/trufflesecurity/trufflehog/v3/pkg/common"
)

var (
gitlabReposEnumerated = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: common.MetricsNamespace,
Subsystem: common.MetricsSubsystem,
Name: "gitlab_repos_enumerated",
Help: "Total number of Gitlab repositories enumerated.",
},
[]string{"source_name"})

gitlabReposScanned = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: common.MetricsNamespace,
Subsystem: common.MetricsSubsystem,
Name: "gitlab_repos_scanned",
Help: "Total number of Gitlab repositories scanned.",
},
[]string{"source_name"})
)

0 comments on commit 2a78139

Please sign in to comment.