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

[service_discovery] Fix race condition preventing SD initialization #135

Merged
merged 2 commits into from
Apr 18, 2017

Conversation

olivielpeau
Copy link
Member

@olivielpeau olivielpeau commented Apr 17, 2017

If JMXFetch starts before the collector process creates the SD pipe,
JMXFetch doesn't find the SD pipe and never re-tries opening it (until
it's fully restarted).

To solve this, retry opening the SD pipe at every run iteration when
SD is enabled. Also, add an --sd-enabled option to know whether
JMXFetch should enable SD (i.e. whether it should expect the SD pipe
to exist or not).

The --sd-standby option is not used and has therefore been removed.

This change requires a change to dd-agent to make jmxfetch.py pass
the --sd-enabled option when SD-JMXFetch is enabled. See DataDog/dd-agent#3306

If JMXFetch starts before the collector process creates the SD pipe,
JMXFetch doesn't find the SD pipe and never re-tries opening it, (until
it's fully restarted).

To solve this, retry opening the SD pipe at every run iteration when
SD is enabled. Also, add an `--sd-enabled` option to know whether
JMXFetch should enable SD (i.e. whether it should expect the SD pipe
to exist or not).

The `--sd-standby` option is not used and has therefore been removed.

This change requires a change to `dd-agent` to make `jmxfetch.py` pass
the `--sd-enabled` option when SD-JMXFetch is enabled.
if(sdPipe == null && appConfig.getSDEnabled()) {
// If SD is enabled and the pipe is not open, retry opening pipe
sdPipe = newSdPipe();
}
try {

Choose a reason for hiding this comment

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

Little nit, but could do
int len = 0
if(sdPipe != null && ((len = sdPipe.available()) > 0)) {
byte[] buffer....

No need to call sdPipe.available twice in succession.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 , addressed in 1c5bede

Copy link
Member

@truthbk truthbk Apr 18, 2017

Choose a reason for hiding this comment

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

Nice one. My bad.

Copy link
Member

@truthbk truthbk left a comment

Choose a reason for hiding this comment

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

Looks good to me :shipit:

Thanks for fixing the var names to something more meaningful.

@truthbk
Copy link
Member

truthbk commented Apr 18, 2017

There's a weird Travis error for oraclejdk7, let's make sure we know what's up with that before merging. I think it's unrelated.

@olivielpeau
Copy link
Member Author

Must've been a flaky test, I've just re-run the tests on oraclejdk7 and they're all green now!

Merging

@olivielpeau olivielpeau merged commit 856838f into master Apr 18, 2017
@olivielpeau olivielpeau added this to the 0.13.1 milestone Apr 18, 2017
@olivielpeau olivielpeau deleted the olivielpeau/fix-sd-race-condition-init branch April 18, 2017 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants