Skip to content
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
15 changes: 14 additions & 1 deletion .govulncheck.yaml
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

26 changes: 3 additions & 23 deletions test/e2e/parallel/registration_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@ import (
"github.com/codeready-toolchain/toolchain-e2e/testsupport/wait"
"github.com/davecgh/go-spew/spew"
"github.com/gofrs/uuid"
routev1 "github.com/openshift/api/route/v1"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
k8swait "k8s.io/apimachinery/pkg/util/wait"
)

Expand Down Expand Up @@ -73,27 +70,10 @@ func TestRegistrationServiceMetricsEndpoint(t *testing.T) {

t.Run("available from a custom route", func(t *testing.T) { // create a route for to expose the `registration-service-metrics` svc
// given
route := &routev1.Route{
ObjectMeta: metav1.ObjectMeta{
Namespace: await.Host().Namespace,
Name: "registration-service-metrics",
},
Spec: routev1.RouteSpec{
To: routev1.RouteTargetReference{
Kind: "Service",
Name: "registration-service-metrics",
},
Port: &routev1.RoutePort{
TargetPort: intstr.FromString("regsvc-metrics"),
},
},
}
err := await.Host().CreateWithCleanup(t, route)
require.NoError(t, err)
_, err = await.Host().WaitForRouteToBeAvailable(t, route.Namespace, route.Name, "/metrics")
require.NoError(t, err, "route not available", route)
route, err := await.Host().WaitForRouteToBeAvailable(t, await.Host().Namespace, "registration-service-metrics", "/metrics")
require.NoError(t, err, "route not available", "registration-service-metrics")

req, err := http.NewRequest("GET", "http://"+route.Spec.Host+"/metrics", nil)
req, err := http.NewRequest("GET", "https://"+route.Spec.Host+"/metrics", nil)
require.NoError(t, err)
// when
resp, err := httpClient.Do(req) // nolint:bodyclose // see `defer Close(t, resp)`
Expand Down
72 changes: 61 additions & 11 deletions test/metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,52 @@ func TestOperatorVersionMetrics(t *testing.T) {
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)

// 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)
})
Comment on lines +39 to +67
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix misleading comments - these refer to "version" metric but test commit metrics.

Lines 43 and 53 have copy-paste errors. The comments say "version" metric but these subtests validate commit and short_commit metrics respectively.

✏️ Proposed fix
 		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
+			// verify that the "commit" 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
+			// verify that the "short_commit" 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)
 		})
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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("commit", func(t *testing.T) {
// when
labels := hostAwait.GetMetricLabels(t, hostAwait.MetricsURL, wait.HostOperatorCommitMetric)
// verify that the "commit" 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 "short_commit" 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)
})
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/metrics/metrics_test.go` around lines 39 - 67, Update the misleading
copy-paste comments in the subtests: in the t.Run("commit") block change the
comment that currently mentions the `"version" metric` to accurately say it
verifies the `commit` metric (using wait.HostOperatorCommitMetric), in
t.Run("short commit") change the comment to say it verifies the `short_commit`
metric (using wait.HostOperatorShortCommitMetric), and in t.Run("version")
ensure the comment references the `version` metric
(wait.HostOperatorVersionMetric); locate these comments near the calls to
hostAwait.GetMetricLabels and the assert.Len checks for the commit label and
update the text accordingly.

})

t.Run("member-operators", func(t *testing.T) {
// given
member1Await := awaitilities.Member1()
member2Await := awaitilities.Member1()
member2Await := awaitilities.Member2()
// member metrics should be available at this point
member1Await.InitMetrics(t)
member2Await.InitMetrics(t)

// --- 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)
Expand All @@ -65,7 +86,7 @@ func TestOperatorVersionMetrics(t *testing.T) {

// --- 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)
Expand All @@ -75,6 +96,35 @@ func TestOperatorVersionMetrics(t *testing.T) {
// 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, "registration-service-metrics", "/metrics")
require.NoError(t, err)
Comment thread
coderabbitai[bot] marked this conversation as resolved.

Comment thread
coderabbitai[bot] marked this conversation as resolved.
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)
})
Comment on lines +107 to +125
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix misleading comments - these refer to registration-service, not Host Operator.

Lines 111 and 121 contain copy-paste errors from the host-operator subtests. The comments say "Host Operator" but this is the registration-service subtest.

✏️ Proposed fix
 		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
+			// verify that the "commit" metric exists for registration-service 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
+			// verify that the "short_commit" metric exists for registration-service and that it has a non-empty `commit` label
 			require.Len(t, labels, 1)
 			commit := labels[0]["commit"]
 			assert.Len(t, commit, 7)
 		})
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

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)
})
t.Run("commit", func(t *testing.T) {
// when
labels := hostAwait.GetMetricLabels(t, hostAwait.RegistrationServiceMetricsURL, wait.RegistrationServiceCommitMetric)
// verify that the "commit" metric exists for registration-service 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 "short_commit" metric exists for registration-service and that it has a non-empty `commit` label
require.Len(t, labels, 1)
commit := labels[0]["commit"]
assert.Len(t, commit, 7)
})
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/metrics/metrics_test.go` around lines 107 - 125, The comments in the
subtests that call hostAwait.GetMetricLabels against
hostAwait.RegistrationServiceMetricsURL (using
wait.RegistrationServiceCommitMetric and
wait.RegistrationServiceShortCommitMetric) incorrectly mention "Host Operator"
due to copy-paste; update the two comment lines (above the require.Len checks in
the "commit" and "short commit" t.Run blocks) to refer to the
registration-service instead (e.g., "verify that the 'version' metric exists for
registration-service and that it has a non-empty `commit` label"), leaving the
test logic and identifiers (hostAwait.GetMetricLabels,
hostAwait.RegistrationServiceMetricsURL, wait.RegistrationServiceCommitMetric,
wait.RegistrationServiceShortCommitMetric) unchanged.

})

}

