Repository: quarkusio/quarkus
Issue: (vert.x-eventloop-thread-1) Unable to look up TXT record for host serverlessinstance0.oagmp.mongodb.net

### Describe the bug

I get the error:
(vert.x-eventloop-thread-1) Unable to look up TXT record for host serverlessinstance0.oagmp.mongodb.net.

In my contaiver resolv.conf file:

bash-4.4$ cat /etc/resolv.conf
nameserver 127.0.0.11
options ndots:0

I'm using the native image quay.io/quarkus/quarkus-micro-image:1.0.

It comes with ndots:0 by default.

Thanks in advance!


### Expected behavior

It find in native mode the look up TXT record for host serverlessinstance0.oagmp.mongodb.net.

### Actual behavior

It doesn't find the look up TXT record for host serverlessinstance0.oagmp.mongodb.net.

### How to Reproduce?

Steps to reproduce:

1) Configure the application.properties
application.properties
quarkus.mongodb.connection-string=
quarkus.mongodb.database=

quarkus.mongodb.native.dns.use-vertx-dns-resolver=true
quarkus.mongodb.native.dns.lookup-timeout=10s

2) Build in native mode

3) Start the application

### Output of `uname -a` or `ver`

Linux 25cf03bb9077 5.10.16.3-microsoft-standard-WSL2 #1 SMP Fri Apr 2 22:23:49 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

### Output of `java -version`

command not found

### GraalVM version (if different from Java)

I'm using quay.io/quarkus/centos-quarkus-maven:21.3.0-java11 to generate the native image

### Quarkus version or git rev

2.7.0.Final

### Build tool (ie. output of `mvnw --version` or `gradlew --version`)

Gradle 7.3.3

### Additional information

I'm using a mongo on Atlas cloud and it is a serverless instance.

Changed files:
extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/MongodbConfig.java
extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/dns/DnsClientProducer.java
extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/graal/MongoClientSubstitutions.java

diff --git a/extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/MongodbConfig.java b/extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/MongodbConfig.java
index c251966e883..d32223bbb02 100644
--- a/extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/MongodbConfig.java
+++ b/extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/MongodbConfig.java
@@ -71,11 +71,17 @@ public class MongodbConfig {
     @ConfigItem(name = "native.dns.server-port", defaultValue = "53")
     public OptionalInt dnsServerPortInNativeMode;
 
-    // mongo.dns.lookup-timeout
     /**
      * If {@code native.dns.use-vertx-dns-resolver} is set to {@code true}, this property configures the DNS lookup timeout
      * duration.
      */
     @ConfigItem(name = "native.dns.lookup-timeout", defaultValue = "5s")
     public Duration dnsLookupTimeoutInNativeMode;
+
+    /**
+     * If {@code native.dns.use-vertx-dns-resolver} is set to {@code true}, this property enables the logging ot the
+     * DNS lookup. It can be useful to understand why the lookup fails.
+     */
+    @ConfigItem(name = "native.dns.log-activity", defaultValue = "false")
+    public Optional<Boolean> dnsLookupLogActivityInNativeMode;
 }
diff --git a/extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/dns/DnsClientProducer.java b/extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/dns/DnsClientProducer.java
index 50f9b8d7d35..d1239265cf4 100644
--- a/extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/dns/DnsClientProducer.java
+++ b/extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/dns/DnsClientProducer.java
@@ -14,8 +14,10 @@
 
 import org.eclipse.microprofile.config.Config;
 import org.eclipse.microprofile.config.ConfigProvider;
+import org.jboss.logging.Logger;
 
 import io.quarkus.arc.Arc;
+import io.vertx.core.dns.DnsClientOptions;
 import io.vertx.mutiny.core.Vertx;
 import io.vertx.mutiny.core.dns.DnsClient;
 
