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

Log records show the hostname on which the native executable was generated #14423

Closed
vietk opened this issue Jan 20, 2021 · 5 comments · Fixed by #14603
Closed

Log records show the hostname on which the native executable was generated #14423

vietk opened this issue Jan 20, 2021 · 5 comments · Fixed by #14603
Labels
area/logging kind/bug Something isn't working
Milestone

Comments

@vietk
Copy link
Contributor

vietk commented Jan 20, 2021

Describe the bug

When a native application is using a log pattern that includes the hostname of the machine, then the hostname displayed is the one of the machine on which the native executable has been generated.

Imagine two machines with the following hostname :

  • build-time-hostname: the hostname of the computer used to build the native image
  • runtime-hostname: the hostname of the machine running the native image

If the application uses the following log format :

quarkus.log.console.format=%d{yyyy/MM/dd HH:mm:ss.SSS} %h %m%n

where %h should display the hostname, then log statements as shown below

logger.info("runtime hostname:" + InetAddress.getLocalHost().getHostName());

will output the following:

image

Expected behavior

I would expect the runtime-hostname to be used in the logs

Actual behavior

JBoss logging system uses org.wildlfy.common.net.Hostname to get a reference on the hostname.

But the references are stored in a static field which is initialized in a static block

    static {
        String[] names = doPrivileged(new GetHostInfoAction());
        hostName = names[0];
        qualifiedHostName = names[1];
        nodeName = names[2];
    }

At native image build time, the static block is recorded in the image heap and then the same value is used for any subsequent calls during the runtime of the application notably in the log system.

To Reproduce

I have reproduced the issue by modifying the basic quickstart project here : https://github.com/vietk/quarkus-quickstarts/tree/reproducer/build-time-hostname.
I use docker containers in order to have 2 different machine

Steps to reproduce the behavior:

  1. call mvn clean install -Pnative -DskipTests
  2. call docker run -h runtime-host-name -it --entrypoint=/target/getting-started-1.0-SNAPSHOT-runner -v $PWD/target:/target -p 8080:8080 quay.io/quarkus/ubi-quarkus-native-image:20.2.0-java11 that override the hostname with -h runtime-host-name
  3. call the service of the application http://localhost:8080/hello/greeting/helloworld

Environment (please complete the following information):

  • Quarkus version or git rev: 1.10.4.Final
  • Build tool: mvn

Best regards,
Kevin

@vietk vietk added the kind/bug Something isn't working label Jan 20, 2021
@ghost ghost added the triage/needs-triage label Jan 20, 2021
@gsmet
Copy link
Member

gsmet commented Jan 20, 2021

/cc @dmlloyd @jamezp

@dmlloyd
Copy link
Member

dmlloyd commented Jan 20, 2021

This surely must be a regression; I remember testing this way back. Perhaps relating to switching over to smallrye-common for the host name - maybe a substitution is missing now (i.e. pointing at the wrong class)?

@jaikiran
Copy link
Member

jaikiran commented Jan 22, 2021

Hello @dmlloyd,

Perhaps relating to switching over to smallrye-common for the host name - maybe a substitution is missing now (i.e. pointing at the wrong class)?

I guess that's indeed the case - this substitution in smallrye-common is targetting the wrong class https://github.com/smallrye/smallrye-common/blob/master/net/src/main/java/io/smallrye/common/net/Substitutions.java#L19 (target class should have been io.smallrye.common.net.GetHostInfoAction). I haven't checked rest o the code in that project. I guess there might be more such copy/paste migration issues?

@jaikiran
Copy link
Member

jaikiran commented Jan 22, 2021

I've raised smallrye/smallrye-common#75 with a patch. Having said that, I don't see how that one substitution alone will prevent the computed host name at build time to not be stored for runtime.

@jaikiran
Copy link
Member

I've opened #14603 with a potential fix.

@ghost ghost added this to the 1.12 - master milestone Jan 26, 2021
@gsmet gsmet modified the milestones: 1.12 - master, 1.11.1.Final Jan 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/logging kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants