-
Notifications
You must be signed in to change notification settings - Fork 88
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
Don't shell out to get the hostname #263
Conversation
I've encountered issues where the JVM cannot allocate memory in order to shell out, causing the puppet report integration to fail when trying to run hostname. Considering the socket library is already being loaded, switching the shell out to use socket.gethostname should make this code more reliable with less overhead.
Unfortunately It seems that you should be able to pass the hostname explicitly to avoid from that call to happen altogether, no? |
That's quite odd, when I tested this initially, Socket.gethostname did return the fqdn. Subsequent testing on other hosts doesn't though. Passing a hostname explicitly would be an option if I was writing something custom that uses dogapi, but what I'm trying to fix is the puppet datadog report tool. When our puppetservers are running hot, the report tool starts failing because the JVM cannot allocate memory to shell out and run hostname. |
I'm not very familiar with the puppet integration, but don't wee pass the host here: https://github.com/DataDog/puppet-datadog-agent/blob/0d3fedc5669bbc65558ab7d0820853c725829443/lib/puppet/reports/datadog_reports.rb#L125 ? |
Hmm... curious. It certainly seems like that should be passing the hostname. This issue was from when we were using the report plugin previously, we actually ripped it out of our environment because it was so unreliable. It looks like the code that passes in the hostname predates when we had this issue, but we definitely had issues with JVM being unable to allocate memory to shell out for the hostname call in dogapi which was what led us to entirely abandoning the report tool. I'll have to dig into this further. Just my 2 cents, even ignoring the issues we have experienced with this in the past, it seems avoiding the shell-out whenever possible is just good practice especially as Ruby has built in functions to provide this. Would a change to my PR which tried the Socket functions first, and only if those failed attempts to shell out be more welcome? |
The issue is that the socket functions will give you a value, but I don't know if you can tell if it failed because the value won't be correct, but you won't have anything to compare it to.
The core issue is that it doesn't seem like Ruby has the exact function that we need. |
Okay, to be fair, the hostname binary can also return the wrong value in the same situations. Namely, where the host is misconfigured. I see that you've made your mind up that shelling out unnecessarily is the better option though, so I won't waste more of my time on this. |
I haven't really made up my mind, I'm just cautious to touch some code that has been that way for 10 years. #179 (comment) is somewhat giving the reasons why we need to be careful here. If we find the Ruby API that consistently gives the same result as |
I've encountered issues where the JVM cannot allocate memory in order to shell out, causing the puppet report integration to fail when trying to run hostname. Considering the socket library is already being loaded, switching the shell out to use socket.gethostname should make this code more reliable with less overhead.
Review checklist (to be filled by reviewers)
changelog/
label attached. If applicable it should have thebackward-incompatible
label attached.do-not-merge/
label attached.kind/
andseverity/
labels attached at least.