Closed eyalkoren closed 3 years ago
Following the requirement to provide a more comprehensive hostname detection algorithm and make it as compatible as possible with beats, I did some digging with the beats team and changed the spec accordingly.
I don't have enough resources to asses how generic and comprehensive it is, other than seeing it working wherever I tried it. It is certainly not 100% bulletproof, but our goals are more modest for now. Any comments, proposals and enhancements are very welcome.
@elastic/apm-agent-devs - please take a look, even if you did already.
Is using a language's standard library method for getting the hostname (e.g. socket.gethostname()
for Python, os.hostname()
for Node.js) acceptable? On unix-y systems these use the gethostname
syscall. On Windows (sigh), Node.js and Python use different Windows APIs for this:
Executing uname
and possibly hostname
will add some cold-startup time for serverless (e.g. Lambda) envs.
@trentm I think the consensus is that the gethostname
syscall is acceptable, and doesn't use DNS.
On the Windows end of things, I've been banging the drum for our python agent to drop Windows support anyway because we have no confirmed Windows users. So I'm not stressing about that side, at least for Python.
@trentm I think the consensus is that the gethostname syscall is acceptable, and doesn't use DNS.
👍 Avoiding any API that involves NDS lookup is indeed the main point here.
This is tricky indeed. Eventually, what we need is a language-independent spec. That's the only reason I chose to put it this way, but everything that can be done without invoking an external process is of course preferable, as long as it yields the same result. I will add inline comments saying that equivalent language-specific APIs can be used. Anyone that wishes to extend that to include concrete examples is very welcome. We may eventually "backport" the spec we come up here to ECS, so any input you put here would be useful.
Lastly, I just learned that the currently proposed algorithm can either return the simple hostname OR FQDN, so I will probably extend the algorithm a little bit to handle that.
Added some clarification on what can be used to replace invocation of external commands and extended the algorithm to clear domain parts if the discovered value is a FQDN.
@elastic/apm-agent-devs we just got a report that the link from APM traces to host metrics may be broken if the hostname discovery is not done as specified hereby, so please take a quick look to see whether such a fix is required in your agent
os.hostname()
, which uses thegethostname
syscall)socket.gethostname()
, which uses thegethostname
syscall)gethostname
which is a trivial wrapper aroundgethostname
syscall)