Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[x/config] Deprecate src/x/config/listenaddress #2017

Merged
merged 1 commit into from
Oct 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion scripts/development/m3_stack/m3coordinator.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
listenAddress:
type: "config"
value: "0.0.0.0:7201"

logging:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
listenAddress:
type: "config"
value: "0.0.0.0:7202"

logging:
Expand Down
1 change: 0 additions & 1 deletion scripts/docker-integration-tests/carbon/m3coordinator.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
listenAddress:
type: "config"
value: "0.0.0.0:7201"

logging:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
listenAddress:
type: "config"
value: "0.0.0.0:7201"

logging:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
coordinator:
listenAddress:
type: "config"
value: "0.0.0.0:7201"

logging:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
listenAddress:
type: "config"
value: "0.0.0.0:7201"

logging:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
listenAddress:
type: "config"
value: "0.0.0.0:7201"

logging:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
listenAddress:
type: "config"
value: "0.0.0.0:7201"

logging:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
listenAddress:
type: "config"
value: "0.0.0.0:7201"

logging:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
listenAddress:
type: "config"
value: "0.0.0.0:7201"

logging:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
listenAddress:
type: "config"
value: "0.0.0.0:7201"

logging:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
listenAddress:
type: "config"
value: "0.0.0.0:7201"

logging:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
listenAddress:
type: "config"
value: "0.0.0.0:7201"

logging:
Expand Down
1 change: 0 additions & 1 deletion scripts/docker-integration-tests/repair/m3coordinator.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
listenAddress:
type: "config"
value: "0.0.0.0:7201"

logging:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
listenAddress:
type: "config"
value: "0.0.0.0:7201"

logging:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
listenAddress:
type: "config"
value: "0.0.0.0:7201"

logging:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
listenAddress:
type: "config"
value: "0.0.0.0:7201"

logging:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
listenAddress:
type: "config"
value: "0.0.0.0:7201"

logging:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
listenAddress:
type: "config"
value: "0.0.0.0:7201"

logging:
Expand Down
1 change: 0 additions & 1 deletion src/cmd/services/m3query/config/testdata/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
listenAddress:
type: "config"
value: "0.0.0.0:7201"

logging:
Expand Down
1 change: 0 additions & 1 deletion src/cmd/services/m3query/config/testdata/config_test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
listenAddress:
type: "config"
value: "0.0.0.0:7201"

logging:
Expand Down
1 change: 0 additions & 1 deletion src/dbnode/config/m3dbnode-all-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/dbnode/config/m3dbnode-cluster-template.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
coordinator:
listenAddress:
type: "config"
value: "0.0.0.0:7201"

local:
Expand Down
1 change: 0 additions & 1 deletion src/dbnode/config/m3dbnode-local-etcd-proto.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
coordinator:
listenAddress:
type: "config"
value: "0.0.0.0:7201"

local:
Expand Down
1 change: 0 additions & 1 deletion src/dbnode/config/m3dbnode-local-etcd.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
coordinator:
listenAddress:
type: "config"
value: "0.0.0.0:7201"

local:
Expand Down
1 change: 0 additions & 1 deletion src/query/config/m3coordinator-cluster-template.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
listenAddress:
type: "config"
value: "0.0.0.0:7201"

logging:
Expand Down
1 change: 0 additions & 1 deletion src/query/config/m3coordinator-local-etcd.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
listenAddress:
type: "config"
value: "0.0.0.0:7201"

logging:
Expand Down
1 change: 0 additions & 1 deletion src/query/config/m3query-dev-etcd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# resources (threads primarily).

listenAddress:
type: "config"
value: "0.0.0.0:7201"

logging:
Expand Down
1 change: 0 additions & 1 deletion src/query/config/m3query-local-etcd.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
listenAddress:
type: "config"
value: "0.0.0.0:7201"

logging:
Expand Down
45 changes: 34 additions & 11 deletions src/x/config/listenaddress/listenaddress.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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 {
Expand All @@ -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)
}

Expand Down
39 changes: 25 additions & 14 deletions src/x/config/listenaddress/listenaddress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -50,7 +61,7 @@ func TestListenAddressResolver(t *testing.T) {

func TestConfigResolverErrorWhenMissing(t *testing.T) {
cfg := Configuration{
ListenAddressType: ConfigResolver,
DeprecatedListenAddressType: ConfigResolver,
}

_, err := cfg.Resolve()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -109,7 +120,7 @@ func TestInvalidEnvironmentVariableResolver(t *testing.T) {

func TestEnvironmentResolverErrorWhenNameMissing(t *testing.T) {
cfg := Configuration{
ListenAddressType: EnvironmentResolver,
DeprecatedListenAddressType: EnvironmentResolver,
}

_, err := cfg.Resolve()
Expand All @@ -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()
Expand All @@ -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()
Expand Down