-
Notifications
You must be signed in to change notification settings - Fork 601
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
Fix Hostname.get_fqdn on AWS Lambda #697
Comments
Ahh yeah I see what you're saying about the As for the log message in that method, Looking through the code, I don't really see any other areas that are using this command, but we do call |
Something like this so I could ensure the const was loaded prior to patching. NewRelic::Agent::Hostname.module_eval do
def self.get_fqdn
# ...
end
end You can verify the technique like so. No idea why it did not work. module HostTest
def self.get_fqdn
'your.host.com'
end
end
HostTest.module_eval do
def self.get_fqdn
'my.host.com'
end
end
HostTest.get_fqdn # => "my.host.com" Any thoughts on where to look next? |
Hmm, yeah that does seem like it should work correctly. Surprising that even with bypassing that method and the hostname command in it, you're still seeing that If that doesn't give that same error message output, then I'm not really sure. I'm not finding any other instances of us using that command in the agent, and we don't call that method in very many places. We do call |
Hello @metaskills, did you get a chance to review the comments from tannalynn? Please let us know if you were able to try the suggestion of using Socket.gethostname. |
Thank you for submitting the issue. However, at this time we are unable to make progress without further feedback. Please reopen the issue if this is still a problem for you. |
Thanks @angelatan2, I understand. I'm unsure where to take this as well. Just really appreciate y'all taking a look and offering some thoughts. I'm changing the log level in my guide here (https://dev.to/aws-heroes/using-new-relic-apm-with-rails-on-aws-lambda-51gi) to be fatal which should avoid seeing it no matter what. I'll also be doing a post this week on moving that sync api call to flush data to a new Lambda Extension that allows this to be outside the request/response time. https://github.com/customink/lambda_punch#-usage This will help us keep using New Relic APM in Rails & Lambda too. Feedback always welcome! |
I dug into this issue a bit and I thought I'd share some of my learnings with you, @angelatan2 and @metaskills:
So I do think that confirms that
@metaskills I'm not quite sure why |
Thanks Brian. Super happy you found the right way to over ride and test this. @angelatan2 Worth re-opening? |
@brcarp Thanks for digging into this issue and sharing the steps to reproduce the problem. We really appreciate it. |
I took a look at this one.
I see two possible agent changes that we can consider introducing:
|
I like those two options. Thoughts @brcarp? |
I think these ideas compliment each other and are both reasonable. Attempting to verify Catching the error is perhaps more robust, for a slightly higher level of effort. I'm not attached to any particular path forward; I'm content to defer to the maintainers on appropriate remediation. |
And now I'm realizing that this is the result of not giving it more than a second or two's thought. Here's an equivalent solution which avoids the use of %x(hostname &> /dev/null && hostname) To make it even more robust and avoid shell syntax altogether, Ruby's require 'popen3'
begin
Open3.popen2('hostname') { |stdin, stdout, wait_thr| puts stdout.read.chomp }
rescue
nil
end |
Thank you @metaskills and @brcarp! I'll keep you both posted on the maintainers' progress on these two options. I dig the use of Open3, good idea. |
* Do not shell out directly with `%x()` to any executable. Instead, use the new Open3 based `NewRelic::Helper.run_command` method. * The new `NewRelic::Helper.run_command` should prevent any unwanted error messages pertaining to binary execution from appearing in any output or log unless the log level is set to 'debug'. * When executing an external binary, make sure it exists first * If the 'hostname' binary does not exist, have `NewRelic::Agent::Hostname.get_fqdn` fall back to `get`, which uses `Socket`. * When using 'uname' for JRuby to determine the platform, use 'unknown' if the 'uname' call fails * Introduce new `NewRelic::CommandExcutableNotFoundError` and `NewRelic::CommandRunFailedError` error classes to help with logic flow. * Bring in 'minitest-stub-const' as a development dependency for stubbing constants resolves #697 Thank you to @metaskills for submitting #697 and pointing out that 'hostname' will not be available to AWS Lambda Ruby functions. Thank you to @brcarp for suggesting the use of Open3 as an improvement over `%x()` to handle output. Thank you to both @metaskills and @brcarp for their continued input and maintainer collaboration on issue #697
Hi! My name is Ken Collins and I work on Ruby/Rails integration with AWS Lambda. More details here. https://lamby.custominktech.com. I've done posts before on how to use APM with Rails and Lambda and today I noticed a new issue when shutting down an instance when working on a simple task runner project. There is no
hostname
on AWS Lambda.My assumption was that
Hostname.get_fqdn
is the reason for this. If I useNEW_RELIC_AGENT_ENABLED=false
the error disappears. Theget_fqdn
method is written in such a that I should see an"Unable to determine fqdn #{e}"
message but I do not. I attempted to override theget_fqdn
method but still saw the "No such file or directory - hostname" message.I've gone thru the code here, but can not find where the error happens. It does not cause a major issue but thought I'd ask is there anywhere any ideas you may have on where this message is coming from?
The text was updated successfully, but these errors were encountered: