You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2020/03/16 03:03:27 UTC

[GitHub] [skywalking] gameover453 opened a new issue #4520: Enhanced Agent Hostname detection function

gameover453 opened a new issue #4520: Enhanced Agent Hostname detection function
URL: https://github.com/apache/skywalking/issues/4520
 
 
   Please answer these questions before submitting your issue.
   
   - Why do you submit this issue?
   - [ ] Question or discussion
   - [ ] Bug
   - [ ] Requirement
   - [X] Feature or performance improvement
   
   ### Requirement or improvement
   
   We know that the hostname detection method of skywalking-agent is provided by JVM API InetAddress.getLocalhost().GetHostName().
   
   https://github.com/apache/skywalking/blob/69e3d80e24b203bef4d86bfce2ef201a961373b0/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/os/OSUtil.java#L46-L54
   
   However, in some Linux system multiple network card scenarios (for example,container/ Alibaba Cloud ECS), the /etc/hosts file configuration is set in the container. Might look like:
   
   Here is a case where hostname resolution is not assigned
   
   in /etc/hosts,Only the following records:  
   
   ```shell
   ::1     localhost       localhost.localdomain   localhost6      localhost6.localdomain6
   127.0.0.1       localhost       localhost.localdomain   localhost4      localhost4.localdomain4
   ```
   
   In this case, if there is no default bound device, GetHostName() will reverse resolve the host name 127.0.0.1 to "localhost", which is usually not what we expected.
   
   So we may be able to make some improvements and perform a second detection for the case of returning "localhost", for example, from the linux kernel information:
   
   
   ```java
   // simple demo .When hostname is localhost, check again.
   public static String getHostName() {
       if (HOST_NAME == null) {
           try {
               InetAddress host = InetAddress.getLocalHost();
               HOST_NAME = host.getHostName();
           } catch (UnknownHostException e) {
               HOST_NAME = "unknown";
           }
       }
   
       if (HOST_NAME == "localhost"){
           try{
               HOST_NAME = new String(Files.readAllBytes(Paths.get("/proc/sys/kernel/hostname")), StandardCharsets.UTF_8);
           } catch (Exception e) {
               HOST_NAME = "unknown";
           }
       }
       return HOST_NAME;
   }
   
   ```
   
   
   
   Maybe things will change. Looking forward to feedback : ) .
   
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [skywalking] wu-sheng commented on issue #4520: Enhanced Agent Hostname detection function

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on issue #4520: Enhanced Agent Hostname detection function
URL: https://github.com/apache/skywalking/issues/4520#issuecomment-599890601
 
 
   @gameover453 From the JDK discussion you referred, I am a little confused. They said, they provide reasonable logic for getLocalHost. Basically, SkyWalking doesn't care about which files you changed, it is about we are using JDK API. Different OSs have different implementation JDK, and we expect the return value is consistent.
   
   I still can't see reading a linux specific file makes more sense. I think we shouldn't argue about change which file, because we don't require for that, we treat JDK implementation projects/vendors at an expert level, definitely better than us.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [skywalking] wu-sheng commented on issue #4520: Enhanced Agent Hostname detection function

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on issue #4520: Enhanced Agent Hostname detection function
URL: https://github.com/apache/skywalking/issues/4520#issuecomment-599381755
 
 
   I am asking to the Alibaba cloud team. Wait for some feedback.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [skywalking] gameover453 commented on issue #4520: Enhanced Agent Hostname detection function

Posted by GitBox <gi...@apache.org>.
gameover453 commented on issue #4520: Enhanced Agent Hostname detection function
URL: https://github.com/apache/skywalking/issues/4520#issuecomment-599959270
 
 
   I agree.
   This thing follows the JDK specification and we don't need to consider the JDK itself.
   In fact, this problem is actually a special scenario: the exact network device was not specified when the program was started, causing the apm-agent get a LoopbackAddress.
   
   Please close this issue.
   Thank you.
   
   
   Of course , I hope to provide some possible help for users who have encountered same problem.
   My solution is when the apm-agent hostname is "localhost", use information provided by "/proc/sys/kernel/hostname" in the kernel. just like  "/etc/hostname" variable. (Linux environment only).
   This does not necessarily work for any scenario, but it may help.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [skywalking] gameover453 commented on issue #4520: Enhanced Agent Hostname detection function

Posted by GitBox <gi...@apache.org>.
gameover453 commented on issue #4520: Enhanced Agent Hostname detection function
URL: https://github.com/apache/skywalking/issues/4520#issuecomment-599865184
 
 
   Thanks for the quick reply.
   
   Yes, usually we don't specify a bound network device for the program (such as when it runs in a pod, such as when it is deployed in Aliyun ECI).
   At this time, the program usually obtains the IP address "127.0.0.1" and obtains the "localhost" host name through reverse analysis(in /etc/hosts first hostname).
   
   There is a related discussion in openjdk-jira, see:
   [JDK-8062840](https://bugs.openjdk.java.net/browse/JDK-8062840)
   
   We don't think modifying /etc/hosts is a good option (though it works, but it is tedious and unreliable), so we try to modify the implementation of getHostName() to solve the problem.
   
   In fact, this is not a design issue.
   But I think we might be able to help improve the problem of apm-agent not displaying the correct hostname.
   
   Checking again when the hostname is "localhost", or omitting "127.0.0.1" if not specified, should help solve the problem.
   
   expecting reply  : )

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [skywalking] wu-sheng closed issue #4520: Enhanced Agent Hostname detection function

Posted by GitBox <gi...@apache.org>.
wu-sheng closed issue #4520: Enhanced Agent Hostname detection function
URL: https://github.com/apache/skywalking/issues/4520
 
 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [skywalking] wu-sheng commented on issue #4520: Enhanced Agent Hostname detection function

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on issue #4520: Enhanced Agent Hostname detection function
URL: https://github.com/apache/skywalking/issues/4520#issuecomment-599962924
 
 
   I think change and maintain a private version should not be a problem as this is a special case. If you have interests, could consider to change `OSUtil` into an agent service, which provide an override mechanism through the plugin. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [skywalking] wu-sheng commented on issue #4520: Enhanced Agent Hostname detection function

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on issue #4520: Enhanced Agent Hostname detection function
URL: https://github.com/apache/skywalking/issues/4520#issuecomment-599811485
 
 
   @gameover453 Seems there is IP in the host file. Are you in different case?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [skywalking] duffqiu commented on issue #4520: Enhanced Agent Hostname detection function

Posted by GitBox <gi...@apache.org>.
duffqiu commented on issue #4520: Enhanced Agent Hostname detection function
URL: https://github.com/apache/skywalking/issues/4520#issuecomment-599616989
 
 
   in aliababa cloud's k8s container service ACK, the pod name and its real ip will be append in /etc/hosts file
   
   here is an example:
   
   [root@pod-centos /]# cat /etc/hosts
   # Kubernetes-managed hosts file.
   127.0.0.1	localhost
   ::1	localhost ip6-localhost ip6-loopback
   fe00::0	ip6-localnet
   fe00::0	ip6-mcastprefix
   fe00::1	ip6-allnodes
   fe00::2	ip6-allrouters
   192.168.0.247	pod-centos

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services