Skip to content
Open
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
6 changes: 3 additions & 3 deletions controllers/spacerequest/spacerequest_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func TestCreateSpaceRequest(t *testing.T) {
HasSpecTargetClusterRoles(srClusterRoles).
HasConditions(spacetest.Ready()). // condition is reflected from space status
HasStatusTargetClusterURL(member1.APIEndpoint). // has new target cluster url
HasNamespaceAccess([]toolchainv1alpha1.NamespaceAccess{{Name: "jane-env1", SecretRef: "existingDevSecret"}, {Name: "jane-env2", SecretRef: "existingDevSecret2"}}). // expected secrets are there. The secret names may not match exactly since it is generated the first time it's created
HasNamespaceAccess([]toolchainv1alpha1.NamespaceAccess{{Name: "jane-env1", SecretRef: "existingDevSecret"}, {Name: "jane-env2", SecretRef: "existingDevSecret2"}}). // nolint:gosec // expected secrets are there. The secret names may not match exactly since it is generated the first time it's created
HasFinalizer()
// a subspace is created with the tierName and cluster roles from the spacerequest
spacetest.AssertThatSpace(t, commontest.HostOperatorNs, spaceutil.SubSpaceName(parentSpace, sr), hostClient).
Expand Down Expand Up @@ -662,7 +662,7 @@ func TestCreateSpaceRequest(t *testing.T) {
HasSpecTargetClusterRoles(srClusterRoles).
HasConditions(spacetest.Ready()). // condition is reflected from space status
HasStatusTargetClusterURL(member1.APIEndpoint). // has new target cluster url
HasNamespaceAccess([]toolchainv1alpha1.NamespaceAccess{{Name: "jane-env1", SecretRef: "existingDevSecret"}, {Name: "jane-env2", SecretRef: "existingDevSecret2"}}). // expected secrets are there. The secret names may not match exactly since it is generated the first time it's created
HasNamespaceAccess([]toolchainv1alpha1.NamespaceAccess{{Name: "jane-env1", SecretRef: "existingDevSecret"}, {Name: "jane-env2", SecretRef: "existingDevSecret2"}}). // nolint:gosec // expected secrets are there. The secret names may not match exactly since it is generated the first time it's created
HasFinalizer()
// check that the secrets are there
secrets := &corev1.SecretList{}
Expand Down Expand Up @@ -1241,7 +1241,7 @@ func TestUpdateSpaceRequest(t *testing.T) {
// spacerequest exists with expected cluster roles and finalizer
spacerequesttest.AssertThatSpaceRequest(t, srNamespace.Name, sr.GetName(), member1.Client).
HasSpecTierName("appstudio-env").
HasNamespaceAccess([]toolchainv1alpha1.NamespaceAccess{{Name: "jane-env", SecretRef: "existingDevSecret"}}). // expected secrets are there. The secret name may not match exactly since it is generated the first time it's created
HasNamespaceAccess([]toolchainv1alpha1.NamespaceAccess{{Name: "jane-env", SecretRef: "existingDevSecret"}}). // nolint:gosec // expected secrets are there. The secret name may not match exactly since it is generated the first time it's created
HasFinalizer()
})
})
Expand Down
9 changes: 4 additions & 5 deletions controllers/usersignup/usersignup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -830,9 +830,8 @@ func (r *Reconciler) annotateCaptchaAssessment(ctx context.Context, userSignup *
// set the annotated assessment value: FRAUDULENT or LEGITIMATE
userSignup.Annotations[toolchainv1alpha1.UserSignupCaptchaAnnotatedAssessmentAnnotationKey] = newAnnotationName

go func() {
gctx := context.Background()
rclient, err := recaptcha.NewClient(gctx)
go func(ctx context.Context) {
rclient, err := recaptcha.NewClient(ctx)
if err != nil {
logger.Error(err, "error creating reCAPTCHA client, cannot annotate assessment")
return
Expand All @@ -844,13 +843,13 @@ func (r *Reconciler) annotateCaptchaAssessment(ctx context.Context, userSignup *
Annotation: newAssessmentAnnotation,
}

response, err := rclient.AnnotateAssessment(gctx, annotateRequest)
response, err := rclient.AnnotateAssessment(ctx, annotateRequest)
if err != nil {
logger.Error(err, "error annotating assessment")
return
}
logger.Info("Assessment annotated successfully", "assessment_annotation", newAnnotationName, "response", response.String())
}()
}(ctx)

}

Expand Down
14 changes: 10 additions & 4 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ func initMetrics() {
HostOperatorCommitGaugeVec = newGaugeVec("host_operator_commit", "Full commit used to identify the version of the host operator", "commit")
HostOperatorShortCommitGaugeVec = newGaugeVec("host_operator_short_commit", "Short commit used to identify the version of the host operator", "commit")
ToolchainStatusGaugeVec = newGaugeVec("toolchain_status", "Current status of the toolchain components", "component")

// set the version metrics
shortCommit := version.Commit
if len(version.Commit) >= 7 {
shortCommit = version.Commit[0:7]
}
HostOperatorVersionGaugeVec.WithLabelValues(shortCommit).Set(1) // the HostOperatorVersionGaugeVec is set to `1`, Grafana will display the 'commit' label as the version for the instant record
HostOperatorCommitGaugeVec.WithLabelValues(version.Commit).SetToCurrentTime() // automatically set the value to the current time, so that the highest value is the current commit
HostOperatorShortCommitGaugeVec.WithLabelValues(shortCommit).SetToCurrentTime() // automatically set the value to the current time, so that the highest value is the current commit

// Histograms
UserSignupProvisionTimeHistogram = newHistogram("user_signup_provision_time", "UserSignup provision time in seconds")
logger.Info("custom metrics initialized")
Expand Down Expand Up @@ -205,10 +215,6 @@ func RegisterCustomMetrics() []prometheus.Collector {
collectors = append(collectors, v)
}

HostOperatorVersionGaugeVec.WithLabelValues(version.Commit[0:7]).Set(1) // the HostOperatorVersionGaugeVec is set to `1`, Grafana will display the 'commit' label as the version for the instant record
HostOperatorCommitGaugeVec.WithLabelValues(version.Commit).SetToCurrentTime() // automatically set the value to the current time, so that the highest value is the current commit
HostOperatorShortCommitGaugeVec.WithLabelValues(version.Commit[0:7]).SetToCurrentTime() // automatically set the value to the current time, so that the highest value is the current commit

logger.Info("custom metrics registered")
return collectors
}
Expand Down
32 changes: 26 additions & 6 deletions pkg/metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1"
"github.com/codeready-toolchain/host-operator/pkg/metrics"
metricstest "github.com/codeready-toolchain/host-operator/test/metrics"
"github.com/codeready-toolchain/host-operator/version"
"github.com/codeready-toolchain/toolchain-common/pkg/test"
"github.com/codeready-toolchain/toolchain-common/pkg/test/masteruserrecord"
metricscommontest "github.com/codeready-toolchain/toolchain-common/pkg/test/metrics"
Expand Down Expand Up @@ -44,29 +45,48 @@ func TestResetMetrics(t *testing.T) {
}

func TestGitCommitGauge(t *testing.T) {
t.Run("HostOperatorCommitGaugeVec", func(t *testing.T) {
t.Run("when commit is longer than 7 characters", func(t *testing.T) {
// given
version.Commit = "short12-34567890"
metrics.Reset()
defer metrics.Reset()
now := time.Now()

// when
metrics.HostOperatorCommitGaugeVec.WithLabelValues("commit-1234567890").SetToCurrentTime()
metrics.Reset()

// then
assert.InDelta(t, float64(now.Unix()), promtestutil.ToFloat64(metrics.HostOperatorCommitGaugeVec.WithLabelValues("commit-1234567890")), float64(time.Minute.Seconds()))
assert.InDelta(t, float64(now.Unix()), promtestutil.ToFloat64(metrics.HostOperatorShortCommitGaugeVec.WithLabelValues("short12")), float64(time.Minute.Seconds()))
assert.InDelta(t, float64(now.Unix()), promtestutil.ToFloat64(metrics.HostOperatorCommitGaugeVec.WithLabelValues("short12-34567890")), float64(time.Minute.Seconds()))
})
t.Run("HostOperatorShortCommitGaugeVec", func(t *testing.T) {
t.Run("when commit is shorter than 7 characters", func(t *testing.T) {
// given
version.Commit = "short"
metrics.Reset()
defer metrics.Reset()
now := time.Now()

// when
metrics.HostOperatorShortCommitGaugeVec.WithLabelValues("hash-1234567890").SetToCurrentTime()
metrics.Reset()

// then
assert.InDelta(t, float64(now.Unix()), promtestutil.ToFloat64(metrics.HostOperatorShortCommitGaugeVec.WithLabelValues("short")), float64(time.Minute.Seconds()))
assert.InDelta(t, float64(now.Unix()), promtestutil.ToFloat64(metrics.HostOperatorCommitGaugeVec.WithLabelValues("short")), float64(time.Minute.Seconds()))
})

t.Run("when commit is empty", func(t *testing.T) {
// given
version.Commit = ""
metrics.Reset()
defer metrics.Reset()
now := time.Now()

// when
metrics.Reset()

// then
assert.InDelta(t, float64(now.Unix()), promtestutil.ToFloat64(metrics.HostOperatorShortCommitGaugeVec.WithLabelValues("hash-1234567890")), float64(time.Minute.Seconds()))
assert.InDelta(t, float64(now.Unix()), promtestutil.ToFloat64(metrics.HostOperatorShortCommitGaugeVec.WithLabelValues("")), float64(time.Minute.Seconds()))
assert.InDelta(t, float64(now.Unix()), promtestutil.ToFloat64(metrics.HostOperatorCommitGaugeVec.WithLabelValues("")), float64(time.Minute.Seconds()))
})
}
func TestIncrementMasterUserRecordCount(t *testing.T) {
Expand Down
Loading