Skip to content

Commit

Permalink
Fix: submit custom metrics via mTLS for lead time test
Browse files Browse the repository at this point in the history
  • Loading branch information
asalan316 committed Jan 8, 2025
1 parent 70ca560 commit 1ba24f9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 48 deletions.
23 changes: 13 additions & 10 deletions src/acceptance/app/custom_metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/acceptance/app/lead_times_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
39 changes: 3 additions & 36 deletions src/acceptance/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 1ba24f9

Please sign in to comment.