// TestMetricsWhenUsersManuallyApproved verifies that `UserSignupsApprovedMetric` and `UserSignupsApprovedWithMethodMetric` counters are increased when users are approved
Expand Down
50 changes: 48 additions & 2 deletions testsupport/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -205,14 +206,46 @@
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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "/metrics" 4 times.

See more on https://sonarcloud.io/project/issues?id=codeready-toolchain_toolchain-e2e&issues=AZ0gq5uljb2ksXck6Nks&open=AZ0gq5uljb2ksXck6Nks&pullRequest=1269
&routev1.RoutePort{
TargetPort: intstr.FromString("https"),
},
&routev1.TLSConfig{
Termination: routev1.TLSTerminationPassthrough,
},
)
require.NoError(t, err)
require.NotEmpty(t, hostMetricsRoute.Status.Ingress, "route has no ingress status for host metrics service")
initHostAwait.MetricsURL = "https://" + hostMetricsRoute.Status.Ingress[0].Host
Comment thread
coderabbitai[bot] marked this conversation as resolved.
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)
require.NotEmpty(t, registrationServiceMetricsRoute.Status.Ingress, "route has no ingress status for registration service metrics service")
initHostAwait.RegistrationServiceMetricsURL = "https://" + registrationServiceMetricsRoute.Status.Ingress[0].Host
t.Logf("registration service metrics URL: %s", initHostAwait.RegistrationServiceMetricsURL)
Comment on lines +223 to +234
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it looks like the route creation is also done in the tests

