From 0295e54edc2022dfde6666e7532f678d6bd1c102 Mon Sep 17 00:00:00 2001 From: Alan Moran Date: Fri, 16 Aug 2024 12:26:56 +0200 Subject: [PATCH] Remove envconfig dependency --- packages/metricsforwarder/spec | 1 - src/autoscaler/helpers/http_server.go | 2 +- src/autoscaler/metricsforwarder/config/config.go | 13 ++++++++----- .../metricsforwarder/config/config_test.go | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/metricsforwarder/spec b/packages/metricsforwarder/spec index 8f756ae8f8..b43e608336 100644 --- a/packages/metricsforwarder/spec +++ b/packages/metricsforwarder/spec @@ -72,7 +72,6 @@ files: - autoscaler/vendor/github.com/jackc/puddle/v2/internal/genstack/* # gosub - autoscaler/vendor/github.com/jmoiron/sqlx/* # gosub - autoscaler/vendor/github.com/jmoiron/sqlx/reflectx/* # gosub -- autoscaler/vendor/github.com/kelseyhightower/envconfig/* # gosub - autoscaler/vendor/github.com/klauspost/compress/* # gosub - autoscaler/vendor/github.com/klauspost/compress/flate/* # gosub - autoscaler/vendor/github.com/klauspost/compress/fse/* # gosub diff --git a/src/autoscaler/helpers/http_server.go b/src/autoscaler/helpers/http_server.go index 406ee55f45..20651246ca 100644 --- a/src/autoscaler/helpers/http_server.go +++ b/src/autoscaler/helpers/http_server.go @@ -12,7 +12,7 @@ import ( ) type ServerConfig struct { - Port int `yaml:"port" envconfig:"PORT"` + Port int `yaml:"port"` TLS models.TLSCerts `yaml:"tls"` } diff --git a/src/autoscaler/metricsforwarder/config/config.go b/src/autoscaler/metricsforwarder/config/config.go index 29c2af0a31..e65e0d752b 100644 --- a/src/autoscaler/metricsforwarder/config/config.go +++ b/src/autoscaler/metricsforwarder/config/config.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "os" + "strconv" "time" "github.com/cloudfoundry-community/go-cfenv" @@ -12,8 +13,6 @@ import ( "code.cloudfoundry.org/app-autoscaler/src/autoscaler/helpers" "code.cloudfoundry.org/app-autoscaler/src/autoscaler/models" - "github.com/kelseyhightower/envconfig" - "gopkg.in/yaml.v3" ) @@ -121,9 +120,13 @@ func LoadConfig(filepath string) (*Config, error) { defer r.Close() } - err = envconfig.Process("", &conf) - if err != nil { - return nil, fmt.Errorf("%w: %w", ErrReadEnvironment, err) + if os.Getenv("PORT") != "" { + port := os.Getenv("PORT") + portNumber, err := strconv.Atoi(port) + if err != nil { + return nil, fmt.Errorf("%w:%w", ErrReadEnvironment, err) + } + conf.Server.Port = portNumber } err = loadVCAPEnvs(&conf) diff --git a/src/autoscaler/metricsforwarder/config/config_test.go b/src/autoscaler/metricsforwarder/config/config_test.go index d9219a8b8d..e03a9cf7d1 100644 --- a/src/autoscaler/metricsforwarder/config/config_test.go +++ b/src/autoscaler/metricsforwarder/config/config_test.go @@ -119,7 +119,7 @@ cred_helper_impl: default It("return invalid port error", func() { Expect(err).To(MatchError(ErrReadEnvironment)) - Expect(err).To(MatchError(MatchRegexp("converting 'NAN' to type int"))) + Expect(err).To(MatchError(MatchRegexp("parsing \"NAN\": invalid syntax"))) }) AfterEach(func() {