Fix forks and repos counter, add metric for orgs enumerated (#2118)

This commit is contained in:
Dustin Decker 2023-11-21 08:52:33 -08:00 committed by GitHub
parent 62c628fb52
commit 75e869faff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 2 deletions

View file

@ -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"})
)

View file

@ -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 {
@ -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())
@ -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
}