Skip to content

refactor: drop MetricsConfig from ToolchainStatus type#1245

Merged
xcoulon merged 6 commits into
codeready-toolchain:masterfrom
xcoulon:toolchain_status_metrics_api_drop
Mar 6, 2026
Merged

refactor: drop MetricsConfig from ToolchainStatus type#1245
xcoulon merged 6 commits into
codeready-toolchain:masterfrom
xcoulon:toolchain_status_metrics_api_drop

Conversation

@xcoulon
Copy link
Copy Markdown
Contributor

@xcoulon xcoulon commented Mar 4, 2026

also, remove all calls to ForceSynchronization() from the tests

see also:

and also:

Signed-off-by: Xavier Coulon xcoulon@redhat.com

Summary by CodeRabbit

  • Bug Fixes

    • Removed metrics-related configuration from host operator config and eliminated related status/printer fields.
  • Chores

    • Simplified cluster status by removing spaceCount and metrics entries from member status.
    • Removed obsolete metrics accessor and related configuration surface.
  • Tests

    • Updated tests to use map-based metric representations and removed redundant metrics-focused test cases.

also, remove all calls to `ForceSynchronization()` from the tests

Signed-off-by: Xavier Coulon <xcoulon@redhat.com>
@openshift-ci openshift-ci Bot requested review from fbm3307 and metlos March 4, 2026 13:47
@openshift-ci openshift-ci Bot added the approved label Mar 4, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 4, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8f74d555-da91-4479-bab8-b54f3480dc6d

📥 Commits

Reviewing files that changed from the base of the PR and between d16171b and c5942af.

📒 Files selected for processing (1)
  • controllers/masteruserrecord/masteruserrecord_controller_test.go

Walkthrough

Removed metrics fields from CRDs and the ToolchainConfig metrics API, updated tests to use map[string]int for metric assertions and removed related test cases, and bumped internal toolchain module versions in go.mod.

Changes

Cohort / File(s) Summary
CRD Schema Updates
config/crd/bases/toolchain.dev.openshift.com_toolchainconfigs.yaml, config/crd/bases/toolchain.dev.openshift.com_toolchainstatuses.yaml
Deleted spec.host.metrics from ToolchainConfig; removed status.members[].spaceCount and status.members[].metrics, and removed a MUR printer column from ToolchainStatus.
Configuration API Removal
controllers/toolchainconfig/configuration.go, controllers/toolchainconfig/configuration_test.go
Removed ToolchainConfig.Metrics() accessor, the MetricsConfig type and its ForceSynchronization() method; removed TestMetrics subtests that validated metrics ForceSynchronization behavior.
Test Assertion & Helpers
test/metrics/metrics.go, pkg/metrics/metrics_test.go, controllers/masteruserrecord/.../masteruserrecord_controller_test.go, controllers/usersignup/.../usersignup_controller_test.go
Changed metric matcher signatures and expectations to accept map[string]int instead of toolchainv1alpha1.Metric; updated numerous test assertions and removed explicit test-side ForceSynchronization config usage (tests now rely on default ToolchainConfig).
Dependency Update
go.mod
Updated required versions of github.com/codeready-toolchain/api and github.com/codeready-toolchain/toolchain-common.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.35% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective of the pull request - removing MetricsConfig from the ToolchainStatus type, which is clearly reflected in the CRD changes and controller modifications throughout the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
test/metrics/metrics.go (1)

37-40: Validate activation/domain key format before calling WithLabelValues.

Using strings.Split(key, ",")... can pass an invalid label count and panic, which obscures the test failure cause. Parse and validate the composite key before asserting the gauge.

Suggested patch
 func (a *MetricAssertion) HaveUsersPerActivationsAndDomain(expected map[string]int) *MetricAssertion {
 	for key, count := range expected {
-		metricscommontest.AssertMetricsGaugeEquals(a.t, count, metrics.UserSignupsPerActivationAndDomainGaugeVec.WithLabelValues(strings.Split(key, ",")...), "invalid gauge value for key '%v'", key)
+		activation, domain, found := strings.Cut(key, ",")
+		require.Truef(a.t, found && activation != "" && domain != "" && !strings.Contains(domain, ","), "invalid key format '%s': expected '<activation>,<domain>'", key)
+		metricscommontest.AssertMetricsGaugeEquals(a.t, count, metrics.UserSignupsPerActivationAndDomainGaugeVec.WithLabelValues(activation, domain), "invalid gauge value for key '%v'", key)
 	}
 	return a
 }

