Skip to content

Commit

Permalink
Add commitsScanned metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
bill-rich committed Jul 24, 2023
1 parent 93c561f commit c862d72
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/sources/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,14 @@ type Git struct {
jobID int64
sourceMetadataFunc func(file, email, commit, timestamp, repository string, line int64) *source_metadatapb.MetaData
verify bool
metrics metrics
concurrency *semaphore.Weighted
}

type metrics struct {
commitsScanned map[string]struct{}
}

func NewGit(sourceType sourcespb.SourceType, jobID, sourceID int64, sourceName string, verify bool, concurrency int,
sourceMetadataFunc func(file, email, commit, timestamp, repository string, line int64) *source_metadatapb.MetaData,
) *Git {
Expand All @@ -65,6 +70,9 @@ func NewGit(sourceType sourcespb.SourceType, jobID, sourceID int64, sourceName s
sourceMetadataFunc: sourceMetadataFunc,
verify: verify,
concurrency: semaphore.NewWeighted(int64(concurrency)),
metrics: metrics{
commitsScanned: map[string]struct{}{},
},
}
}

Expand Down Expand Up @@ -339,6 +347,10 @@ func CloneRepoUsingSSH(ctx context.Context, gitUrl string, args ...string) (stri
return CloneRepo(ctx, userInfo, gitUrl, args...)
}

func (s *Git) CommitsScanned() map[string]struct{} {
return s.metrics.commitsScanned
}

func (s *Git) ScanCommits(ctx context.Context, repo *git.Repository, path string, scanOptions *ScanOptions, chunksChan chan *sources.Chunk) error {
if err := GitCmdCheck(); err != nil {
return err
Expand Down Expand Up @@ -371,6 +383,7 @@ func (s *Git) ScanCommits(ctx context.Context, repo *git.Repository, path string
break
}
depth++
s.metrics.commitsScanned[commit.Hash] = struct{}{}
logger.V(5).Info("scanning commit", "commit", commit.Hash)
for _, diff := range commit.Diffs {
if !scanOptions.Filter.Pass(diff.PathB) {
Expand Down

0 comments on commit c862d72

Please sign in to comment.