From c181db81a6d080df4a11a5f7ae916426b51f0e77 Mon Sep 17 00:00:00 2001 From: Andrew Mains Date: Tue, 22 Oct 2019 15:30:19 -0400 Subject: [PATCH] Deprecate listenaddress --- CHANGELOG.md | 2 + .../development/m3_stack/m3coordinator.yml | 1 - .../aggregator/m3coordinator.yml | 1 - .../carbon/m3coordinator.yml | 1 - .../cold_writes_simple/m3coordinator.yml | 1 - .../m3dbnode.yml | 1 - .../m3coordinator-cluster-a.yml | 1 - .../m3coordinator-cluster-b.yml | 1 - .../prometheus/m3coordinator.yml | 1 - .../m3coordinator01.yml | 1 - .../m3coordinator02.yml | 1 - .../query_fanout/m3coordinator-cluster-a.yml | 1 - .../query_fanout/m3coordinator-cluster-b.yml | 1 - .../query_fanout/m3coordinator-cluster-c.yml | 1 - .../repair/m3coordinator.yml | 1 - .../m3coordinator-cluster-a.yml | 1 - .../m3coordinator-cluster-b.yml | 1 - .../replication/m3coordinator-cluster-a.yml | 1 - .../replication/m3coordinator-cluster-b.yml | 1 - .../simple_v2_batch_apis/m3coordinator.yml | 1 - .../m3query/config/testdata/config.yml | 1 - .../m3query/config/testdata/config_test.yml | 1 - src/dbnode/config/m3dbnode-all-config.yml | 1 - .../config/m3dbnode-cluster-template.yml | 1 - .../config/m3dbnode-local-etcd-proto.yml | 1 - src/dbnode/config/m3dbnode-local-etcd.yml | 1 - .../config/m3coordinator-cluster-template.yml | 1 - src/query/config/m3coordinator-local-etcd.yml | 1 - src/query/config/m3query-dev-etcd.yml | 1 - src/query/config/m3query-local-etcd.yml | 1 - src/x/config/listenaddress/listenaddress.go | 45 ++++++++++++++----- .../listenaddress/listenaddress_test.go | 39 ++++++++++------ 32 files changed, 61 insertions(+), 54 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bc25afb69..a96b186e01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ## Features - **Config**: support env var expansion using go.uber.org/config. +- **Config**: Deprecate listenaddress expansion in favor of go.uber.org/config +env var expansion ([#2017](https://github.com/m3db/m3/pull/2017/files)) # 0.14.1 diff --git a/scripts/development/m3_stack/m3coordinator.yml b/scripts/development/m3_stack/m3coordinator.yml index 3f6865ff2a..4c7108c4e4 100644 --- a/scripts/development/m3_stack/m3coordinator.yml +++ b/scripts/development/m3_stack/m3coordinator.yml @@ -1,5 +1,4 @@ listenAddress: - type: "config" value: "0.0.0.0:7201" logging: diff --git a/scripts/docker-integration-tests/aggregator/m3coordinator.yml b/scripts/docker-integration-tests/aggregator/m3coordinator.yml index 33f977a537..2b1c9b68b7 100644 --- a/scripts/docker-integration-tests/aggregator/m3coordinator.yml +++ b/scripts/docker-integration-tests/aggregator/m3coordinator.yml @@ -1,5 +1,4 @@ listenAddress: - type: "config" value: "0.0.0.0:7202" logging: diff --git a/scripts/docker-integration-tests/carbon/m3coordinator.yml b/scripts/docker-integration-tests/carbon/m3coordinator.yml index 26e7bb8fb0..ff075d84bc 100644 --- a/scripts/docker-integration-tests/carbon/m3coordinator.yml +++ b/scripts/docker-integration-tests/carbon/m3coordinator.yml @@ -1,5 +1,4 @@ listenAddress: - type: "config" value: "0.0.0.0:7201" logging: diff --git a/scripts/docker-integration-tests/cold_writes_simple/m3coordinator.yml b/scripts/docker-integration-tests/cold_writes_simple/m3coordinator.yml index 466079145a..6c6ebd622c 100644 --- a/scripts/docker-integration-tests/cold_writes_simple/m3coordinator.yml +++ b/scripts/docker-integration-tests/cold_writes_simple/m3coordinator.yml @@ -1,5 +1,4 @@ listenAddress: - type: "config" value: "0.0.0.0:7201" logging: diff --git a/scripts/docker-integration-tests/dedicated_etcd_embedded_coordinator/m3dbnode.yml b/scripts/docker-integration-tests/dedicated_etcd_embedded_coordinator/m3dbnode.yml index 53431cc430..6c793f8330 100644 --- a/scripts/docker-integration-tests/dedicated_etcd_embedded_coordinator/m3dbnode.yml +++ b/scripts/docker-integration-tests/dedicated_etcd_embedded_coordinator/m3dbnode.yml @@ -1,6 +1,5 @@ coordinator: listenAddress: - type: "config" value: "0.0.0.0:7201" logging: diff --git a/scripts/docker-integration-tests/multi_cluster_write/m3coordinator-cluster-a.yml b/scripts/docker-integration-tests/multi_cluster_write/m3coordinator-cluster-a.yml index 4da4151a28..e31c37acdc 100644 --- a/scripts/docker-integration-tests/multi_cluster_write/m3coordinator-cluster-a.yml +++ b/scripts/docker-integration-tests/multi_cluster_write/m3coordinator-cluster-a.yml @@ -1,5 +1,4 @@ listenAddress: - type: "config" value: "0.0.0.0:7201" logging: diff --git a/scripts/docker-integration-tests/multi_cluster_write/m3coordinator-cluster-b.yml b/scripts/docker-integration-tests/multi_cluster_write/m3coordinator-cluster-b.yml index 9a74154728..b13af81125 100644 --- a/scripts/docker-integration-tests/multi_cluster_write/m3coordinator-cluster-b.yml +++ b/scripts/docker-integration-tests/multi_cluster_write/m3coordinator-cluster-b.yml @@ -1,5 +1,4 @@ listenAddress: - type: "config" value: "0.0.0.0:7201" logging: diff --git a/scripts/docker-integration-tests/prometheus/m3coordinator.yml b/scripts/docker-integration-tests/prometheus/m3coordinator.yml index 886309208b..305f200b7f 100644 --- a/scripts/docker-integration-tests/prometheus/m3coordinator.yml +++ b/scripts/docker-integration-tests/prometheus/m3coordinator.yml @@ -1,5 +1,4 @@ listenAddress: - type: "config" value: "0.0.0.0:7201" logging: diff --git a/scripts/docker-integration-tests/prometheus_replication/m3coordinator01.yml b/scripts/docker-integration-tests/prometheus_replication/m3coordinator01.yml index 7cb55470b6..2a559916c2 100644 --- a/scripts/docker-integration-tests/prometheus_replication/m3coordinator01.yml +++ b/scripts/docker-integration-tests/prometheus_replication/m3coordinator01.yml @@ -1,5 +1,4 @@ listenAddress: - type: "config" value: "0.0.0.0:7201" logging: diff --git a/scripts/docker-integration-tests/prometheus_replication/m3coordinator02.yml b/scripts/docker-integration-tests/prometheus_replication/m3coordinator02.yml index bb002d124c..9a2d14308f 100644 --- a/scripts/docker-integration-tests/prometheus_replication/m3coordinator02.yml +++ b/scripts/docker-integration-tests/prometheus_replication/m3coordinator02.yml @@ -1,5 +1,4 @@ listenAddress: - type: "config" value: "0.0.0.0:7201" logging: diff --git a/scripts/docker-integration-tests/query_fanout/m3coordinator-cluster-a.yml b/scripts/docker-integration-tests/query_fanout/m3coordinator-cluster-a.yml index ebae58ac82..3345e80a63 100644 --- a/scripts/docker-integration-tests/query_fanout/m3coordinator-cluster-a.yml +++ b/scripts/docker-integration-tests/query_fanout/m3coordinator-cluster-a.yml @@ -1,5 +1,4 @@ listenAddress: - type: "config" value: "0.0.0.0:7201" logging: diff --git a/scripts/docker-integration-tests/query_fanout/m3coordinator-cluster-b.yml b/scripts/docker-integration-tests/query_fanout/m3coordinator-cluster-b.yml index 6ca2245f86..769e3f8ffb 100644 --- a/scripts/docker-integration-tests/query_fanout/m3coordinator-cluster-b.yml +++ b/scripts/docker-integration-tests/query_fanout/m3coordinator-cluster-b.yml @@ -1,5 +1,4 @@ listenAddress: - type: "config" value: "0.0.0.0:7201" logging: diff --git a/scripts/docker-integration-tests/query_fanout/m3coordinator-cluster-c.yml b/scripts/docker-integration-tests/query_fanout/m3coordinator-cluster-c.yml index ee7ff4bcf8..3924603001 100644 --- a/scripts/docker-integration-tests/query_fanout/m3coordinator-cluster-c.yml +++ b/scripts/docker-integration-tests/query_fanout/m3coordinator-cluster-c.yml @@ -1,5 +1,4 @@ listenAddress: - type: "config" value: "0.0.0.0:7201" logging: diff --git a/scripts/docker-integration-tests/repair/m3coordinator.yml b/scripts/docker-integration-tests/repair/m3coordinator.yml index 466079145a..6c6ebd622c 100644 --- a/scripts/docker-integration-tests/repair/m3coordinator.yml +++ b/scripts/docker-integration-tests/repair/m3coordinator.yml @@ -1,5 +1,4 @@ listenAddress: - type: "config" value: "0.0.0.0:7201" logging: diff --git a/scripts/docker-integration-tests/repair_and_replication/m3coordinator-cluster-a.yml b/scripts/docker-integration-tests/repair_and_replication/m3coordinator-cluster-a.yml index 4da4151a28..e31c37acdc 100644 --- a/scripts/docker-integration-tests/repair_and_replication/m3coordinator-cluster-a.yml +++ b/scripts/docker-integration-tests/repair_and_replication/m3coordinator-cluster-a.yml @@ -1,5 +1,4 @@ listenAddress: - type: "config" value: "0.0.0.0:7201" logging: diff --git a/scripts/docker-integration-tests/repair_and_replication/m3coordinator-cluster-b.yml b/scripts/docker-integration-tests/repair_and_replication/m3coordinator-cluster-b.yml index 9a74154728..b13af81125 100644 --- a/scripts/docker-integration-tests/repair_and_replication/m3coordinator-cluster-b.yml +++ b/scripts/docker-integration-tests/repair_and_replication/m3coordinator-cluster-b.yml @@ -1,5 +1,4 @@ listenAddress: - type: "config" value: "0.0.0.0:7201" logging: diff --git a/scripts/docker-integration-tests/replication/m3coordinator-cluster-a.yml b/scripts/docker-integration-tests/replication/m3coordinator-cluster-a.yml index 4da4151a28..e31c37acdc 100644 --- a/scripts/docker-integration-tests/replication/m3coordinator-cluster-a.yml +++ b/scripts/docker-integration-tests/replication/m3coordinator-cluster-a.yml @@ -1,5 +1,4 @@ listenAddress: - type: "config" value: "0.0.0.0:7201" logging: diff --git a/scripts/docker-integration-tests/replication/m3coordinator-cluster-b.yml b/scripts/docker-integration-tests/replication/m3coordinator-cluster-b.yml index 9a74154728..b13af81125 100644 --- a/scripts/docker-integration-tests/replication/m3coordinator-cluster-b.yml +++ b/scripts/docker-integration-tests/replication/m3coordinator-cluster-b.yml @@ -1,5 +1,4 @@ listenAddress: - type: "config" value: "0.0.0.0:7201" logging: diff --git a/scripts/docker-integration-tests/simple_v2_batch_apis/m3coordinator.yml b/scripts/docker-integration-tests/simple_v2_batch_apis/m3coordinator.yml index beffe0f668..1f9333bdec 100644 --- a/scripts/docker-integration-tests/simple_v2_batch_apis/m3coordinator.yml +++ b/scripts/docker-integration-tests/simple_v2_batch_apis/m3coordinator.yml @@ -1,5 +1,4 @@ listenAddress: - type: "config" value: "0.0.0.0:7201" logging: diff --git a/src/cmd/services/m3query/config/testdata/config.yml b/src/cmd/services/m3query/config/testdata/config.yml index ff56bc388c..0e27dfe751 100644 --- a/src/cmd/services/m3query/config/testdata/config.yml +++ b/src/cmd/services/m3query/config/testdata/config.yml @@ -1,5 +1,4 @@ listenAddress: - type: "config" value: "0.0.0.0:7201" logging: diff --git a/src/cmd/services/m3query/config/testdata/config_test.yml b/src/cmd/services/m3query/config/testdata/config_test.yml index 75c557e2c7..f8e982ed1a 100644 --- a/src/cmd/services/m3query/config/testdata/config_test.yml +++ b/src/cmd/services/m3query/config/testdata/config_test.yml @@ -1,5 +1,4 @@ listenAddress: - type: "config" value: "0.0.0.0:7201" logging: diff --git a/src/dbnode/config/m3dbnode-all-config.yml b/src/dbnode/config/m3dbnode-all-config.yml index fa38d12e4a..9c3064ab92 100644 --- a/src/dbnode/config/m3dbnode-all-config.yml +++ b/src/dbnode/config/m3dbnode-all-config.yml @@ -2,7 +2,6 @@ coordinator: # Address for M3Coordinator to listen for traffic. listenAddress: - type: "config" value: "0.0.0.0:7201" # All configured M3DB namespaces must be listed in this config if running an diff --git a/src/dbnode/config/m3dbnode-cluster-template.yml b/src/dbnode/config/m3dbnode-cluster-template.yml index 2092996aed..23b5c9b223 100644 --- a/src/dbnode/config/m3dbnode-cluster-template.yml +++ b/src/dbnode/config/m3dbnode-cluster-template.yml @@ -1,6 +1,5 @@ coordinator: listenAddress: - type: "config" value: "0.0.0.0:7201" local: diff --git a/src/dbnode/config/m3dbnode-local-etcd-proto.yml b/src/dbnode/config/m3dbnode-local-etcd-proto.yml index 604283ca88..7cae28ed10 100644 --- a/src/dbnode/config/m3dbnode-local-etcd-proto.yml +++ b/src/dbnode/config/m3dbnode-local-etcd-proto.yml @@ -1,6 +1,5 @@ coordinator: listenAddress: - type: "config" value: "0.0.0.0:7201" local: diff --git a/src/dbnode/config/m3dbnode-local-etcd.yml b/src/dbnode/config/m3dbnode-local-etcd.yml index 608574a06f..6970916644 100644 --- a/src/dbnode/config/m3dbnode-local-etcd.yml +++ b/src/dbnode/config/m3dbnode-local-etcd.yml @@ -1,6 +1,5 @@ coordinator: listenAddress: - type: "config" value: "0.0.0.0:7201" local: diff --git a/src/query/config/m3coordinator-cluster-template.yml b/src/query/config/m3coordinator-cluster-template.yml index 30164edf0d..dd6167eb34 100644 --- a/src/query/config/m3coordinator-cluster-template.yml +++ b/src/query/config/m3coordinator-cluster-template.yml @@ -1,5 +1,4 @@ listenAddress: - type: "config" value: "0.0.0.0:7201" logging: diff --git a/src/query/config/m3coordinator-local-etcd.yml b/src/query/config/m3coordinator-local-etcd.yml index 6ea968a031..3c4afc7137 100644 --- a/src/query/config/m3coordinator-local-etcd.yml +++ b/src/query/config/m3coordinator-local-etcd.yml @@ -1,5 +1,4 @@ listenAddress: - type: "config" value: "0.0.0.0:7201" logging: diff --git a/src/query/config/m3query-dev-etcd.yml b/src/query/config/m3query-dev-etcd.yml index 3a6d14994f..09c1278e6b 100644 --- a/src/query/config/m3query-dev-etcd.yml +++ b/src/query/config/m3query-dev-etcd.yml @@ -2,7 +2,6 @@ # resources (threads primarily). listenAddress: - type: "config" value: "0.0.0.0:7201" logging: diff --git a/src/query/config/m3query-local-etcd.yml b/src/query/config/m3query-local-etcd.yml index 1054ec5eb5..bc97a8000d 100644 --- a/src/query/config/m3query-local-etcd.yml +++ b/src/query/config/m3query-local-etcd.yml @@ -1,5 +1,4 @@ listenAddress: - type: "config" value: "0.0.0.0:7201" logging: diff --git a/src/x/config/listenaddress/listenaddress.go b/src/x/config/listenaddress/listenaddress.go index 8ae2ced271..1f0d6354f5 100644 --- a/src/x/config/listenaddress/listenaddress.go +++ b/src/x/config/listenaddress/listenaddress.go @@ -20,6 +20,21 @@ // Package listenaddress provides a configuration struct for resolving // a listen address from YAML. +// +// Deprecation notice: +// The environment resolution behavior of this +// class has largely been superseded +// by config environment interpolation in go.uber.org/config (see config/README.md for +// details). Instead of: +// +// listenAddress: +// type: environment +// envVarListenPort: MY_PORT_VAR +// +// one can do: +// +// listenAddress: +// value: 0.0.0.0:${MY_PORT_VAR} package listenaddress import ( @@ -45,22 +60,30 @@ const ( // Configuration is the configuration for resolving a listen address. type Configuration struct { - // ListenAddressType is the port type for the port - ListenAddressType Resolver `yaml:"type" validate:"nonzero"` + // DeprecatedListenAddressType is the port type for the port + // DEPRECATED: use config interpolation with `value` (config/README.md) + DeprecatedListenAddressType Resolver `yaml:"type"` // Value is the config specified listen address if using config port type. Value *string `yaml:"value"` // EnvVarListenPort specifies the environment variable name for the listen address port. - EnvVarListenPort *string `yaml:"envVarListenPort"` + // DEPRECATED: use config interpolation with `value` (config/README.md) + DeprecatedEnvVarListenPort *string `yaml:"envVarListenPort"` - // EnvVarListenHost specifies the environment variable name for the listen address hostname. - EnvVarListenHost *string `yaml:"envVarListenHost"` + // DeprecatedEnvVarListenHost specifies the environment variable name for the listen address hostname. + // DEPRECATED: use config interpolation with `value` (config/README.md) + DeprecatedEnvVarListenHost *string `yaml:"envVarListenHost"` } // Resolve returns the resolved listen address given the configuration. func (c Configuration) Resolve() (string, error) { - listenAddrType := c.ListenAddressType + listenAddrType := c.DeprecatedListenAddressType + + if listenAddrType == "" { + // Default to ConfigResolver + listenAddrType = ConfigResolver + } var listenAddress string switch listenAddrType { @@ -74,23 +97,23 @@ func (c Configuration) Resolve() (string, error) { case EnvironmentResolver: // environment variable for port is required - if c.EnvVarListenPort == nil { + if c.DeprecatedEnvVarListenPort == nil { err := fmt.Errorf("missing port env var name using: resolver=%s", string(listenAddrType)) return "", err } - portStr := os.Getenv(*c.EnvVarListenPort) + portStr := os.Getenv(*c.DeprecatedEnvVarListenPort) port, err := strconv.Atoi(portStr) if err != nil { err := fmt.Errorf("invalid port env var value using: resolver=%s, name=%s", - string(listenAddrType), *c.EnvVarListenPort) + string(listenAddrType), *c.DeprecatedEnvVarListenPort) return "", err } // if environment variable for hostname is not set, use the default - if c.EnvVarListenHost == nil { + if c.DeprecatedEnvVarListenHost == nil { listenAddress = fmt.Sprintf("%s:%d", defaultHostname, port) } else { - envHost := os.Getenv(*c.EnvVarListenHost) + envHost := os.Getenv(*c.DeprecatedEnvVarListenHost) listenAddress = fmt.Sprintf("%s:%d", envHost, port) } diff --git a/src/x/config/listenaddress/listenaddress_test.go b/src/x/config/listenaddress/listenaddress_test.go index 074edbd198..7d6ede6b9b 100644 --- a/src/x/config/listenaddress/listenaddress_test.go +++ b/src/x/config/listenaddress/listenaddress_test.go @@ -38,8 +38,19 @@ var ( func TestListenAddressResolver(t *testing.T) { cfg := Configuration{ - ListenAddressType: ConfigResolver, - Value: &defaultListen, + DeprecatedListenAddressType: ConfigResolver, + Value: &defaultListen, + } + + value, err := cfg.Resolve() + require.NoError(t, err) + + assert.Equal(t, defaultListen, value) +} + +func TestListenAddressResolverDefaultsToConfigResolver(t *testing.T) { + cfg := Configuration{ + Value: &defaultListen, } value, err := cfg.Resolve() @@ -50,7 +61,7 @@ func TestListenAddressResolver(t *testing.T) { func TestConfigResolverErrorWhenMissing(t *testing.T) { cfg := Configuration{ - ListenAddressType: ConfigResolver, + DeprecatedListenAddressType: ConfigResolver, } _, err := cfg.Resolve() @@ -63,8 +74,8 @@ func TestEnvironmentVariableResolverWithDefault(t *testing.T) { require.NoError(t, os.Setenv(envListenPort, envPort)) cfg := Configuration{ - ListenAddressType: EnvironmentResolver, - EnvVarListenPort: &envListenPort, + DeprecatedListenAddressType: EnvironmentResolver, + DeprecatedEnvVarListenPort: &envListenPort, } value, err := cfg.Resolve() @@ -81,9 +92,9 @@ func TestEnvironmentVariableResolver(t *testing.T) { require.NoError(t, os.Setenv(envListenHost, envHost)) cfg := Configuration{ - ListenAddressType: EnvironmentResolver, - EnvVarListenPort: &envListenPort, - EnvVarListenHost: &envListenHost, + DeprecatedListenAddressType: EnvironmentResolver, + DeprecatedEnvVarListenPort: &envListenPort, + DeprecatedEnvVarListenHost: &envListenHost, } value, err := cfg.Resolve() @@ -99,8 +110,8 @@ func TestInvalidEnvironmentVariableResolver(t *testing.T) { require.NoError(t, os.Setenv(varName, expected)) cfg := Configuration{ - ListenAddressType: EnvironmentResolver, - EnvVarListenPort: &varName, + DeprecatedListenAddressType: EnvironmentResolver, + DeprecatedEnvVarListenPort: &varName, } _, err := cfg.Resolve() @@ -109,7 +120,7 @@ func TestInvalidEnvironmentVariableResolver(t *testing.T) { func TestEnvironmentResolverErrorWhenNameMissing(t *testing.T) { cfg := Configuration{ - ListenAddressType: EnvironmentResolver, + DeprecatedListenAddressType: EnvironmentResolver, } _, err := cfg.Resolve() @@ -120,8 +131,8 @@ func TestEnvironmentResolverErrorWhenValueMissing(t *testing.T) { varName := "OTHER_LISTEN_ENV_PORT" cfg := Configuration{ - ListenAddressType: EnvironmentResolver, - EnvVarListenPort: &varName, + DeprecatedListenAddressType: EnvironmentResolver, + DeprecatedEnvVarListenPort: &varName, } _, err := cfg.Resolve() @@ -130,7 +141,7 @@ func TestEnvironmentResolverErrorWhenValueMissing(t *testing.T) { func TestUnknownResolverError(t *testing.T) { cfg := Configuration{ - ListenAddressType: "some-unknown-resolver", + DeprecatedListenAddressType: "some-unknown-resolver", } _, err := cfg.Resolve()