-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Allow agent to use a static list to connect to multiple collectors (#134) #137
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you for sending a PR!
cmd/agent/app/config.go
Outdated
// Set this to communicate with Collector directly, without routing layer. | ||
CollectorHostPort string `yaml:"collectorHostPort"` | ||
// CollectorHostPorts is the static list of hostPorts for Jaeger Collector. | ||
CollectorHostPorts string `yaml:"CollectorHostPorts"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be a breaking change. Also, in YAML it would be more natural to declare this as []string
. So I would suggest the following
- keep
collectorHostPort
but document it as comma-separated string - change CollectorHostPorts to
[]string
(yaml label should start with lower-case) - leave the builder binding the string flag to the original
collectorHostPort
- in the constructor, combing values from
[]string
and fromcollectorHostPort
(after splitting on,
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for review. Just submit a new CL with the fix.
cmd/agent/app/config.go
Outdated
@@ -75,10 +76,13 @@ type Builder struct { | |||
Processors []ProcessorConfiguration `yaml:"processors"` | |||
SamplingServer SamplingServerConfiguration `yaml:"samplingServer"` | |||
|
|||
// CollectorHostPort is the hostPort for Jaeger Collector. | |||
// Set this to communicate with Collector directly, without routing layer. | |||
// CollectorHostPort is comma-separate string representing host:ports of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: comma-separated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
cmd/agent/app/flags.go
Outdated
@@ -52,7 +52,7 @@ func (b *Builder) Bind(flags *flag.FlagSet) { | |||
&b.CollectorHostPort, | |||
"collector.host-port", | |||
"", | |||
"host:port of a single collector to connect to directly (e.g. when not using service discovery)") | |||
"comma-separate string representing host:ports of a static list of collectors to connect to directly (e.g. when not using service discovery)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: comma-separated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
cmd/agent/app/config.go
Outdated
d := discovery.FixedDiscoverer(hostPorts) | ||
notifier := &discovery.Dispatcher{} | ||
b.WithDiscoverer(d).WithDiscoveryNotifier(notifier) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a test that verifies the merging behavior
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added. During adding unittest, I realize there is potential partially overlapping case for the two sources of static collector lists, and the handling potentially be very complicated, for example, localhost:5700 vs 127.0.0.1:5700. I start to wonder that why do not we just use CollectotHostPort string, and get rid of CollectorHostPorts entirely. By this way, the logic will be a lot simpler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I am not very happy with the duplication myself. The builder struct is designed to be yaml-friendly. We internally have a different main.go for the agent that includes some additional internal components, and a yaml-file-based configuration. And in yaml it's a lot nicer to define the addresses as a list
- collectorHostPorts:
- hostA:57000
- hostB:57000
- hostC:57000
rather than comma-separated string
- collectorHostPort: hostA:57000,hostB:57000,hostC:57000
My preferred model would be to have only CollectorHostPorts []string
. But I don't know how to bind it to a cmd line flag nicely.
If you want to drop the []string
var and only keep the comma-separated string, I am fine with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Figure out the "ideal" solution can be achieved by a customized flag. Just submit a new version. Please help take a look.
cmd/agent/app/flags_test.go
Outdated
@@ -41,7 +42,7 @@ func TestBingFlags(t *testing.T) { | |||
"-processor.jaeger-binary.workers=42", | |||
}) | |||
assert.Equal(t, 3, len(cfg.Processors)) | |||
assert.Equal(t, "1.2.3.4:555", cfg.CollectorHostPort) | |||
assert.Equal(t, "1.2.3.4:555,1.2.3.4:666", strings.Join(cfg.CollectorHostPorts, ",")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the test can be more structured:
assert.Equal(t, []string{"1.2.3.4:555", "1.2.3.4:666"}, cfg.CollectorHostPorts)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
cmd/agent/app/flags.go
Outdated
flags.StringVar( | ||
&b.CollectorHostPort, | ||
flags.Var( | ||
&b.CollectorHostPorts, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather than adding staticCollectors
type in config, I would define a type here, e.g. stringSliceFlag, which would take a pointer to a regular slice, e.g.
type stringSliceFlag type {
slice *[]string
}
flags.Var(
&stringSliceFlag{slice: &b.CollectorHostPorts},
This way the "flag"-ness is encapsulated in the flags
file, without spilling into the config struct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
cmd/agent/app/config_test.go
Outdated
|
||
assert.Equal( | ||
t, | ||
"127.0.0.1:14267,127.0.0.1:14268,127.0.0.1:14269", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use structured comparison (see comment below)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
cmd/agent/app/config_test.go
Outdated
assert.Equal(t, len(c), len(hostPorts)) | ||
|
||
hostPortsStr := strings.Join(hostPorts, ",") | ||
assert.Equal(t, strings.Join(c, ","), hostPortsStr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can compare slices directly, without string join
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
cmd/agent/app/config.go
Outdated
// Set sets the flag value, part of the flag.Value interface. | ||
func (c *staticCollectors) Set(value string) error { | ||
if len(*c) > 0 { | ||
return errors.New("interval flag already set") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/interval/comma-separated/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall looks good. Please rebase off master.
I think the reason the tests are failing is because of this code in crossdock/main.go
:
// InitializeAgent initializes the jaeger agent.
func InitializeAgent(url string, logger *zap.Logger) services.AgentService {
cmd := exec.Command("/bin/sh", "-c", fmt.Sprintf(agentCmd,
"-collector.host-port=localhost:14267 -processor.zipkin-compact.server-host-port=test_driver:5775 "+
cmd/agent/app/config_test.go
Outdated
|
||
c, err := cfg.discoverer.Instances() | ||
assert.NoError(t, err) | ||
assert.Equal(t, len(c), len(hostPorts)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundant when comparing arrays directly below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point
cmd/agent/app/config.go
Outdated
if len(b.CollectorHostPorts) != 0 { | ||
d := discovery.FixedDiscoverer(b.CollectorHostPorts) | ||
notifier := &discovery.Dispatcher{} | ||
b.WithDiscoverer(d).WithDiscoveryNotifier(notifier) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: b = b.With...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
err = flags.Parse([]string{ | ||
"-collector.host-port=1.2.3.4:555,1.2.3.4:666", | ||
}) | ||
assert.NotNil(t, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure this is needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was for improving code coverage. Removed.
Please check where the coverage goes down, we want to keep at 100%. Also, if you haven't, please sign the contributor license. |
discoveryMgr, err := b.enableDiscovery(b.channel, logger) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "cannot enable service discovery") | ||
} | ||
var clientOpts *tchannelThrift.ClientOptions | ||
if discoveryMgr == nil && b.CollectorHostPort != "" { | ||
clientOpts = &tchannelThrift.ClientOptions{HostPort: b.CollectorHostPort} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we still need tchannelThrift client option if collectorhosts are static. This is the reason why the build is failing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like a bug elsewhere, because we don't need clientOptions when using the real discovery system, so it should've worked by using fixed discoverer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the failure possible to repro on dev box? How should I proceed?
Thx.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yurishkuro we don't need clientOptions when using the real discovery system because internally we use a different version of tchannel that binds to our internal discovery system. Here, we need to pass in the static port or else tchannel can't find collector.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@black-adder but that's what attaching a static discovery does, it updates the peer list afterwards.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wrong, there was nothing wrong with this... dunno how I came to that conclusion.
sign the cla and we can land this |
I had signed a while ago. Somehow, this page always shows that I have not. When I click in the Details, it shows I have signed. |
Fixes #134