From 1ba24f93bddf58511a9d4d059ca580bdc324f70c Mon Sep 17 00:00:00 2001 From: Arsalan Khan Date: Wed, 8 Jan 2025 13:34:50 +0100 Subject: [PATCH] Fix: submit custom metrics via mTLS for lead time test --- src/acceptance/app/custom_metric_test.go | 23 ++++++++------ src/acceptance/app/lead_times_test.go | 4 +-- src/acceptance/helpers/helpers.go | 39 ++---------------------- 3 files changed, 18 insertions(+), 48 deletions(-) diff --git a/src/acceptance/app/custom_metric_test.go b/src/acceptance/app/custom_metric_test.go index 0a42139603..ebfba3597c 100644 --- a/src/acceptance/app/custom_metric_test.go +++ b/src/acceptance/app/custom_metric_test.go @@ -26,19 +26,18 @@ var _ = Describe("AutoScaler custom metrics", func() { AfterEach(AppAfterEach) Describe("custom metrics policy for same app", func() { - BeforeEach(func() { - credentialType := "binding-secret" - policy = GeneratePolicyWithCredentialType( - 1, 2, "test_metric", 500, 500, - &credentialType) - instanceName = CreatePolicy(cfg, appToScaleName, appToScaleGUID, policy) - StartApp(appToScaleName, cfg.CfPushTimeoutDuration()) - }) /* - Going forward, custom metrics submission should be possible via mTLS route only.This test can be removed in future if credential-type is set to X509. + Going forward, custom metrics submission should be possible via mTLS route only.This test can be removed in future if credential-type is set to X509 permanently. Added test for rollback cases where custom metrics are still sent via basic auth route. */ Context("when scaling by custom metrics", func() { + BeforeEach(func() { + credentialType := "binding-secret" + policy = GeneratePolicyWithCredentialType( + 1, 2, "test_metric", 500, 500, &credentialType) + instanceName = CreatePolicy(cfg, appToScaleName, appToScaleGUID, policy) + StartApp(appToScaleName, cfg.CfPushTimeoutDuration()) + }) It("should scale out and scale in", Label(acceptance.LabelSmokeTests), func() { By("Scale out to 2 instances") scaleOut := sendMetricToAutoscaler(cfg, appToScaleGUID, appToScaleName, 550, false) @@ -53,11 +52,15 @@ var _ = Describe("AutoScaler custom metrics", func() { WithTimeout(5 * time.Minute). WithPolling(15 * time.Second). Should(Equal(1)) - }) }) Context("when scaling by custom metrics via mtls", func() { + BeforeEach(func() { + policy := GenerateDynamicScaleOutAndInPolicy(1, 2, "test_metric", 500, 500) + instanceName = CreatePolicy(cfg, appToScaleName, appToScaleGUID, policy) + StartApp(appToScaleName, cfg.CfPushTimeoutDuration()) + }) It("should scale out and scale in", Label(acceptance.LabelSmokeTests), func() { By("Scale out to 2 instances") scaleOut := sendMetricToAutoscaler(cfg, appToScaleGUID, appToScaleName, 550, true) diff --git a/src/acceptance/app/lead_times_test.go b/src/acceptance/app/lead_times_test.go index f833ee348c..62e972333f 100644 --- a/src/acceptance/app/lead_times_test.go +++ b/src/acceptance/app/lead_times_test.go @@ -29,8 +29,8 @@ var _ = Describe("Autoscaler lead times for scaling", func() { coolDown := TestCoolDownSeconds * time.Second scalingTimewindow := 130 * time.Second // be friendly and allow some time for "internal autoscaler processes" (metric polling interval etc.) to take place before actual scaling happens - sendMetricForScaleOutAndReturnNumInstancesFunc := sendMetricToAutoscaler(cfg, appToScaleGUID, appToScaleName, 510, false) - sendMetricForScaleInAndReturnNumInstancesFunc := sendMetricToAutoscaler(cfg, appToScaleGUID, appToScaleName, 490, false) + sendMetricForScaleOutAndReturnNumInstancesFunc := sendMetricToAutoscaler(cfg, appToScaleGUID, appToScaleName, 510, true) + sendMetricForScaleInAndReturnNumInstancesFunc := sendMetricToAutoscaler(cfg, appToScaleGUID, appToScaleName, 490, true) By("checking that no scaling out happens before breach_duration_secs have passed") Consistently(sendMetricForScaleOutAndReturnNumInstancesFunc). diff --git a/src/acceptance/helpers/helpers.go b/src/acceptance/helpers/helpers.go index 8fe4ccfed6..0efcb6b851 100644 --- a/src/acceptance/helpers/helpers.go +++ b/src/acceptance/helpers/helpers.go @@ -67,10 +67,9 @@ type ScalingPolicy struct { } type ScalingPolicyWithExtraFields struct { - IsAdmin bool `json:"is_admin"` - IsSSO bool `json:"is_sso"` - Role string `json:"role"` - //CredentialType *string `json:"credential-type,omitempty"` + IsAdmin bool `json:"is_admin"` + IsSSO bool `json:"is_sso"` + Role string `json:"role"` InstanceMin int `json:"instance_min_count"` InstanceMax int `json:"instance_max_count"` ScalingRules []*ScalingRulesWithExtraFields `json:"scaling_rules,omitempty"` @@ -283,38 +282,6 @@ func GeneratePolicyWithCredentialType(instanceMin, instanceMax int, metricName s return string(marshaled) } -func GeneratePolicyWithExtraFields(instanceMin, instanceMax int, metricName string, scaleInWhenBelowThreshold int64, scaleOutWhenGreaterOrEqualThreshold int64, credentialType *string) string { - scalingOutRule := ScalingRule{ - MetricType: metricName, - BreachDurationSeconds: TestBreachDurationSeconds, - Threshold: scaleOutWhenGreaterOrEqualThreshold, - Operator: ">=", - CoolDownSeconds: TestCoolDownSeconds, - Adjustment: "+1", - } - scalingInRule := ScalingRule{ - MetricType: metricName, - BreachDurationSeconds: TestBreachDurationSeconds, - Threshold: scaleInWhenBelowThreshold, - Operator: "<", - CoolDownSeconds: TestCoolDownSeconds, - Adjustment: "-1", - } - policyWithExtraFields := ScalingPolicyWithExtraFields{ - IsAdmin: false, - IsSSO: false, - Role: "", - //CredentialType: credentialType, - InstanceMin: instanceMin, - InstanceMax: instanceMax, - ScalingRules: []*ScalingRulesWithExtraFields{{StatsWindowSeconds: 0, ScalingRule: scalingOutRule}, {StatsWindowSeconds: 0, ScalingRule: scalingInRule}}, - } - marshaled, err := MarshalWithoutHTMLEscape(policyWithExtraFields) - Expect(err).NotTo(HaveOccurred()) - - return string(marshaled) -} - func buildScaleOutScaleInPolicy(instanceMin int, instanceMax int, metricName string, scaleInWhenBelowThreshold int64, scaleOutWhenGreaterOrEqualThreshold int64) ScalingPolicy { scalingOutRule := ScalingRule{ MetricType: metricName,