Skip to content

Commit

Permalink
Fix forks and repos counter, add metric for orgs enumerated
Browse files Browse the repository at this point in the history
  • Loading branch information
dustin-decker committed Nov 20, 2023
1 parent cd9c1ae commit e4c9c53
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
8 changes: 8 additions & 0 deletions pkg/sources/github/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@ var (
Help: "Total number of GitHub repositories scanned.",
},
[]string{"source_name"})

githubOrgsEnumerated = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: common.MetricsNamespace,
Subsystem: common.MetricsSubsystem,
Name: "github_orgs_enumerated",
Help: "Total number of GitHub organizations enumerated.",
},
[]string{"source_name"})
)
17 changes: 15 additions & 2 deletions pkg/sources/github/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ func (s *Source) processRepos(ctx context.Context, target string, listRepos repo
numRepos, numForks int
)

uniqueOrgs := map[string]struct{}{}

for {
someRepos, res, err := listRepos(ctx, target, listOpts)
if err == nil {
Expand All @@ -220,7 +222,16 @@ func (s *Source) processRepos(ctx context.Context, target string, listRepos repo
if r.GetFork() && !s.conn.IncludeForks {
continue
}
numForks++

if r.GetFork() {
numForks++
}

numRepos++

if r.GetOwner().GetType() == "Organization" {
uniqueOrgs[r.GetOwner().GetLogin()] = struct{}{}
}

repoName, repoURL := r.GetFullName(), r.GetCloneURL()
s.repoSizes.addRepo(repoURL, r.GetSize())
Expand All @@ -234,7 +245,9 @@ func (s *Source) processRepos(ctx context.Context, target string, listRepos repo
}
opts.Page = res.NextPage
}
logger.V(2).Info("found repos", "total", numRepos, "num_forks", numForks)

logger.V(2).Info("found repos", "total", numRepos, "num_forks", numForks, "num_orgs", len(uniqueOrgs))
githubOrgsEnumerated.WithLabelValues(s.name).Set(float64(len(uniqueOrgs)))

return nil
}
Expand Down

0 comments on commit e4c9c53

Please sign in to comment.