feat(metrics): add tests for GitHub organization and team metrics; defer metric updates in controllers#90
Open
onuryilmaz wants to merge 1 commit intomainfrom
Open
feat(metrics): add tests for GitHub organization and team metrics; defer metric updates in controllers#90onuryilmaz wants to merge 1 commit intomainfrom
onuryilmaz wants to merge 1 commit intomainfrom
Conversation
…fer metric updates in controllers
Contributor
There was a problem hiding this comment.
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/metricsunit 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-testto 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
githubOrganizationis allocated beforeGet()and never cleared onGet()errors (including NotFound), the deferredSetGithubOrganizationMetrics(githubOrganization)will run on an empty object. That can create/overwrite Prometheus series with emptygithub/organizationlabel values. Consider settinggithubOrganization = nilbefore returning onGet()errors, or only assigning the pointer after a successfulGet()(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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.