@@ -29,6 +31,7 @@ public abstract class DnsClientProducer {
 
     private static final String DNS_SERVER = "quarkus.mongodb.native.dns.server-host";
     private static final String DNS_SERVER_PORT = "quarkus.mongodb.native.dns.server-port";
+    private static final String DNS_SERVER_ACTIVITY = "quarkus.mongodb.native.dns.log-activity";
 
     public static final String LOOKUP_TIMEOUT = "quarkus.mongodb.native.dns.lookup-timeout";
 
@@ -39,6 +42,8 @@ public static synchronized io.vertx.mutiny.core.dns.DnsClient createDnsClient()
         if (client == null) {
             Vertx vertx = Arc.container().instance(Vertx.class).get();
 
+            boolean activity = config.getOptionalValue(DNS_SERVER_ACTIVITY, Boolean.class).orElse(false);
+
             // If the server is not set, we attempt to read the /etc/resolv.conf. If it does not exist, we use the default
             // configuration.
             String server = config.getOptionalValue(DNS_SERVER, String.class).orElseGet(() -> {
@@ -50,9 +55,9 @@ public static synchronized io.vertx.mutiny.core.dns.DnsClient createDnsClient()
             });
             if (server != null) {
                 int port = config.getOptionalValue(DNS_SERVER_PORT, Integer.class).orElse(53);
-                client = vertx.createDnsClient(port, server);
+                client = vertx.createDnsClient(new DnsClientOptions().setLogActivity(activity).setPort(port).setHost(server));
             } else {
-                client = vertx.createDnsClient();
+                client = vertx.createDnsClient(new DnsClientOptions().setLogActivity(activity));
             }
         }
 
@@ -64,19 +69,23 @@ public static List<String> nameServers() {
         if (!new File(file).isFile()) {
             return Collections.emptyList();
         }
-
         Path p = Paths.get(file);
         List<String> nameServers = new ArrayList<>();
         String line;
         try (BufferedReader br = new BufferedReader(new InputStreamReader(Files.newInputStream(p)))) {
             while ((line = br.readLine()) != null) {
                 StringTokenizer st = new StringTokenizer(line);
-                if (st.nextToken().startsWith("nameserver")) {
-                    nameServers.add(st.nextToken());
+                if (st.hasMoreTokens()) {
+                    String token = st.nextToken();
+                    if (token.startsWith("nameserver")) {
+                        // If we do not have another token it means that the line is not formatted correctly.
+                        // So, throwing an exception is ok.
+                        nameServers.add(st.nextToken().trim());
+                    }
                 }
             }
         } catch (IOException e) {
-            e.printStackTrace();
+            Logger.getLogger(DnsClientProducer.class).error("Unable to read the /etc/resolv.conf file", e);
         }
         return nameServers;
     }
diff --git a/extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/graal/MongoClientSubstitutions.java b/extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/graal/MongoClientSubstitutions.java
index ca3f5e26d3f..2186a4c9384 100644
--- a/extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/graal/MongoClientSubstitutions.java
+++ b/extensions/mongodb-client/runtime/src/main/java/io/quarkus/mongodb/runtime/graal/MongoClientSubstitutions.java
@@ -116,7 +116,7 @@ final class CompressorSubstitute {
 }
 
 @TargetClass(InternalStreamConnection.class)
-final class InternalStreamConnectionSubtitution {
+final class InternalStreamConnectionSubstitution {
     @Substitute
     private CompressorSubstitute createCompressor(final MongoCompressor mongoCompressor) {
         throw new UnsupportedOperationException("Unsupported compressor in native mode");
@@ -179,7 +179,6 @@ public List<String> resolveHostFromSrvRecords(final String srvHost) {
             if (srvRecords.isEmpty()) {
                 throw new MongoConfigurationException("No SRV records available for host " + "_mongodb._tcp." + srvHost);
             }
-
             for (SrvRecord srvRecord : srvRecords) {
                 String resolvedHost = srvRecord.target().endsWith(".")
                         ? srvRecord.target().substring(0, srvRecord.target().length() - 1)