route := &routev1.Route{
ObjectMeta: metav1.ObjectMeta{
Namespace: await.Host().Namespace,
Name: "registration-service-metrics",
},
Spec: routev1.RouteSpec{
To: routev1.RouteTargetReference{
Kind: "Service",
Name: "registration-service-metrics",
},
Port: &routev1.RoutePort{
TargetPort: intstr.FromString("regsvc-metrics"),
},
},
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ahh, good catch! I only ran the tests in the test/metrics package so I missed the route creation in test/e2e. Let me refactor that

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed in 0aaaaed


// 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")
require.NotEmpty(t, memberMetricsRoute.Status.Ingress, "route has no ingress status for member metrics service")
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)
Expand All @@ -222,6 +255,19 @@
if IsSecondMemberMode(t) {
err = initMember2Await.WaitUntilWebhookDeleted(t) // webhook on member2 should be deleted
require.NoError(t, err)
memberMetricsRoute, err := initMember2Await.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")
require.NotEmpty(t, memberMetricsRoute.Status.Ingress, "route has no ingress status for member metrics service")
initMember2Await.MetricsURL = "https://" + memberMetricsRoute.Status.Ingress[0].Host
t.Logf("member metrics URL: %s", initMember2Await.MetricsURL)

}
initMemberAwait.WaitForMemberWebhooks(t, webhookImage)

