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

override reporter config only when agent host or port was set in env #513

Merged
merged 3 commits into from May 14, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion config/config_env.go
Expand Up @@ -187,20 +187,25 @@ func (rc *ReporterConfig) reporterConfigFromEnv() (*ReporterConfig, error) {
rc.User = user
rc.Password = pswd
} else {
useEnv := false
host := jaeger.DefaultUDPSpanServerHost
if e := os.Getenv(envAgentHost); e != "" {
host = e
useEnv = true
}

port := jaeger.DefaultUDPSpanServerPort
if e := os.Getenv(envAgentPort); e != "" {
if value, err := strconv.ParseInt(e, 10, 0); err == nil {
port = int(value)
useEnv = true
} else {
return nil, errors.Wrapf(err, "cannot parse env var %s=%s", envAgentPort, e)
}
}
rc.LocalAgentHostPort = fmt.Sprintf("%s:%d", host, port)
if useEnv || rc.LocalAgentHostPort == "" {
rc.LocalAgentHostPort = fmt.Sprintf("%s:%d", host, port)
}
}

return rc, nil
Expand Down
49 changes: 49 additions & 0 deletions config/config_test.go
Expand Up @@ -252,6 +252,55 @@ func TestReporter(t *testing.T) {
assert.Equal(t, "user", cfg.User)
assert.Equal(t, "password", cfg.Password)

//
Copy link
Member

Choose a reason for hiding this comment

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

Could you please split these into separate, appropriately named tests? There's no reason to keep everything in one function, and it makes it hard to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

unsetEnv(t, envEndpoint)
unsetEnv(t, envAgentHost)
unsetEnv(t, envAgentPort)
rc = ReporterConfig{}

//
cfg, err = rc.reporterConfigFromEnv()
assert.NoError(t, err)

assert.Equal(t, "localhost:6831", cfg.LocalAgentHostPort)

//
rc = ReporterConfig{
LocalAgentHostPort: "localhost01:7777",
}

//
cfg, err = rc.reporterConfigFromEnv()
assert.NoError(t, err)

assert.Equal(t, "localhost01:7777", cfg.LocalAgentHostPort)

//
setEnv(t, envAgentHost, "localhost02")
unsetEnv(t, envAgentPort)
rc = ReporterConfig{
LocalAgentHostPort: "localhost01:7777",
}

//
cfg, err = rc.reporterConfigFromEnv()
assert.NoError(t, err)

assert.Equal(t, "localhost02:6831", cfg.LocalAgentHostPort)

//
unsetEnv(t, envAgentHost)
setEnv(t, envAgentPort, "8888")
rc = ReporterConfig{
LocalAgentHostPort: "localhost01:7777",
}

//
cfg, err = rc.reporterConfigFromEnv()
assert.NoError(t, err)

assert.Equal(t, "localhost:8888", cfg.LocalAgentHostPort)

// cleanup
unsetEnv(t, envReporterMaxQueueSize)
unsetEnv(t, envReporterFlushInterval)
Expand Down