Skip to content

feat(metrics): add tests for GitHub organization and team metrics; defer metric updates in controllers#90

Open
onuryilmaz wants to merge 1 commit intomainfrom
metrics-fix-2
Open

feat(metrics): add tests for GitHub organization and team metrics; defer metric updates in controllers#90
onuryilmaz wants to merge 1 commit intomainfrom
metrics-fix-2

Conversation

@onuryilmaz
Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI review requested due to automatic review settings May 5, 2026 11:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds unit tests for the Prometheus metrics emitted for GithubOrganization / GithubTeam resources and adjusts controller reconcile flows to rely more on deferred (“end of reconcile”) metrics updates.

Changes:

  • Add internal/metrics unit tests validating one-hot status gauges and operation counters for GitHub org/team resources.
  • Update controller reconcile logic to defer final metric updates instead of updating metrics at multiple intermediate points.
  • Extend make controller-test to run both controller and metrics package tests.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
Makefile Runs go test for internal/controller and internal/metrics in controller-test.
internal/metrics/metrics_test.go Adds tests for org/team status and operations metrics.
internal/controller/githubteam_controller.go Removes an intermediate metrics update (expects deferred update to cover final state).
internal/controller/githuborganization_controller.go Adds deferred final metrics update and removes intermediate updates.
go.mod Adds an indirect dependency (github.com/kylelemons/godebug).
Comments suppressed due to low confidence (1)

internal/controller/githuborganization_controller.go:84

  • Because githubOrganization is allocated before Get() and never cleared on Get() errors (including NotFound), the deferred SetGithubOrganizationMetrics(githubOrganization) will run on an empty object. That can create/overwrite Prometheus series with empty github/organization label values. Consider setting githubOrganization = nil before returning on Get() errors, or only assigning the pointer after a successful Get() (and guarding the defer accordingly).
	githubOrganization = &v1.GithubOrganization{}
	err = r.Get(ctx, req.NamespacedName, githubOrganization)
	if err != nil {
		if errors.IsNotFound(err) {
			// if not found -- skip

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 127 to +128
// reflect new status in metrics before proceeding
ghmetrics.SetGithubOrganizationMetrics(githubOrganization)
// (defer will also update it at the end)
Comment on lines 165 to +166
// reflect new status/operations in metrics
ghmetrics.SetGithubOrganizationMetrics(githubOrganization)
// (defer will also update it at the end)
return reconcile.Result{}, err
}
ghmetrics.SetGithubOrganizationMetrics(githubOrganization)
// (defer will also update it at the end)
Comment on lines 103 to +107
if err := r.Client.Status().Update(ctx, githubTeam); err != nil {
return reconcile.Result{}, err
}
// reflect new status in metrics before proceeding
ghmetrics.SetGithubTeamMetrics(githubTeam)
// (defer will also update it at the end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants