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

add shared helper for stripping whitespace of storage host strings #1306

Closed
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
8 changes: 2 additions & 6 deletions plugin/storage/cassandra/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/spf13/viper"

"github.com/jaegertracing/jaeger/pkg/cassandra/config"
"github.com/jaegertracing/jaeger/plugin/storage/helper"
)

const (
Expand Down Expand Up @@ -216,7 +217,7 @@ func (cfg *namespaceConfig) initFromViper(v *viper.Viper) {
cfg.MaxRetryAttempts = v.GetInt(cfg.namespace + suffixMaxRetryAttempts)
cfg.Timeout = v.GetDuration(cfg.namespace + suffixTimeout)
cfg.ReconnectInterval = v.GetDuration(cfg.namespace + suffixReconnectInterval)
cfg.servers = stripWhiteSpace(v.GetString(cfg.namespace + suffixServers))
cfg.servers = helper.StripWhiteSpace(v.GetString(cfg.namespace + suffixServers))
cfg.Port = v.GetInt(cfg.namespace + suffixPort)
cfg.Keyspace = v.GetString(cfg.namespace + suffixKeyspace)
cfg.LocalDC = v.GetString(cfg.namespace + suffixDC)
Expand Down Expand Up @@ -256,8 +257,3 @@ 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)
}
3 changes: 2 additions & 1 deletion plugin/storage/es/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/spf13/viper"

"github.com/jaegertracing/jaeger/pkg/es/config"
"github.com/jaegertracing/jaeger/plugin/storage/helper"
)

const (
Expand Down Expand Up @@ -218,7 +219,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 = helper.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
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
8 changes: 8 additions & 0 deletions plugin/storage/helper/helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package helper

import "strings"

// stripWhiteSpace removes all whitespace characters from a string
func StripWhiteSpace(str string) string {
return strings.Replace(str, " ", "", -1)
}
3 changes: 2 additions & 1 deletion plugin/storage/kafka/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/spf13/viper"

"github.com/jaegertracing/jaeger/pkg/kafka/producer"
"github.com/jaegertracing/jaeger/plugin/storage/helper"
)

const (
Expand Down Expand Up @@ -74,7 +75,7 @@ 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(helper.StripWhiteSpace(v.GetString(configPrefix+suffixBrokers)), ","),
}
opt.topic = v.GetString(configPrefix + suffixTopic)
opt.encoding = v.GetString(configPrefix + suffixEncoding)
Expand Down
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