diff --git a/src/autoscaler/api/cmd/api/api_test.go b/src/autoscaler/api/cmd/api/api_test.go index 76183d5dba..df398e612d 100644 --- a/src/autoscaler/api/cmd/api/api_test.go +++ b/src/autoscaler/api/cmd/api/api_test.go @@ -1,13 +1,14 @@ package main_test import ( - "code.cloudfoundry.org/app-autoscaler/src/autoscaler/routes" "fmt" "io" "net/http" "os" "time" + "code.cloudfoundry.org/app-autoscaler/src/autoscaler/routes" + . "code.cloudfoundry.org/app-autoscaler/src/autoscaler/testhelpers" "code.cloudfoundry.org/app-autoscaler/src/autoscaler/api/config" @@ -245,8 +246,8 @@ var _ = Describe("Api", func() { // healthendpoint.READINESS_PATH, healthendpoint.PPROF_PATH, healthendpoint.PROMETHEUS_PATH} cfg = basicAuthConfig // Setting password only for `basicAuthConfig` is not sufficient, - // since the server-process does not use that configuration. - // Alternatively, basiAuthConfig could be just a pointer. + // since the server-process does not use that configuration. + // Alternatively, basiAuthConfig could be just a pointer. runner.configPath = writeConfig(&cfg).Name() runner.Start() }) diff --git a/src/autoscaler/healthendpoint/health_readiness_test.go b/src/autoscaler/healthendpoint/health_readiness_test.go index 323a55da23..de8ba482dd 100644 --- a/src/autoscaler/healthendpoint/health_readiness_test.go +++ b/src/autoscaler/healthendpoint/health_readiness_test.go @@ -1,7 +1,6 @@ package healthendpoint_test import ( - "code.cloudfoundry.org/app-autoscaler/src/autoscaler/routes" "io" "net/http" "net/url" @@ -9,6 +8,8 @@ import ( "sync/atomic" "time" + "code.cloudfoundry.org/app-autoscaler/src/autoscaler/routes" + "code.cloudfoundry.org/app-autoscaler/src/autoscaler/models" "github.com/pkg/errors" diff --git a/src/autoscaler/healthendpoint/server.go b/src/autoscaler/healthendpoint/server.go index 7a095f78e6..6ccb9f71cd 100644 --- a/src/autoscaler/healthendpoint/server.go +++ b/src/autoscaler/healthendpoint/server.go @@ -1,13 +1,14 @@ package healthendpoint import ( - "code.cloudfoundry.org/app-autoscaler/src/autoscaler/routes" "fmt" "net/http" "net/http/pprof" "os" "time" + "code.cloudfoundry.org/app-autoscaler/src/autoscaler/routes" + "github.com/prometheus/client_golang/prometheus/promhttp" "code.cloudfoundry.org/app-autoscaler/src/autoscaler/models" @@ -35,7 +36,6 @@ func (bam *basicAuthenticationMiddleware) middleware(next http.Handler) http.Han if !authOK || bcrypt.CompareHashAndPassword(bam.usernameHash, []byte(username)) != nil || bcrypt.CompareHashAndPassword(bam.passwordHash, []byte(password)) != nil { - http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) return } @@ -47,7 +47,6 @@ func (bam *basicAuthenticationMiddleware) middleware(next http.Handler) http.Han // Make sure that username and password is not empty func NewServerWithBasicAuth(conf models.HealthConfig, healthCheckers []Checker, logger lager.Logger, gatherer prometheus.Gatherer, time func() time.Time) (ifrit.Runner, error) { - healthRouter, err := NewHealthRouterWithBasicAuth(conf, healthCheckers, logger, gatherer, time) if err != nil { return nil, err @@ -65,7 +64,6 @@ func NewServerWithBasicAuth(conf models.HealthConfig, healthCheckers []Checker, func NewHealthRouterWithBasicAuth(conf models.HealthConfig, healthCheckers []Checker, logger lager.Logger, gatherer prometheus.Gatherer, time func() time.Time) (*mux.Router, error) { - router := mux.NewRouter() authMiddleware, err := createBasicAuthMiddleware(logger, conf.HealthCheckUsernameHash, conf.HealthCheckUsername, conf.HealthCheckPasswordHash, conf.HealthCheckPassword) @@ -106,7 +104,6 @@ func NewHealthRouterWithBasicAuth(conf models.HealthConfig, healthCheckers []Che // Returns an error in case BasicAuth is required but the configuration is not set up properly. func addLivelinessHandlers(conf models.HealthConfig, mainRouter *mux.Router, time func() time.Time, authMiddleware *basicAuthenticationMiddleware) error { - livenessHandler := common.VarsFunc(readiness([]Checker{}, time)) livenessRouter := mainRouter.PathPrefix(routes.LivenessPath).Subrouter() @@ -129,7 +126,6 @@ func addLivelinessHandlers(conf models.HealthConfig, mainRouter *mux.Router, tim func addReadinessHandler(conf models.HealthConfig, mainRouter *mux.Router, authMiddleware *basicAuthenticationMiddleware, healthCheckers []Checker, time func() time.Time, ) error { - readinessRouter := mainRouter.PathPrefix("/health").Subrouter() if endpointsNeedsProtection(routes.ReadinessPath, conf) { readinessRouter.Use(authMiddleware.middleware) @@ -150,7 +146,6 @@ func addReadinessHandler(conf models.HealthConfig, mainRouter *mux.Router, // Returns an error in case BasicAuth is required but the configuration is not set up properly. func addPprofHandlers(conf models.HealthConfig, mainRouter *mux.Router, authMiddleware *basicAuthenticationMiddleware) error { - pprofRouter := mainRouter.PathPrefix(routes.PprofPath).Subrouter() if endpointsNeedsProtection(routes.PprofPath, conf) { @@ -176,7 +171,6 @@ func addPprofHandlers(conf models.HealthConfig, mainRouter *mux.Router, // Returns an error in case BasicAuth is required but the configuration is not set up properly. func addPrometheusHandler(mainRouter *mux.Router, conf models.HealthConfig, authMiddleware *basicAuthenticationMiddleware, gatherer prometheus.Gatherer) error { - promHandler := promhttp.HandlerFor(gatherer, promhttp.HandlerOpts{}) prometheusRouter := mainRouter.PathPrefix(routes.PrometheusPath).Subrouter() diff --git a/src/autoscaler/integration/components_test.go b/src/autoscaler/integration/components_test.go index ccbdfb3f5a..121c93d77c 100644 --- a/src/autoscaler/integration/components_test.go +++ b/src/autoscaler/integration/components_test.go @@ -216,7 +216,7 @@ func (components *Components) PrepareGolangApiServerConfig(dbURI string, publicA }, Health: models.HealthConfig{ UnprotectedEndpoints: []string{"", routes.LivenessPath, - routes.ReadinessPath, routes.PrometheusPath, routes.PprofPath}}, + routes.ReadinessPath, routes.PrometheusPath, routes.PprofPath}}, PublicApiServer: apiConfig.ServerConfig{ Port: publicApiPort, TLS: models.TLSCerts{ @@ -397,7 +397,7 @@ func (components *Components) PrepareEventGeneratorConfig(dbUri string, port int }, Health: models.HealthConfig{ UnprotectedEndpoints: []string{"", routes.LivenessPath, - routes.ReadinessPath, routes.PrometheusPath, routes.PprofPath}}, + routes.ReadinessPath, routes.PrometheusPath, routes.PprofPath}}, Server: egConfig.ServerConfig{ Port: port, TLS: models.TLSCerts{ @@ -462,7 +462,7 @@ func (components *Components) PrepareScalingEngineConfig(dbURI string, port int, }, Health: models.HealthConfig{ UnprotectedEndpoints: []string{"", routes.LivenessPath, - routes.ReadinessPath, routes.PrometheusPath, routes.PprofPath}}, + routes.ReadinessPath, routes.PrometheusPath, routes.PprofPath}}, Server: seConfig.ServerConfig{ Port: port, TLS: models.TLSCerts{ @@ -500,7 +500,7 @@ func (components *Components) PrepareOperatorConfig(dbURI string, ccUAAURL strin }, Health: models.HealthConfig{ UnprotectedEndpoints: []string{"", routes.LivenessPath, - routes.ReadinessPath, routes.PrometheusPath, routes.PprofPath}}, + routes.ReadinessPath, routes.PrometheusPath, routes.PprofPath}}, CF: cf.Config{ API: ccUAAURL, ClientID: "admin", @@ -570,7 +570,7 @@ func (components *Components) PrepareMetricsGatewayConfig(dbURI string, metricSe }, Health: models.HealthConfig{ UnprotectedEndpoints: []string{"", routes.LivenessPath, - routes.ReadinessPath, routes.PrometheusPath, routes.PprofPath}}, + routes.ReadinessPath, routes.PrometheusPath, routes.PprofPath}}, EnvelopChanSize: 500, NozzleCount: 1, MetricServerAddrs: metricServerAddresses, @@ -616,7 +616,7 @@ func (components *Components) PrepareMetricsServerConfig(dbURI string, httpClien }, Health: models.HealthConfig{ UnprotectedEndpoints: []string{"", routes.LivenessPath, - routes.ReadinessPath, routes.PrometheusPath, routes.PprofPath}}, + routes.ReadinessPath, routes.PrometheusPath, routes.PprofPath}}, HttpClientTimeout: httpClientTimeout, NodeAddrs: []string{"localhost"}, NodeIndex: 0,