As per coding guidelines, "Focus on major issues impacting performance, readability, maintainability and security. Avoid nitpicks and avoid verbosity."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/metrics/metrics.go` around lines 37 - 40, In
HaveUsersPerActivationsAndDomain, validate and parse the composite key before
calling metrics.UserSignupsPerActivationAndDomainGaugeVec.WithLabelValues: split
the key using strings.SplitN(key, ",", 2), trim spaces, ensure you get the exact
number of labels expected (e.g., 2 parts: activation and domain), and if not,
call a test failure (t.Fatalf/t.Errorf) with a clear message referencing the
offending key; only then pass the validated parts to WithLabelValues and call
metricscommontest.AssertMetricsGaugeEquals.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@go.mod`:
- Line 6: The go.mod currently pins a personal-fork or PR ref (e.g., the module
line "github.com/codeready-toolchain/toolchain-common
v0.0.0-20260225205316-85e4bef507f2" and associated replace directives
referencing refs/pull/500/head and refs/pull/520/head) which ties the build to
open upstream PR commits; remove or replace these temporary replace directives
and module pins with either the canonical released module version or wait and
update to the upstream PR merge commit, or explicitly document these
replacements as development-only in a comment and developer-facing README;
ensure any replace lines referencing those PR refs are reverted so CI/builds do
not depend on unstable PR refs.

---

Nitpick comments:
In `@test/metrics/metrics.go`:
- Around line 37-40: In HaveUsersPerActivationsAndDomain, validate and parse the
composite key before calling
metrics.UserSignupsPerActivationAndDomainGaugeVec.WithLabelValues: split the key
using strings.SplitN(key, ",", 2), trim spaces, ensure you get the exact number
of labels expected (e.g., 2 parts: activation and domain), and if not, call a
test failure (t.Fatalf/t.Errorf) with a clear message referencing the offending
key; only then pass the validated parts to WithLabelValues and call
metricscommontest.AssertMetricsGaugeEquals.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bdc6fa97-a780-4436-b98f-1d6b25ffd99d

📥 Commits

Reviewing files that changed from the base of the PR and between 0c289d8 and 7c9731b.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (9)
  • config/crd/bases/toolchain.dev.openshift.com_toolchainconfigs.yaml
  • config/crd/bases/toolchain.dev.openshift.com_toolchainstatuses.yaml
  • controllers/masteruserrecord/masteruserrecord_controller_test.go
  • controllers/toolchainconfig/configuration.go
  • controllers/toolchainconfig/configuration_test.go
  • controllers/usersignup/usersignup_controller_test.go
  • go.mod
  • pkg/metrics/metrics_test.go
  • test/metrics/metrics.go
💤 Files with no reviewable changes (4)
  • controllers/toolchainconfig/configuration_test.go
  • controllers/toolchainconfig/configuration.go
  • config/crd/bases/toolchain.dev.openshift.com_toolchainstatuses.yaml
  • config/crd/bases/toolchain.dev.openshift.com_toolchainconfigs.yaml

Comment thread go.mod Outdated
mfrancisc and others added 2 commits March 5, 2026 13:09
Comment thread controllers/masteruserrecord/masteruserrecord_controller_test.go Outdated
@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented Mar 5, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: MatousJobanek, rajivnathan, xcoulon

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [MatousJobanek,rajivnathan,xcoulon]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
controllers/masteruserrecord/masteruserrecord_controller_test.go (1)

289-292: ⚠️ Potential issue | 🟠 Major

Fix gofmt failure at Line 289 before merge.

Line 289 indentation is not gofmt-compliant, and CI is already failing on this exact line.

Proposed formatting fix
-mur := murtest.NewMasterUserRecord(t, "john",
+	mur := murtest.NewMasterUserRecord(t, "john",
 		murtest.WithOwnerLabel("john-123"),
 		murtest.StatusUserAccount(commontest.MemberClusterName),
 		murtest.Finalizer("finalizer.toolchain.dev.openshift.com"))
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@controllers/masteruserrecord/masteruserrecord_controller_test.go` around
lines 289 - 292, The test instantiation of mur :=
murtest.NewMasterUserRecord(...) is misindented causing gofmt to fail; reformat
the call so the continuation lines are aligned (each argument indented with a
tab) or simply run gofmt/gofmt -w on the file to fix indentation for the
NewMasterUserRecord call and its option lines (murtest.WithOwnerLabel,
murtest.StatusUserAccount, murtest.Finalizer) so the arguments line up correctly
under murtest.NewMasterUserRecord.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@controllers/masteruserrecord/masteruserrecord_controller_test.go`:
- Around line 289-292: The test instantiation of mur :=
murtest.NewMasterUserRecord(...) is misindented causing gofmt to fail; reformat
the call so the continuation lines are aligned (each argument indented with a
tab) or simply run gofmt/gofmt -w on the file to fix indentation for the
NewMasterUserRecord call and its option lines (murtest.WithOwnerLabel,
murtest.StatusUserAccount, murtest.Finalizer) so the arguments line up correctly
under murtest.NewMasterUserRecord.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cb74ba0a-970e-4c4a-b632-06c574697a7b

📥 Commits

Reviewing files that changed from the base of the PR and between feae5c2 and d16171b.

📒 Files selected for processing (1)
  • controllers/masteruserrecord/masteruserrecord_controller_test.go

Signed-off-by: Xavier Coulon <xcoulon@redhat.com>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Mar 6, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
36.6% Duplication on New Code (required ≤ 30%)

See analysis details on SonarQube Cloud

@xcoulon xcoulon merged commit 0d678eb into codeready-toolchain:master Mar 6, 2026
10 of 11 checks passed
@xcoulon xcoulon deleted the toolchain_status_metrics_api_drop branch March 6, 2026 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants