Skip to content

Find, verify, and analyze leaked credentials

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

Dustin Decker75e869faff2b
diff --git a/pkg/sources/github/metrics.go b/pkg/sources/github/metrics.go
index e6a1711fb..c552709ec 100644
--- a/pkg/sources/github/metrics.go
+++ b/pkg/sources/github/metrics.go
@@ -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"})
)
diff --git a/pkg/sources/github/repo.go b/pkg/sources/github/repo.go
index 901ab0f09..836cb1a23 100644
--- a/pkg/sources/github/repo.go
+++ b/pkg/sources/github/repo.go
@@ -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
}