Merge pull request #9442 from gyuho/urls
etcdmain: remove "listen-metrics-urls" manual parsingrelease-3.4
commit
46f346f87a
|
@ -133,7 +133,7 @@ func newConfig() *config {
|
||||||
fs.StringVar(&cfg.ec.WalDir, "wal-dir", cfg.ec.WalDir, "Path to the dedicated wal directory.")
|
fs.StringVar(&cfg.ec.WalDir, "wal-dir", cfg.ec.WalDir, "Path to the dedicated wal directory.")
|
||||||
fs.Var(flags.NewURLsValue(embed.DefaultListenPeerURLs), "listen-peer-urls", "List of URLs to listen on for peer traffic.")
|
fs.Var(flags.NewURLsValue(embed.DefaultListenPeerURLs), "listen-peer-urls", "List of URLs to listen on for peer traffic.")
|
||||||
fs.Var(flags.NewURLsValue(embed.DefaultListenClientURLs), "listen-client-urls", "List of URLs to listen on for client traffic.")
|
fs.Var(flags.NewURLsValue(embed.DefaultListenClientURLs), "listen-client-urls", "List of URLs to listen on for client traffic.")
|
||||||
fs.StringVar(&cfg.ec.ListenMetricsUrlsJSON, "listen-metrics-urls", "", "List of URLs to listen on for metrics.")
|
fs.Var(flags.NewURLsValue(""), "listen-metrics-urls", "List of URLs to listen on for metrics.")
|
||||||
fs.UintVar(&cfg.ec.MaxSnapFiles, "max-snapshots", cfg.ec.MaxSnapFiles, "Maximum number of snapshot files to retain (0 is unlimited).")
|
fs.UintVar(&cfg.ec.MaxSnapFiles, "max-snapshots", cfg.ec.MaxSnapFiles, "Maximum number of snapshot files to retain (0 is unlimited).")
|
||||||
fs.UintVar(&cfg.ec.MaxWalFiles, "max-wals", cfg.ec.MaxWalFiles, "Maximum number of wal files to retain (0 is unlimited).")
|
fs.UintVar(&cfg.ec.MaxWalFiles, "max-wals", cfg.ec.MaxWalFiles, "Maximum number of wal files to retain (0 is unlimited).")
|
||||||
fs.StringVar(&cfg.ec.Name, "name", cfg.ec.Name, "Human-readable name for this member.")
|
fs.StringVar(&cfg.ec.Name, "name", cfg.ec.Name, "Human-readable name for this member.")
|
||||||
|
@ -269,14 +269,7 @@ func (cfg *config) configFromCmdLine() error {
|
||||||
cfg.ec.LCUrls = flags.URLsFromFlag(cfg.cf.flagSet, "listen-client-urls")
|
cfg.ec.LCUrls = flags.URLsFromFlag(cfg.cf.flagSet, "listen-client-urls")
|
||||||
cfg.ec.ACUrls = flags.URLsFromFlag(cfg.cf.flagSet, "advertise-client-urls")
|
cfg.ec.ACUrls = flags.URLsFromFlag(cfg.cf.flagSet, "advertise-client-urls")
|
||||||
cfg.ec.HostWhitelist = flags.StringSliceFromFlag(cfg.cf.flagSet, "host-whitelist")
|
cfg.ec.HostWhitelist = flags.StringSliceFromFlag(cfg.cf.flagSet, "host-whitelist")
|
||||||
|
cfg.ec.ListenMetricsUrls = flags.URLsFromFlag(cfg.cf.flagSet, "listen-metrics-urls")
|
||||||
if len(cfg.ec.ListenMetricsUrlsJSON) > 0 {
|
|
||||||
u, err := types.NewURLs(strings.Split(cfg.ec.ListenMetricsUrlsJSON, ","))
|
|
||||||
if err != nil {
|
|
||||||
plog.Fatalf("unexpected error setting up listen-metrics-urls: %v", err)
|
|
||||||
}
|
|
||||||
cfg.ec.ListenMetricsUrls = []url.URL(u)
|
|
||||||
}
|
|
||||||
|
|
||||||
cfg.ec.ClusterState = cfg.cf.clusterState.String()
|
cfg.ec.ClusterState = cfg.cf.clusterState.String()
|
||||||
cfg.cp.Fallback = cfg.cf.fallback.String()
|
cfg.cp.Fallback = cfg.cf.fallback.String()
|
||||||
|
@ -311,12 +304,22 @@ func (cfg *config) configFromFile(path string) error {
|
||||||
if yerr := yaml.Unmarshal(b, &cfg.cp); yerr != nil {
|
if yerr := yaml.Unmarshal(b, &cfg.cp); yerr != nil {
|
||||||
return yerr
|
return yerr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cfg.ec.ListenMetricsUrlsJSON != "" {
|
||||||
|
us, err := types.NewURLs(strings.Split(cfg.ec.ListenMetricsUrlsJSON, ","))
|
||||||
|
if err != nil {
|
||||||
|
plog.Panicf("unexpected error setting up listen-metrics-urls: %v", err)
|
||||||
|
}
|
||||||
|
cfg.ec.ListenMetricsUrls = []url.URL(us)
|
||||||
|
}
|
||||||
|
|
||||||
if cfg.cp.FallbackJSON != "" {
|
if cfg.cp.FallbackJSON != "" {
|
||||||
if err := cfg.cf.fallback.Set(cfg.cp.FallbackJSON); err != nil {
|
if err := cfg.cf.fallback.Set(cfg.cp.FallbackJSON); err != nil {
|
||||||
plog.Panicf("unexpected error setting up discovery-fallback flag: %v", err)
|
plog.Panicf("unexpected error setting up discovery-fallback flag: %v", err)
|
||||||
}
|
}
|
||||||
cfg.cp.Fallback = cfg.cf.fallback.String()
|
cfg.cp.Fallback = cfg.cf.fallback.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.cp.ProxyJSON != "" {
|
if cfg.cp.ProxyJSON != "" {
|
||||||
if err := cfg.cf.proxy.Set(cfg.cp.ProxyJSON); err != nil {
|
if err := cfg.cf.proxy.Set(cfg.cp.ProxyJSON); err != nil {
|
||||||
plog.Panicf("unexpected error setting up proxyFlag: %v", err)
|
plog.Panicf("unexpected error setting up proxyFlag: %v", err)
|
||||||
|
|
|
@ -20,18 +20,17 @@ import (
|
||||||
"github.com/coreos/etcd/pkg/types"
|
"github.com/coreos/etcd/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// URLsValue wraps "types.URLs".
|
||||||
type URLsValue types.URLs
|
type URLsValue types.URLs
|
||||||
|
|
||||||
// Set parses a command line set of URLs formatted like:
|
// Set parses a command line set of URLs formatted like:
|
||||||
// http://127.0.0.1:2380,http://10.1.1.2:80
|
// http://127.0.0.1:2380,http://10.1.1.2:80
|
||||||
func (us *URLsValue) Set(s string) error {
|
func (us *URLsValue) Set(s string) error {
|
||||||
strs := strings.Split(s, ",")
|
ss, err := types.NewURLs(strings.Split(s, ","))
|
||||||
nus, err := types.NewURLs(strs)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
*us = URLsValue(ss)
|
||||||
*us = URLsValue(nus)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,9 +42,14 @@ func (us *URLsValue) String() string {
|
||||||
return strings.Join(all, ",")
|
return strings.Join(all, ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewURLsValue(init string) *URLsValue {
|
// NewURLsValue implements "url.URL" slice as flag.Value interface.
|
||||||
|
// Given value is to be separated by comma.
|
||||||
|
func NewURLsValue(s string) *URLsValue {
|
||||||
|
if s == "" {
|
||||||
|
return &URLsValue{}
|
||||||
|
}
|
||||||
v := &URLsValue{}
|
v := &URLsValue{}
|
||||||
if err := v.Set(init); err != nil {
|
if err := v.Set(s); err != nil {
|
||||||
plog.Panicf("new URLsValue should never fail: %v", err)
|
plog.Panicf("new URLsValue should never fail: %v", err)
|
||||||
}
|
}
|
||||||
return v
|
return v
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
package flags
|
package flags
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/url"
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -45,17 +47,27 @@ func TestValidateURLsValueBad(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValidateURLsValueGood(t *testing.T) {
|
func TestNewURLsValue(t *testing.T) {
|
||||||
tests := []string{
|
tests := []struct {
|
||||||
"https://1.2.3.4:8080",
|
s string
|
||||||
"http://10.1.1.1:80",
|
exp []url.URL
|
||||||
"http://localhost:80",
|
}{
|
||||||
"http://:80",
|
{s: "https://1.2.3.4:8080", exp: []url.URL{{Scheme: "https", Host: "1.2.3.4:8080"}}},
|
||||||
|
{s: "http://10.1.1.1:80", exp: []url.URL{{Scheme: "http", Host: "10.1.1.1:80"}}},
|
||||||
|
{s: "http://localhost:80", exp: []url.URL{{Scheme: "http", Host: "localhost:80"}}},
|
||||||
|
{s: "http://:80", exp: []url.URL{{Scheme: "http", Host: ":80"}}},
|
||||||
|
{
|
||||||
|
s: "http://localhost:1,https://localhost:2",
|
||||||
|
exp: []url.URL{
|
||||||
|
{Scheme: "http", Host: "localhost:1"},
|
||||||
|
{Scheme: "https", Host: "localhost:2"},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for i, in := range tests {
|
for i := range tests {
|
||||||
u := URLsValue{}
|
uu := []url.URL(*NewURLsValue(tests[i].s))
|
||||||
if err := u.Set(in); err != nil {
|
if !reflect.DeepEqual(tests[i].exp, uu) {
|
||||||
t.Errorf("#%d: err=%v, want nil for in=%q", i, err, in)
|
t.Fatalf("#%d: expected %+v, got %+v", i, tests[i].exp, uu)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue