diff --git a/pkg/sources/github/metrics.go b/pkg/sources/github/metrics.go index e6a1711fb98d..c552709ecf09 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 901ab0f09bce..836cb1a238ce 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 }