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

[agent] Make timeout for reporting configurable #1034

Merged
merged 2 commits into from
Nov 17, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Fix tests and make sure deprecated flags work
Signed-off-by: Goutham Veeramachaneni <gouthamve@gmail.com>
  • Loading branch information
gouthamve committed Nov 17, 2018
commit 34d298df9316c3a5b2fabb3e8dd5f50b9a8acd75
9 changes: 7 additions & 2 deletions cmd/agent/app/reporter/tchannel/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,13 @@ func (b *Builder) InitFromViper(v *viper.Viper, logger *zap.Logger) *Builder {
if len(v.GetString(tchannelPrefix+hostPort)) > 0 {
b.CollectorHostPorts = strings.Split(v.GetString(tchannelPrefix+hostPort), ",")
}
b.DiscoveryMinPeers = v.GetInt(tchannelPrefix + discoveryMinPeers)
b.ConnCheckTimeout = v.GetDuration(tchannelPrefix + discoveryConnCheckTimeout)

if value := v.GetInt(tchannelPrefix + discoveryMinPeers); value != defaultMinPeers {
b.DiscoveryMinPeers = value
}
gouthamve marked this conversation as resolved.
Show resolved Hide resolved
if value := v.GetDuration(tchannelPrefix + discoveryConnCheckTimeout); value != defaultConnCheckTimeout {
b.ConnCheckTimeout = value
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strictly speaking this does not solve the overriding problem if the manually provided value was the same as the default value, but it's still an improvement. The key thing is that we just need to remove the legacy flags soon.

b.ReportTimeout = v.GetDuration(tchannelPrefix + reportTimeout)
return b
}
23 changes: 13 additions & 10 deletions cmd/agent/app/reporter/tchannel/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ import (
)

func TestBingFlags(t *testing.T) {
v := viper.New()
command := cobra.Command{}
flags := &flag.FlagSet{}
AddFlags(flags)
command.PersistentFlags().AddGoFlagSet(flags)
v.BindPFlags(command.PersistentFlags())

tests := []struct {
flags []string
builder Builder
Expand All @@ -47,14 +40,14 @@ func TestBingFlags(t *testing.T) {
},
{flags: []string{
"--collector.host-port=1.2.3.4:555,1.2.3.4:666",
"--discovery.min-peers=42",
"--discovery.min-peers=45",
"--discovery.conn-check-timeout=85s",
},
builder: Builder{ConnCheckTimeout: time.Second * 85, ReportTimeout: defaultReportTimeout, DiscoveryMinPeers: 42, CollectorHostPorts: []string{"1.2.3.4:555", "1.2.3.4:666"}},
builder: Builder{ConnCheckTimeout: time.Second * 85, ReportTimeout: defaultReportTimeout, DiscoveryMinPeers: 45, CollectorHostPorts: []string{"1.2.3.4:555", "1.2.3.4:666"}},
},
{flags: []string{
"--collector.host-port=1.2.3.4:555,1.2.3.4:666",
"--discovery.min-peers=42",
"--discovery.min-peers=46",
"--discovery.conn-check-timeout=85s",
"--reporter.tchannel.host-port=1.2.3.4:5556,1.2.3.4:6667",
"--reporter.tchannel.discovery.min-peers=43",
Expand All @@ -64,6 +57,16 @@ func TestBingFlags(t *testing.T) {
},
}
for _, test := range tests {
// Reset flags every iteration.
v := viper.New()
command := cobra.Command{}

flags := &flag.FlagSet{}
AddFlags(flags)
command.ResetFlags()
command.PersistentFlags().AddGoFlagSet(flags)
v.BindPFlags(command.PersistentFlags())

err := command.ParseFlags(test.flags)
require.NoError(t, err)
b := Builder{}
Expand Down