Expand Down
7 changes: 3 additions & 4 deletions testsupport/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,14 @@ func getBuckets(t dto.MetricType, m *dto.Metric) (*[]*dto.Bucket, error) {

// GetMetricLabels return all labels (indexed by key) for all metrics of the given `family`
func GetMetricLabels(restConfig *rest.Config, baseURL string, family string) ([]map[string]string, error) {
uri := baseURL + "/metrics"
var metrics []byte

client := http.Client{
Timeout: time.Duration(30 * time.Second),
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, //nolint:gosec
},
}
request, err := http.NewRequest("Get", uri, nil)
uri := baseURL + "/metrics"
request, err := http.NewRequest("GET", uri, nil)
if err != nil {
return nil, err
}
Expand All @@ -150,6 +148,7 @@ func GetMetricLabels(restConfig *rest.Config, baseURL string, family string) ([]
defer func() {
_ = resp.Body.Close()
}()
var metrics []byte
metrics, err = io.ReadAll(resp.Body)
if err != nil {
return nil, err
Expand Down
26 changes: 11 additions & 15 deletions testsupport/wait/awaitility.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/rest"
"k8s.io/kubectl/pkg/util/podutils"
Expand Down Expand Up @@ -210,8 +209,8 @@
// SetupRouteForService if needed, creates a route for the given service (with the same namespace/name)
// It waits until the route is available (or returns an error) by first checking the resource status
// and then making a call to the given endpoint
func (a *Awaitility) SetupRouteForService(t *testing.T, serviceName, endpoint string) (routev1.Route, error) {
t.Logf("setting up route for service '%s' with endpoint '%s'", serviceName, endpoint)
func (a *Awaitility) SetupRouteForService(t *testing.T, serviceName string, path string, port *routev1.RoutePort, tlsConfig *routev1.TLSConfig) (routev1.Route, error) {
t.Logf("setting up route for service '%s' with endpoint '%s'", serviceName, path)
service, err := a.WaitForService(t, serviceName)
if err != nil {
return routev1.Route{}, err
Expand All @@ -230,28 +229,24 @@
Name: service.Name,
},
Spec: routev1.RouteSpec{
Port: &routev1.RoutePort{
TargetPort: intstr.FromString("https"),
},
TLS: &routev1.TLSConfig{
Termination: routev1.TLSTerminationPassthrough,
},
To: routev1.RouteTargetReference{
Kind: service.Kind,
Name: service.Name,
},
Port: port,
TLS: tlsConfig,
},
}
if err = a.Client.Create(context.TODO(), &route); err != nil {
return route, err
}
}
return a.WaitForRouteToBeAvailable(t, route.Namespace, route.Name, endpoint)
return a.WaitForRouteToBeAvailable(t, route.Namespace, route.Name, path)
}

// WaitForRouteToBeAvailable waits until the given route is available, ie, it has an Ingress with a host configured
// and the endpoint is reachable (with a `200 OK` status response)
func (a *Awaitility) WaitForRouteToBeAvailable(t *testing.T, ns, name, endpoint string) (routev1.Route, error) {
func (a *Awaitility) WaitForRouteToBeAvailable(t *testing.T, ns, name, path string) (routev1.Route, error) {

Check failure on line 249 in testsupport/wait/awaitility.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 23 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=codeready-toolchain_toolchain-e2e&issues=AZ0gq5tkjb2ksXck6Nkr&open=AZ0gq5tkjb2ksXck6Nkr&pullRequest=1269
t.Logf("waiting for route '%s' in namespace '%s'", name, ns)
route := routev1.Route{}
// retrieve the route for the registration service
Expand Down Expand Up @@ -282,13 +277,13 @@
InsecureSkipVerify: true, // nolint:gosec
},
}
request, err = http.NewRequest("GET", "https://"+route.Status.Ingress[0].Host+endpoint, nil)
request, err = http.NewRequest("GET", "https://"+route.Status.Ingress[0].Host+path, nil)
if err != nil {
return false, err
}
request.Header.Add("Authorization", fmt.Sprintf("Bearer %s", a.RestConfig.BearerToken))
} else {
request, err = http.NewRequest("GET", "http://"+route.Status.Ingress[0].Host+endpoint, nil)
request, err = http.NewRequest("GET", "http://"+route.Status.Ingress[0].Host+path, nil)
if err != nil {
return false, err
}
Expand Down Expand Up @@ -335,8 +330,9 @@

// GetMetricValue gets the value of the metric with the given family and label key-value pair
// fails if the metric with the given labelAndValues does not exist
func (a *Awaitility) GetMetricLabels(t *testing.T, family string) []map[string]string {
labels, err := metrics.GetMetricLabels(a.RestConfig, a.MetricsURL, family)
func (a *Awaitility) GetMetricLabels(t *testing.T, metricsURL, family string) []map[string]string {
t.Logf("getting labels for metric '%s' from '%s'", family, metricsURL)
labels, err := metrics.GetMetricLabels(a.RestConfig, metricsURL, family)
require.NoError(t, err)
return labels
}
Expand Down
23 changes: 15 additions & 8 deletions testsupport/wait/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ var (
// HostAwaitility the Awaitility for the Host cluster
type HostAwaitility struct {
*Awaitility
RegistrationServiceNs string
RegistrationServiceURL string
APIProxyURL string
RegistrationServiceNs string
RegistrationServiceURL string
RegistrationServiceMetricsURL string
APIProxyURL string
}

// NewHostAwaitility initializes a HostAwaitility
Expand All @@ -81,10 +82,11 @@ func NewHostAwaitility(cfg *rest.Config, cl client.Client, ns string, registrati
// WithRetryOptions returns a new HostAwaitility with the given RetryOptions applied
func (a *HostAwaitility) WithRetryOptions(options ...RetryOption) *HostAwaitility {
return &HostAwaitility{
Awaitility: a.Awaitility.WithRetryOptions(options...),
RegistrationServiceNs: a.RegistrationServiceNs,
RegistrationServiceURL: a.RegistrationServiceURL,
APIProxyURL: a.APIProxyURL,
Awaitility: a.Awaitility.WithRetryOptions(options...),
RegistrationServiceNs: a.RegistrationServiceNs,
RegistrationServiceURL: a.RegistrationServiceURL,
RegistrationServiceMetricsURL: a.RegistrationServiceMetricsURL,
APIProxyURL: a.APIProxyURL,
}
}

Expand All @@ -111,7 +113,12 @@ const (

UsersPerActivationsAndDomainMetric = "sandbox_users_per_activations_and_domain"

HostOperatorVersionMetric = "sandbox_host_operator_version"
HostOperatorVersionMetric = "sandbox_host_operator_version" // DEPRECATED: use HostOperatorCommitMetric instead
HostOperatorCommitMetric = "sandbox_host_operator_commit"
HostOperatorShortCommitMetric = "sandbox_host_operator_short_commit"

RegistrationServiceCommitMetric = "sandbox_registration_service_commit"
RegistrationServiceShortCommitMetric = "sandbox_registration_service_short_commit"

SignupProvisionTimeMetric = "sandbox_user_signup_provision_time"
)
Expand Down
Loading