Skip to content

Commit

Permalink
wip: custom metrics with binding secret
Browse files Browse the repository at this point in the history
  • Loading branch information
asalan316 committed Jan 7, 2025
1 parent 27b5ce2 commit 57ddefa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
10 changes: 7 additions & 3 deletions src/acceptance/app/custom_metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ var _ = Describe("AutoScaler custom metrics", func() {

Describe("custom metrics policy for same app", func() {
BeforeEach(func() {
policy = GenerateDynamicScaleOutAndInPolicy(1, 2, "test_metric", 500, 500)
policy = GeneratePolicyWithCredentialType(
1, 2, "test_metric", 500, 500,
"binding-secret")
instanceName = CreatePolicy(cfg, appToScaleName, appToScaleGUID, policy)
StartApp(appToScaleName, cfg.CfPushTimeoutDuration())
})
// This test will fail if credential-type is set to X509 in autoscaler broker.
// Therefore, only mtls connection will be supported for custom metrics in future
/*
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.
Added test for rollback cases where custom metrics are still sent via basic auth route.
*/
Context("when scaling by custom metrics", func() {
It("should scale out and scale in", Label(acceptance.LabelSmokeTests), func() {
By("Scale out to 2 instances")
Expand Down
30 changes: 20 additions & 10 deletions src/acceptance/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ func (b *BindingConfig) SetCustomMetricsStrategy(allowFrom string) {
}

type ScalingPolicy struct {
InstanceMin int `json:"instance_min_count"`
InstanceMax int `json:"instance_max_count"`
ScalingRules []*ScalingRule `json:"scaling_rules,omitempty"`
Schedules *ScalingSchedules `json:"schedules,omitempty"`
InstanceMin int `json:"instance_min_count"`
InstanceMax int `json:"instance_max_count"`
ScalingRules []*ScalingRule `json:"scaling_rules,omitempty"`
Schedules *ScalingSchedules `json:"schedules,omitempty"`
CredentialType *string `json:"credential_type,omitempty"`
}

type ScalingPolicyWithExtraFields struct {
Expand Down Expand Up @@ -191,7 +192,7 @@ func GenerateBindingsWithScalingPolicy(allowFrom string, instanceMin, instanceMa
Configuration: Configuration{CustomMetrics: CustomMetricsConfig{
MetricSubmissionStrategy: MetricsSubmissionStrategy{AllowFrom: allowFrom},
}},
ScalingPolicy: buildScaleOutScaleInPolicy(instanceMin, instanceMax, metricName, scaleInThreshold, scaleOutThreshold),
ScalingPolicy: buildScaleOutScaleInPolicy(instanceMin, instanceMax, metricName, scaleInThreshold, scaleOutThreshold, ""),
}
marshalledBinding, err := MarshalWithoutHTMLEscape(bindingConfig)
Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -265,14 +266,22 @@ func GenerateDynamicScaleOutPolicyWithExtraFields(instanceMin, instanceMax int,
}

func GenerateDynamicScaleOutAndInPolicy(instanceMin, instanceMax int, metricName string, scaleInWhenBelowThreshold int64, scaleOutWhenGreaterOrEqualThreshold int64) string {
policy := buildScaleOutScaleInPolicy(instanceMin, instanceMax, metricName, scaleInWhenBelowThreshold, scaleOutWhenGreaterOrEqualThreshold)
policy := buildScaleOutScaleInPolicy(instanceMin, instanceMax, metricName, scaleInWhenBelowThreshold, scaleOutWhenGreaterOrEqualThreshold, "")
marshaled, err := MarshalWithoutHTMLEscape(policy)
Expect(err).NotTo(HaveOccurred())

return string(marshaled)
}

func buildScaleOutScaleInPolicy(instanceMin int, instanceMax int, metricName string, scaleInWhenBelowThreshold int64, scaleOutWhenGreaterOrEqualThreshold int64) ScalingPolicy {
func GeneratePolicyWithCredentialType(instanceMin, instanceMax int, metricName string, scaleInWhenBelowThreshold int64, scaleOutWhenGreaterOrEqualThreshold int64, credentialType string) string {
policyWithCredentialType := buildScaleOutScaleInPolicy(instanceMin, instanceMax, metricName, scaleInWhenBelowThreshold, scaleOutWhenGreaterOrEqualThreshold, credentialType)
marshaled, err := MarshalWithoutHTMLEscape(policyWithCredentialType)
Expect(err).NotTo(HaveOccurred())

return string(marshaled)
}

func buildScaleOutScaleInPolicy(instanceMin int, instanceMax int, metricName string, scaleInWhenBelowThreshold int64, scaleOutWhenGreaterOrEqualThreshold int64, credentialType string) ScalingPolicy {
scalingOutRule := ScalingRule{
MetricType: metricName,
BreachDurationSeconds: TestBreachDurationSeconds,
Expand All @@ -290,9 +299,10 @@ func buildScaleOutScaleInPolicy(instanceMin int, instanceMax int, metricName str
Adjustment: "-1",
}
policy := ScalingPolicy{
InstanceMin: instanceMin,
InstanceMax: instanceMax,
ScalingRules: []*ScalingRule{&scalingOutRule, &scalingInRule},
InstanceMin: instanceMin,
InstanceMax: instanceMax,
ScalingRules: []*ScalingRule{&scalingOutRule, &scalingInRule},
CredentialType: &credentialType,
}
return policy
}
Expand Down

0 comments on commit 57ddefa

Please sign in to comment.