-
Notifications
You must be signed in to change notification settings - Fork 78
test(registration-service): expose metrics for the git commit #1269
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,14 @@ | ||
| ignored-vulnerabilities: [] | ||
| ignored-vulnerabilities: | ||
| # Incorrect parsing of IPv6 host literals in net/url | ||
| # Found in: net/url@go1.24.13 | ||
| # Fixed in: net/url@go1.25.8 | ||
| - id: GO-2026-4601 | ||
| info: https://pkg.go.dev/vuln/GO-2026-4601 | ||
| silence-until: 2026-04-23 | ||
| # FileInfo can escape from a Root in os | ||
| # Found in: os@go1.24.13 | ||
| # Fixed in: os@go1.25.8 | ||
| - id: GO-2026-4602 | ||
| info: https://pkg.go.dev/vuln/GO-2026-4602 | ||
| silence-until: 2026-04-23 | ||
|
|
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -32,18 +32,41 @@ | |||||||||||||||||||||||||||||
| awaitilities := WaitForDeployments(t) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| t.Run("host-operator", func(t *testing.T) { | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // given | ||||||||||||||||||||||||||||||
| hostAwait := awaitilities.Host() | ||||||||||||||||||||||||||||||
| // host metrics should be available at this point | ||||||||||||||||||||||||||||||
| hostAwait.InitMetrics(t, awaitilities.Member1().ClusterName, awaitilities.Member2().ClusterName) | ||||||||||||||||||||||||||||||
| _, err := hostAwait.WaitForRouteToBeAvailable(t, hostAwait.Namespace, "host-operator-metrics-service", "/metrics") | ||||||||||||||||||||||||||||||
|
Check failure on line 38 in test/metrics/metrics_test.go
|
||||||||||||||||||||||||||||||
| require.NoError(t, err) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // when | ||||||||||||||||||||||||||||||
| labels := hostAwait.GetMetricLabels(t, wait.HostOperatorVersionMetric) | ||||||||||||||||||||||||||||||
| t.Run("commit", func(t *testing.T) { | ||||||||||||||||||||||||||||||
| // when | ||||||||||||||||||||||||||||||
| labels := hostAwait.GetMetricLabels(t, hostAwait.MetricsURL, wait.HostOperatorCommitMetric) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // verify that the "version" metric exists for Host Operator and that it has a non-empty `commit` label | ||||||||||||||||||||||||||||||
| require.Len(t, labels, 1) | ||||||||||||||||||||||||||||||
| commit := labels[0]["commit"] | ||||||||||||||||||||||||||||||
| assert.Len(t, commit, 7) | ||||||||||||||||||||||||||||||
| // verify that the "version" metric exists for Host Operator and that it has a non-empty `commit` label | ||||||||||||||||||||||||||||||
| require.Len(t, labels, 1) | ||||||||||||||||||||||||||||||
| commit := labels[0]["commit"] | ||||||||||||||||||||||||||||||
| assert.Len(t, commit, len("e6a12a442a60dfd86d348a030ad2e789c79184b5")) // example value: 40 characters | ||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| t.Run("short commit", func(t *testing.T) { | ||||||||||||||||||||||||||||||
| // when | ||||||||||||||||||||||||||||||
| labels := hostAwait.GetMetricLabels(t, hostAwait.MetricsURL, wait.HostOperatorShortCommitMetric) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // verify that the "version" metric exists for Host Operator and that it has a non-empty `commit` label | ||||||||||||||||||||||||||||||
| require.Len(t, labels, 1) | ||||||||||||||||||||||||||||||
| commit := labels[0]["commit"] | ||||||||||||||||||||||||||||||
| assert.Len(t, commit, 7) | ||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| t.Run("version", func(t *testing.T) { | ||||||||||||||||||||||||||||||
| // when | ||||||||||||||||||||||||||||||
| labels := hostAwait.GetMetricLabels(t, hostAwait.MetricsURL, wait.HostOperatorVersionMetric) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // verify that the "version" metric exists for Host Operator and that it has a non-empty `commit` label | ||||||||||||||||||||||||||||||
| require.Len(t, labels, 1) | ||||||||||||||||||||||||||||||
| commit := labels[0]["commit"] | ||||||||||||||||||||||||||||||
| assert.Len(t, commit, 7) | ||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| t.Run("member-operators", func(t *testing.T) { | ||||||||||||||||||||||||||||||
|
|
@@ -56,7 +79,7 @@ | |||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // --- member1 --- | ||||||||||||||||||||||||||||||
| // when | ||||||||||||||||||||||||||||||
| labels := member1Await.GetMetricLabels(t, wait.MemberOperatorVersionMetric) | ||||||||||||||||||||||||||||||
| labels := member1Await.GetMetricLabels(t, member1Await.MetricsURL, wait.MemberOperatorVersionMetric) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // verify that the "version" metric exists for the first Member Operator and that it has a non-empty `commit` label | ||||||||||||||||||||||||||||||
| require.Len(t, labels, 1) | ||||||||||||||||||||||||||||||
|
|
@@ -65,7 +88,7 @@ | |||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // --- member2 --- | ||||||||||||||||||||||||||||||
| // when | ||||||||||||||||||||||||||||||
| labels = member2Await.GetMetricLabels(t, wait.MemberOperatorVersionMetric) | ||||||||||||||||||||||||||||||
| labels = member2Await.GetMetricLabels(t, member2Await.MetricsURL, wait.MemberOperatorVersionMetric) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // verify that the "version" metric exists for the second Member Operator and that it has a non-empty `commit` label | ||||||||||||||||||||||||||||||
| require.Len(t, labels, 1) | ||||||||||||||||||||||||||||||
|
|
@@ -75,6 +98,35 @@ | |||||||||||||||||||||||||||||
| // expect the same version on member1 and member2 | ||||||||||||||||||||||||||||||
| assert.Equal(t, commit1, commit2) | ||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| t.Run("registration-service", func(t *testing.T) { | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // given | ||||||||||||||||||||||||||||||
| hostAwait := awaitilities.Host() | ||||||||||||||||||||||||||||||
| _, err := hostAwait.WaitForRouteToBeAvailable(t, hostAwait.Namespace, "host-operator-metrics-service", "/metrics") | ||||||||||||||||||||||||||||||
| require.NoError(t, err) | ||||||||||||||||||||||||||||||
|
Comment on lines
+102
to
+107
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Wrong service name in route availability check for registration-service metrics. Line 106 waits for 🐛 Proposed fix t.Run("registration-service", func(t *testing.T) {
// given
hostAwait := awaitilities.Host()
- _, err := hostAwait.WaitForRouteToBeAvailable(t, hostAwait.Namespace, "host-operator-metrics-service", "/metrics")
+ _, err := hostAwait.WaitForRouteToBeAvailable(t, hostAwait.RegistrationServiceNs, "registration-service-metrics", "/metrics")
require.NoError(t, err)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Comment on lines
+106
to
+107
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the same
Suggested change
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| t.Run("commit", func(t *testing.T) { | ||||||||||||||||||||||||||||||
| // when | ||||||||||||||||||||||||||||||
| labels := hostAwait.GetMetricLabels(t, hostAwait.RegistrationServiceMetricsURL, wait.RegistrationServiceCommitMetric) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // verify that the "version" metric exists for Host Operator and that it has a non-empty `commit` label | ||||||||||||||||||||||||||||||
| require.Len(t, labels, 1) | ||||||||||||||||||||||||||||||
| commit := labels[0]["commit"] | ||||||||||||||||||||||||||||||
| assert.Len(t, commit, len("da3f54634cc65075d51d067a157831d44bf1413e")) // example value: 40 characters | ||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| t.Run("short commit", func(t *testing.T) { | ||||||||||||||||||||||||||||||
| // when | ||||||||||||||||||||||||||||||
| labels := hostAwait.GetMetricLabels(t, hostAwait.RegistrationServiceMetricsURL, wait.RegistrationServiceShortCommitMetric) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // verify that the "version" metric exists for Host Operator and that it has a non-empty `commit` label | ||||||||||||||||||||||||||||||
| require.Len(t, labels, 1) | ||||||||||||||||||||||||||||||
| commit := labels[0]["commit"] | ||||||||||||||||||||||||||||||
| assert.Len(t, commit, 7) | ||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // TestMetricsWhenUsersManuallyApproved verifies that `UserSignupsApprovedMetric` and `UserSignupsApprovedWithMethodMetric` counters are increased when users are approved | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -34,6 +34,7 @@ | |||||||||||||||||||||||||||||||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||||||||||||||||||||||||||||||
| "k8s.io/apimachinery/pkg/runtime" | ||||||||||||||||||||||||||||||||
| "k8s.io/apimachinery/pkg/types" | ||||||||||||||||||||||||||||||||
| "k8s.io/apimachinery/pkg/util/intstr" | ||||||||||||||||||||||||||||||||
| "k8s.io/client-go/rest" | ||||||||||||||||||||||||||||||||
| "k8s.io/client-go/tools/clientcmd" | ||||||||||||||||||||||||||||||||
| "k8s.io/client-go/tools/clientcmd/api" | ||||||||||||||||||||||||||||||||
|
|
@@ -205,14 +206,43 @@ | |||||||||||||||||||||||||||||||
| require.NoError(t, err, "failed to find proxy metrics service") | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // setup host metrics route for metrics verification in tests | ||||||||||||||||||||||||||||||||
| hostMetricsRoute, err := initHostAwait.SetupRouteForService(t, "host-operator-metrics-service", "/metrics") | ||||||||||||||||||||||||||||||||
| hostMetricsRoute, err := initHostAwait.SetupRouteForService(t, "host-operator-metrics-service", "/metrics", | ||||||||||||||||||||||||||||||||
|
Check failure on line 209 in testsupport/init.go
|
||||||||||||||||||||||||||||||||
| &routev1.RoutePort{ | ||||||||||||||||||||||||||||||||
| TargetPort: intstr.FromString("https"), | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| &routev1.TLSConfig{ | ||||||||||||||||||||||||||||||||
| Termination: routev1.TLSTerminationPassthrough, | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
| require.NoError(t, err) | ||||||||||||||||||||||||||||||||
| initHostAwait.MetricsURL = "https://" + hostMetricsRoute.Status.Ingress[0].Host | ||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Check if SetupRouteForService guarantees non-empty Ingress on return
ast-grep --pattern 'func ($_ *Awaitility) SetupRouteForService($$$) ($_, error) {
$$$
}'Repository: codeready-toolchain/toolchain-e2e Length of output: 2439 🏁 Script executed: # First, let's locate and examine testsupport/init.go
fd init.go testsupport
# Also check the line count to understand file structure
wc -l testsupport/init.go 2>/dev/null || echo "File not found in expected path"Repository: codeready-toolchain/toolchain-e2e Length of output: 120 🏁 Script executed: # Search for files that use SetupRouteForService and access Ingress[0].Host
rg "SetupRouteForService|Ingress\[0\]\.Host" --type-list | head -20Repository: codeready-toolchain/toolchain-e2e Length of output: 466 🏁 Script executed: # Find WaitForRouteToBeAvailable implementation
ast-grep --pattern 'func ($_ *Awaitility) WaitForRouteToBeAvailable($$$) ($_, error) {
$$$
}'Repository: codeready-toolchain/toolchain-e2e Length of output: 4243 🏁 Script executed: # Examine testsupport/init.go around lines 218, 231, 244
sed -n '210,250p' testsupport/init.goRepository: codeready-toolchain/toolchain-e2e Length of output: 1936 🏁 Script executed: # Also check for the specific string from the review comment snippet
rg "initHostAwait.MetricsURL" testsupport/Repository: codeready-toolchain/toolchain-e2e Length of output: 257 🏁 Script executed: # Find all places accessing .Status.Ingress[0]
rg "Status\.Ingress\[0\]" testsupport/Repository: codeready-toolchain/toolchain-e2e Length of output: 772 🏁 Script executed: # Check all occurrences of accessing Ingress in the codebase
rg "\.Status\.Ingress" --type go -B 2 -A 2 | head -100Repository: codeready-toolchain/toolchain-e2e Length of output: 2139 Add defensive checks before accessing route Ingress slice. Lines 218, 231, and 244 access if len(route.Status.Ingress) == 0 {
t.Fatalf("route has no ingress status")
}🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||
| t.Logf("host metrics URL: %s", initHostAwait.MetricsURL) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // setup registration service metrics route for metrics verification in tests | ||||||||||||||||||||||||||||||||
| registrationServiceMetricsRoute, err := initHostAwait.SetupRouteForService(t, "registration-service-metrics", "/metrics", | ||||||||||||||||||||||||||||||||
| &routev1.RoutePort{ | ||||||||||||||||||||||||||||||||
| TargetPort: intstr.FromString("regsvc-metrics"), | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| &routev1.TLSConfig{ | ||||||||||||||||||||||||||||||||
| Termination: routev1.TLSTerminationEdge, | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
| require.NoError(t, err) | ||||||||||||||||||||||||||||||||
| initHostAwait.RegistrationServiceMetricsURL = "https://" + registrationServiceMetricsRoute.Status.Ingress[0].Host | ||||||||||||||||||||||||||||||||
| t.Logf("registration service metrics URL: %s", initHostAwait.RegistrationServiceMetricsURL) | ||||||||||||||||||||||||||||||||
|
Comment on lines
+222
to
+232
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it looks like the route creation is also done in the tests toolchain-e2e/test/e2e/parallel/registration_service_test.go Lines 76 to 90 in 629dc7b
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ahh, good catch! I only ran the tests in the |
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // setup member metrics route for metrics verification in tests | ||||||||||||||||||||||||||||||||
| memberMetricsRoute, err := initMemberAwait.SetupRouteForService(t, "member-operator-metrics-service", "/metrics") | ||||||||||||||||||||||||||||||||
| memberMetricsRoute, err := initMemberAwait.SetupRouteForService(t, "member-operator-metrics-service", "/metrics", | ||||||||||||||||||||||||||||||||
| &routev1.RoutePort{ | ||||||||||||||||||||||||||||||||
| TargetPort: intstr.FromString("https"), | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| &routev1.TLSConfig{ | ||||||||||||||||||||||||||||||||
| Termination: routev1.TLSTerminationPassthrough, | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
| require.NoError(t, err, "failed while setting up or waiting for the route to the 'member-operator-metrics' service to be available") | ||||||||||||||||||||||||||||||||
| initMemberAwait.MetricsURL = "https://" + memberMetricsRoute.Status.Ingress[0].Host | ||||||||||||||||||||||||||||||||
| t.Logf("member metrics URL: %s", initMemberAwait.MetricsURL) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // Wait for the webhooks in Member 1 only because we do not deploy webhooks for Member 2 | ||||||||||||||||||||||||||||||||
| // (we can't deploy the same webhook multiple times on the same cluster) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's just a detail, but you technically don't need this because
WaitForRouteToBeAvailableis executed as part ofSetupRouteForService