Skip to content

Commit 78aea1f

Browse files
committed
operator prometheus e2e creates and removes multiple httpscaledobjects
Signed-off-by: Elieser Pereira <[email protected]>
1 parent 27db195 commit 78aea1f

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

tests/checks/operator_prometheus_metrics/operator_prometheus_metrics_test.go

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"strings"
99
"testing"
10+
"time"
1011

1112
prommodel "github.com/prometheus/client_model/go"
1213
"github.com/prometheus/common/expfmt"
@@ -165,20 +166,25 @@ func TestMetricGeneration(t *testing.T) {
165166
// Send a test request to the interceptor
166167
sendLoad(t, kc, data)
167168

168-
httpScaledObjecData, httpScaledObjecDataTemplates := getTemplateHTTPScaledObjecData()
169-
KubectlApplyMultipleWithTemplate(t, httpScaledObjecData, httpScaledObjecDataTemplates)
169+
CreateManyHttpScaledObjecs(t, 10)
170+
time.Sleep(time.Second * 10)
170171

171172
// Fetch metrics and validate them
172173
family := fetchAndParsePrometheusMetrics(t, fmt.Sprintf("curl --insecure %s", kedaOperatorPrometheusURL))
173174
val, ok := family["keda_http_scaled_object_total"]
174175
assert.True(t, ok, "keda_http_scaled_object_total is available")
175-
176176
httpSacaledObjectCount := getMetricsValue(val)
177-
assert.GreaterOrEqual(t, httpSacaledObjectCount, float64(1))
178-
assert.Equal(t, httpSacaledObjectCount, float64(2))
177+
assert.GreaterOrEqual(t, httpSacaledObjectCount, float64(10))
178+
179+
DeleteManyHttpScaledObjecs(t, 10)
180+
time.Sleep(time.Second * 10)
181+
// Fetch metrics and validate them after deleting httpscaledobjects
182+
family = fetchAndParsePrometheusMetrics(t, fmt.Sprintf("curl --insecure %s", kedaOperatorPrometheusURL))
183+
val, ok = family["keda_http_scaled_object_total"]
184+
httpSacaledObjectCountAfterCleanUp := getMetricsValue(val)
185+
assert.Equal(t, float64(1), httpSacaledObjectCountAfterCleanUp)
179186

180187
// cleanup
181-
KubectlDeleteMultipleWithTemplate(t, httpScaledObjecData, httpScaledObjecDataTemplates)
182188
DeleteKubernetesResources(t, testNamespace, data, templates)
183189
}
184190

@@ -239,17 +245,35 @@ func getTemplateData() (templateData, []Template) {
239245
}
240246
}
241247

242-
func getTemplateHTTPScaledObjecData() (templateData, []Template) {
248+
func getTemplateHTTPScaledObjecData(httpScaledObjecID string) (templateData, []Template) {
249+
deploymentCustom := fmt.Sprintf("other-deployment-%s", httpScaledObjecID)
250+
httpScaledObjectCustom := fmt.Sprintf("other-http-scaled-object-name-%s", httpScaledObjecID)
251+
templateName := fmt.Sprintf("otherHttpScaledObjectName-%s", httpScaledObjecID)
243252
return templateData{
244253
TestNamespace: testNamespace,
245-
DeploymentName: "OtherDeployment",
254+
DeploymentName: deploymentCustom,
246255
ServiceName: serviceName,
247256
ClientName: clientName,
248-
HTTPScaledObjectName: "OtherHttpScaledObjectName",
257+
HTTPScaledObjectName: httpScaledObjectCustom,
249258
Host: host,
250259
MinReplicas: minReplicaCount,
251260
MaxReplicas: maxReplicaCount,
252261
}, []Template{
253-
{Name: "OtherHttpScaledObjectName", Config: httpScaledObjectTemplate},
262+
{Name: templateName, Config: httpScaledObjectTemplate},
254263
}
255264
}
265+
266+
func CreateManyHttpScaledObjecs(t *testing.T, objectsCount int) {
267+
for i := 0; i < objectsCount; i++ {
268+
httpScaledObjecData, httpScaledObjecDataTemplates := getTemplateHTTPScaledObjecData(fmt.Sprintf("%d", i))
269+
KubectlApplyMultipleWithTemplate(t, httpScaledObjecData, httpScaledObjecDataTemplates)
270+
}
271+
272+
}
273+
func DeleteManyHttpScaledObjecs(t *testing.T, objectsCount int) {
274+
for i := 0; i < objectsCount; i++ {
275+
httpScaledObjecData, httpScaledObjecDataTemplates := getTemplateHTTPScaledObjecData(fmt.Sprintf("%d", i))
276+
KubectlDeleteMultipleWithTemplate(t, httpScaledObjecData, httpScaledObjecDataTemplates)
277+
}
278+
279+
}

0 commit comments

Comments
 (0)