Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this.

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
Loading