Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 59bf6eae authored by Mike Yu's avatar Mike Yu Committed by Gerrit Code Review
Browse files

Merge "Set correct DNS server to the stats"

parents 2e53ad23 d6a26701
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -580,11 +580,8 @@ int res_nsend(ResState* statp, span<const uint8_t> msg, span<uint8_t> ans, int*
            if (!usable_servers[ns]) continue;

            *rcode = RCODE_INTERNAL_ERROR;

            // Get server addr
            const IPSockAddr& serverSockAddr = statp->nsaddrs[ns];
            LOG(DEBUG) << __func__ << ": Querying server (# " << ns + 1
                       << ") address = " << serverSockAddr.toString();
                       << ") address = " << statp->nsaddrs[ns].toString();

            ::android::net::Protocol query_proto = useTcp ? PROTO_TCP : PROTO_UDP;
            time_t query_time = 0;
@@ -650,8 +647,9 @@ int res_nsend(ResState* statp, span<const uint8_t> msg, span<uint8_t> ans, int*
                    // KeepListening UDP mechanism is incompatible with usable_servers of legacy
                    // stats, so keep the old logic for now.
                    // TODO: Replace usable_servers of legacy stats with new one.
                    resolv_cache_add_resolver_stats_sample(
                            statp->netid, revision_id, serverSockAddr, sample, params.max_samples);
                    resolv_cache_add_resolver_stats_sample(statp->netid, revision_id,
                                                           receivedServerAddr, sample,
                                                           params.max_samples);
                    resolv_stats_add(statp->netid, receivedServerAddr, dnsQueryEvent);
                }
            }
+15 −3
Original line number Diff line number Diff line
@@ -6122,9 +6122,15 @@ TEST_F(ResolverTest, KeepListeningUDP) {
    const struct TestConfig {
        int retryCount;
        int delayTimeMs;
        int expectedDns1Successes;
        int expectedDns1Timeouts;
        int expectedDns2Timeouts;
    } testConfigs[]{
            {1, 1500},
            {2, 3500},
            {1, 1500, 1, 1, 0},
            // Actually, there will be two timeouts and one success for DNS1. However, the
            // DnsResolver doesn't record the stats during the second iteration of DNS servers, so
            // the success and timeout of DNS1 is 0 and 1, respectively.
            {2, 3500, 0, 1, 1},
    };
    for (const std::string_view callType : {"getaddrinfo", "resnsend"}) {
        for (const auto& cfg : testConfigs) {
@@ -6151,7 +6157,13 @@ TEST_F(ResolverTest, KeepListeningUDP) {
                int fd = resNetworkQuery(TEST_NETID, host_name, ns_c_in, ns_t_aaaa, 0);
                expectAnswersValid(fd, AF_INET6, "::1.2.3.4");
            }
            // TODO(b/271405311): check that the DNS stats from getResolverInfo() is correct.
            const std::vector<NameserverStats> expectedCleartextDnsStats = {
                    NameserverStats(listen_addr1)
                            .setSuccesses(cfg.expectedDns1Successes)
                            .setTimeouts(cfg.expectedDns1Timeouts),
                    NameserverStats(listen_addr2).setTimeouts(cfg.expectedDns2Timeouts),
            };
            EXPECT_TRUE(expectStatsEqualTo(expectedCleartextDnsStats));
            thread.join();
        }
    }