@@ -18,6 +18,8 @@ package core
1818
1919import (
2020 "fmt"
21+ "net/http"
22+ "net/http/httptest"
2123 "regexp"
2224 "strings"
2325 "testing"
@@ -30,12 +32,14 @@ import (
3032 "k8s.io/autoscaler/cluster-autoscaler/config"
3133 "k8s.io/autoscaler/cluster-autoscaler/core/utils"
3234 "k8s.io/autoscaler/cluster-autoscaler/estimator"
35+ "k8s.io/autoscaler/cluster-autoscaler/metrics"
3336 "k8s.io/autoscaler/cluster-autoscaler/processors/nodegroupset"
3437 "k8s.io/autoscaler/cluster-autoscaler/utils/errors"
3538 kube_util "k8s.io/autoscaler/cluster-autoscaler/utils/kubernetes"
3639 . "k8s.io/autoscaler/cluster-autoscaler/utils/test"
3740 "k8s.io/autoscaler/cluster-autoscaler/utils/units"
3841 kube_record "k8s.io/client-go/tools/record"
42+ "k8s.io/component-base/metrics/legacyregistry"
3943
4044 appsv1 "k8s.io/api/apps/v1"
4145 apiv1 "k8s.io/api/core/v1"
@@ -974,17 +978,33 @@ func TestCheckScaleUpDeltaWithinLimits(t *testing.T) {
974978}
975979
976980func TestAuthError (t * testing.T ) {
981+ metrics .RegisterAll ()
977982 context , err := NewScaleTestAutoscalingContext (config.AutoscalingOptions {}, & fake.Clientset {}, nil , nil , nil )
978983 assert .NoError (t , err )
979984
980985 nodeGroup := & mockprovider.NodeGroup {}
981986 info := nodegroupset.ScaleUpInfo {Group : nodeGroup }
982987 nodeGroup .On ("Id" ).Return ("A" )
983- nodeGroup .On ("IncreaseSize" , 0 ).Return (errors .NewAutoscalerError (errors .AuthorizationError , "" ))
988+ nodeGroup .On ("IncreaseSize" , 0 ).Return (errors .NewAutoscalerError (errors .AutoscalerErrorType ( "abcd" ) , "" ))
984989
985990 clusterStateRegistry := clusterstate .NewClusterStateRegistry (nil , clusterstate.ClusterStateRegistryConfig {}, context .LogRecorder , newBackoff ())
986991
987992 aerr := executeScaleUp (& context , clusterStateRegistry , info , "" , time .Now ())
988993 assert .Error (t , aerr )
989- assert .Equal (t , errors .AuthorizationError , aerr .Type ())
994+
995+ req , err := http .NewRequest ("GET" , "/" , nil )
996+ if err != nil {
997+ t .Fatal (err )
998+ }
999+ rr := httptest .NewRecorder ()
1000+ handler := http .HandlerFunc (legacyregistry .Handler ().ServeHTTP )
1001+ handler .ServeHTTP (rr , req )
1002+
1003+ // Check that the status code is what we expect.
1004+ if status := rr .Code ; status != http .StatusOK {
1005+ t .Errorf ("handler returned wrong status code: got %v want %v" ,
1006+ status , http .StatusOK )
1007+ }
1008+ // Check that the failed scale up reason is set correctly.
1009+ assert .Contains (t , rr .Body .String (), "cluster_autoscaler_failed_scale_ups_total{reason=\" abcd\" } 1" )
9901010}
0 commit comments