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

Added whitespace tolerance for value for ES servers and kafka brokers #1305

Merged
merged 2 commits into from
Jan 30, 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
7 changes: 6 additions & 1 deletion plugin/storage/es/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func initFromViper(cfg *namespaceConfig, v *viper.Viper) {
cfg.Username = v.GetString(cfg.namespace + suffixUsername)
cfg.Password = v.GetString(cfg.namespace + suffixPassword)
cfg.Sniffer = v.GetBool(cfg.namespace + suffixSniffer)
cfg.servers = v.GetString(cfg.namespace + suffixServerURLs)
cfg.servers = stripWhiteSpace(v.GetString(cfg.namespace + suffixServerURLs))
cfg.MaxSpanAge = v.GetDuration(cfg.namespace + suffixMaxSpanAge)
cfg.MaxNumSpans = v.GetInt(cfg.namespace + suffixMaxNumSpans)
cfg.NumShards = v.GetInt64(cfg.namespace + suffixNumShards)
Expand Down Expand Up @@ -259,3 +259,8 @@ func (opt *Options) Get(namespace string) *config.Configuration {
nsCfg.Servers = strings.Split(nsCfg.servers, ",")
return &nsCfg.Configuration
}

// stripWhiteSpace removes all whitespace characters from a string
func stripWhiteSpace(str string) string {
return strings.Replace(str, " ", "", -1)
}
4 changes: 2 additions & 2 deletions plugin/storage/es/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ func TestOptionsWithFlags(t *testing.T) {
opts := NewOptions("es", "es.aux")
v, command := config.Viperize(opts.AddFlags)
command.ParseFlags([]string{
"--es.server-urls=1.1.1.1,2.2.2.2",
"--es.server-urls=1.1.1.1, 2.2.2.2",
"--es.username=hello",
"--es.password=world",
"--es.sniffer=true",
"--es.max-span-age=48h",
"--es.num-shards=20",
"--es.num-replicas=10",
// a couple overrides
"--es.aux.server-urls=3.3.3.3,4.4.4.4",
"--es.aux.server-urls=3.3.3.3, 4.4.4.4",
"--es.aux.max-span-age=24h",
"--es.aux.num-replicas=10",
})
Expand Down
7 changes: 6 additions & 1 deletion plugin/storage/kafka/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,13 @@ func (opt *Options) AddFlags(flagSet *flag.FlagSet) {
// InitFromViper initializes Options with properties from viper
func (opt *Options) InitFromViper(v *viper.Viper) {
opt.config = producer.Configuration{
Brokers: strings.Split(v.GetString(configPrefix+suffixBrokers), ","),
Brokers: strings.Split(stripWhiteSpace(v.GetString(configPrefix+suffixBrokers)), ","),
}
opt.topic = v.GetString(configPrefix + suffixTopic)
opt.encoding = v.GetString(configPrefix + suffixEncoding)
}

// stripWhiteSpace removes all whitespace characters from a string
func stripWhiteSpace(str string) string {
return strings.Replace(str, " ", "", -1)
}
2 changes: 1 addition & 1 deletion plugin/storage/kafka/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestOptionsWithFlags(t *testing.T) {
v, command := config.Viperize(opts.AddFlags)
command.ParseFlags([]string{
"--kafka.topic=topic1",
"--kafka.brokers=127.0.0.1:9092,0.0.0:1234",
"--kafka.brokers=127.0.0.1:9092, 0.0.0:1234",
"--kafka.encoding=protobuf"})
opts.InitFromViper(v)

Expand Down