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

Allow agent to use a static list to connect to multiple collectors (#134) #137

Merged
merged 3 commits into from
May 9, 2017

Conversation

yuekui2
Copy link
Contributor

@yuekui2 yuekui2 commented Apr 29, 2017

Fixes #134

@CLAassistant
Copy link

CLAassistant commented Apr 29, 2017

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@yurishkuro yurishkuro changed the title issue #134 Allow agent to use a static list to connect to multiple co… Allow agent to use a static list to connect to multiple collectors (#134) Apr 29, 2017
Copy link
Member

@yurishkuro yurishkuro left a 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!

// 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"`
Copy link
Member

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

  1. keep collectorHostPort but document it as comma-separated string
  2. change CollectorHostPorts to []string (yaml label should start with lower-case)
  3. leave the builder binding the string flag to the original collectorHostPort
  4. in the constructor, combing values from []string and from collectorHostPort (after splitting on ,)

Copy link
Contributor Author

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.

@@ -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
Copy link
Member

Choose a reason for hiding this comment

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

nit: comma-separated

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

@@ -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)")
Copy link
Member

Choose a reason for hiding this comment

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

nit: comma-separated

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

d := discovery.FixedDiscoverer(hostPorts)
notifier := &discovery.Dispatcher{}
b.WithDiscoverer(d).WithDiscoveryNotifier(notifier)
}
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 89a32d1 on yuekui2:master into b916b37 on uber:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 0b5b0f6 on yuekui2:master into b916b37 on uber:master.

@@ -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, ","))
Copy link
Member

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)

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

flags.StringVar(
&b.CollectorHostPort,
flags.Var(
&b.CollectorHostPorts,
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point

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


assert.Equal(
t,
"127.0.0.1:14267,127.0.0.1:14268,127.0.0.1:14269",
Copy link
Member

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)

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

assert.Equal(t, len(c), len(hostPorts))

hostPortsStr := strings.Join(hostPorts, ",")
assert.Equal(t, strings.Join(c, ","), hostPortsStr)
Copy link
Member

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

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

// 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")
Copy link
Member

Choose a reason for hiding this comment

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

s/interval/comma-separated/

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

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.8%) to 99.174% when pulling 0d7ff12 on yuekui2:master into b916b37 on uber:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling fbf4911 on yuekui2:master into b916b37 on uber:master.

Copy link
Member

@yurishkuro yurishkuro left a 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 "+


c, err := cfg.discoverer.Instances()
assert.NoError(t, err)
assert.Equal(t, len(c), len(hostPorts))
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point

if len(b.CollectorHostPorts) != 0 {
d := discovery.FixedDiscoverer(b.CollectorHostPorts)
notifier := &discovery.Dispatcher{}
b.WithDiscoverer(d).WithDiscoveryNotifier(notifier)
Copy link
Member

Choose a reason for hiding this comment

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

nit: b = b.With...

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

err = flags.Parse([]string{
"-collector.host-port=1.2.3.4:555,1.2.3.4:666",
})
assert.NotNil(t, err)
Copy link
Member

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

Copy link
Contributor Author

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.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.04%) to 99.958% when pulling 05482fb on yuekui2:master into b916b37 on uber:master.

@yurishkuro
Copy link
Member

Please check where the coverage goes down, we want to keep at 100%.

Also, if you haven't, please sign the contributor license.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling e03fd15 on yuekui2:master into b916b37 on uber:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 0463f7b on yuekui2:master into f209812 on uber:master.

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}
Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor

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.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling a2fa6bd on yuekui2:master into 4a63496 on uber:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 5a504a8 on yuekui2:master into 4dc8b7f on uber:master.

@black-adder
Copy link
Contributor

sign the cla and we can land this

@yuekui2
Copy link
Contributor Author

yuekui2 commented May 9, 2017

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.

@black-adder black-adder merged commit 3a42e0e into jaegertracing:master May 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants