From 2a7813929b3a4d17c2bc6aab09ae1a95a066b4de Mon Sep 17 00:00:00 2001 From: ahrav Date: Fri, 8 Dec 2023 09:50:09 -0800 Subject: [PATCH] add metrics for gitlab (#2190) --- pkg/sources/gitlab/gitlab.go | 5 +++++ pkg/sources/gitlab/metrics.go | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 pkg/sources/gitlab/metrics.go diff --git a/pkg/sources/gitlab/gitlab.go b/pkg/sources/gitlab/gitlab.go index 7851e7c6feef..54893cc0bb10 100644 --- a/pkg/sources/gitlab/gitlab.go +++ b/pkg/sources/gitlab/gitlab.go @@ -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 { @@ -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 } @@ -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 diff --git a/pkg/sources/gitlab/metrics.go b/pkg/sources/gitlab/metrics.go new file mode 100644 index 000000000000..9273682254e8 --- /dev/null +++ b/pkg/sources/gitlab/metrics.go @@ -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"}) +)