Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Custom Metrics Acceptance Test (mTLS) #2742

Merged
merged 2 commits into from
Apr 8, 2024
Merged
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
56 changes: 39 additions & 17 deletions src/acceptance/app/custom_metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app_test

import (
"acceptance"
"acceptance/config"
. "acceptance/helpers"
"time"

Expand All @@ -28,28 +29,49 @@ var _ = Describe("AutoScaler custom metrics policy", func() {
Context("when scaling by custom metrics", func() {
It("should scale out and scale in", Label(acceptance.LabelSmokeTests), func() {
By("Scale out to 2 instances")
scaleOut := func() (int, error) {
SendMetric(cfg, appName, 550)
return RunningInstances(appGUID, 5*time.Second)
}
Eventually(scaleOut, 5*time.Minute, 15*time.Second).Should(Equal(2))
scaleOut := sendMetricToAutoscaler(cfg, appGUID, appName, 550, false)
Eventually(scaleOut).
WithTimeout(5 * time.Minute).
WithPolling(15 * time.Second).
Should(Equal(2))

By("Scale in to 1 instances")
scaleIn := func() (int, error) {
SendMetric(cfg, appName, 100)
return RunningInstances(appGUID, 5*time.Second)
}
Eventually(scaleIn, 5*time.Minute, 15*time.Second).Should(Equal(1))
scaleIn := sendMetricToAutoscaler(cfg, appGUID, appName, 100, false)
Eventually(scaleIn).
WithTimeout(5 * time.Minute).
WithPolling(15 * time.Second).
Should(Equal(1))

})
})

Context("when adding custom-metrics via mtls", func() {
It("should successfully add a metric using the app", func() {
By("adding policy so test_metric is allowed")
policy = GenerateDynamicScaleOutAndInPolicy(1, 2, "test_metric", 500, 500)
By("sending metric via mtls endpoint")
SendMetricMTLS(cfg, appName, 10)
GinkgoWriter.Println("")
Context("when scaling by custom metrics via mtls", func() {
It("should scale out and scale in", Label(acceptance.LabelSmokeTests), func() {
By("Scale out to 2 instances")
scaleOut := sendMetricToAutoscaler(cfg, appGUID, appName, 550, true)
Eventually(scaleOut).
WithTimeout(5 * time.Minute).
WithPolling(15 * time.Second).
Should(Equal(2))

By("Scale in to 1 instance")
scaleIn := sendMetricToAutoscaler(cfg, appGUID, appName, 100, true)
Eventually(scaleIn).
WithTimeout(5 * time.Minute).
WithPolling(15 * time.Second).
Should(Equal(1))

})
})
})

func sendMetricToAutoscaler(config *config.Config, appGUID string, appName string, metricThreshold int, mtls bool) func() (int, error) {
return func() (int, error) {
if mtls {
SendMetricMTLS(config, appName, metricThreshold)
} else {
SendMetric(config, appName, metricThreshold)
}
return RunningInstances(appGUID, 5*time.Second)
}
}
Loading