Skip to content

Commit

Permalink
Fix precommit CI check and failed test in proemtheus_scaler_test and …
Browse files Browse the repository at this point in the history
…scaledobject_controller_test

Signed-off-by: dttung2905 <ttdao.2015@accountancy.smu.edu.sg>
  • Loading branch information
dttung2905 committed Aug 5, 2023
1 parent 172528b commit 6611c38
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion apis/keda/v1alpha1/scaledobject_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func validateWorkload(so *ScaledObject, action string) (admission.Warnings, erro
}

func verifyTriggers(incomingSo *ScaledObject, action string) error {
err := ValidateTriggers(scaledobjectlog.WithValues("name", incomingSo.Name), incomingSo.Spec.Triggers)
err := ValidateTriggers(incomingSo.Spec.Triggers)
if err != nil {
scaledobjectlog.WithValues("name", incomingSo.Name).Error(err, "validation error")
prommetrics.RecordScaledObjectValidatingErrors(incomingSo.Namespace, action, "incorrect-triggers")
Expand Down
3 changes: 1 addition & 2 deletions apis/keda/v1alpha1/scaletriggers_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package v1alpha1
import (
"fmt"

"github.com/go-logr/logr"
autoscalingv2 "k8s.io/api/autoscaling/v2"
)

Expand Down Expand Up @@ -50,7 +49,7 @@ type AuthenticationRef struct {
// ValidateTriggers checks that general trigger metadata are valid, it checks:
// - triggerNames in ScaledObject are unique
// - useCachedMetrics is defined only for a supported triggers
func ValidateTriggers(logger logr.Logger, triggers []ScaleTriggers) error {
func ValidateTriggers(triggers []ScaleTriggers) error {
triggersCount := len(triggers)
if triggers != nil && triggersCount > 0 {
triggerNames := make(map[string]bool, triggersCount)
Expand Down
3 changes: 1 addition & 2 deletions apis/keda/v1alpha1/scaletriggers_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package v1alpha1
import (
"testing"

"github.com/go-logr/logr"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -90,7 +89,7 @@ func TestValidateTriggers(t *testing.T) {
for _, test := range tests {
tt := test
t.Run(test.name, func(t *testing.T) {
err := ValidateTriggers(logr.Discard(), tt.triggers)
err := ValidateTriggers(tt.triggers)
if test.expectedErrMsg == "" {
assert.NoError(t, err)
} else {
Expand Down
2 changes: 1 addition & 1 deletion controllers/keda/scaledobject_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (r *ScaledObjectReconciler) reconcileScaledObject(ctx context.Context, logg
return "ScaledObject doesn't have correct Idle/Min/Max Replica Counts specification", err
}

err = kedav1alpha1.ValidateTriggers(logger, scaledObject.Spec.Triggers)
err = kedav1alpha1.ValidateTriggers(scaledObject.Spec.Triggers)
if err != nil {
return "ScaledObject doesn't have correct triggers specification", err
}
Expand Down
4 changes: 2 additions & 2 deletions controllers/keda/scaledobject_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ var _ = Describe("ScaledObjectController", func() {
)

var triggerMeta = []map[string]string{
{"serverAddress": "http://localhost:9090", "metricName": "http_requests_total", "threshold": "100", "query": "up", "disableScaleToZero": "true"},
{"serverAddress": "http://localhost:9090", "metricName": "http_requests_total2", "threshold": "100", "query": "up"},
{"serverAddress": "http://localhost:9090", "threshold": "100", "query": "up", "disableScaleToZero": "true"},
}

BeforeEach(func() {
Expand Down Expand Up @@ -221,6 +220,7 @@ var _ = Describe("ScaledObjectController", func() {

// Call function tobe tested
metricSpecs, err := metricNameTestReconciler.getScaledObjectMetricSpecs(context.Background(), testLogger, duplicateNamedScaledObject)
Ω(err).ShouldNot(BeNil())

// Test that the status was not updated
Ω(duplicateNamedScaledObject.Status.ExternalMetricNames).Should(BeNil())
Expand Down
6 changes: 3 additions & 3 deletions pkg/scalers/prometheus_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var testPromMetadata = []parsePrometheusMetadataTestData{
// all properly formed
{map[string]string{"serverAddress": "http://localhost:9090", "metricName": "http_requests_total", "threshold": "100", "query": "up"}, false},
// all properly formed, with namespace
{map[string]string{"serverAddress": "http://localhost:9090", "metricName": "http_requests_total", "threshold": "100", "query": "up", "namespace": "foo"}, false},
{map[string]string{"serverAddress": "http://localhost:9090", "threshold": "100", "query": "up", "namespace": "foo"}, false},
// all properly formed, with ignoreNullValues
{map[string]string{"serverAddress": "http://localhost:9090", "metricName": "http_requests_total", "threshold": "100", "query": "up", "ignoreNullValues": "false"}, false},
// all properly formed, with activationThreshold
Expand Down Expand Up @@ -63,8 +63,8 @@ var testPromMetadata = []parsePrometheusMetadataTestData{
}

var prometheusMetricIdentifiers = []prometheusMetricIdentifier{
{&testPromMetadata[1], 0, "s0-prometheus-http_requests_total"},
{&testPromMetadata[1], 1, "s1-prometheus-http_requests_total"},
{&testPromMetadata[1], 0, "s0-prometheus-prometheus"},
{&testPromMetadata[1], 1, "s1-prometheus-prometheus"},
}

type prometheusAuthMetadataTestData struct {
Expand Down

0 comments on commit 6611c38

Please sign in to comment.