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

Commit 80f6ad2f authored by Ken Chen's avatar Ken Chen
Browse files

Remove validity time constraint in DNS query log

Carriers will use DNS query logs in tests. Removes log expiration time
limit so logs persist long enough for 24 hour testing.

Bug: 279596912
Bug: 231264474
Bug: 200748696
Test: atest resolv_unit_test:DnsQueryLogTest
Change-Id: Ib98b16053d0386e98be370fa6138d667dfcb03c9
parent 5f01f311
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -58,13 +58,10 @@ uint64_t DnsQueryLog::getLogSizeFromSysProp() {
}

void DnsQueryLog::dump(netdutils::DumpWriter& dw) const {
    dw.println("DNS query log (last %lld minutes):", (mValidityTimeMs / 60000).count());
    dw.println("DNS query log:");
    netdutils::ScopedIndent indentStats(dw);
    const auto now = std::chrono::system_clock::now();

    for (const auto& record : mQueue.copy()) {
        if (now - record.timestamp > mValidityTimeMs) continue;

        const std::string maskedHostname = maskHostname(record.hostname);
        const std::string maskedIpsStr = maskIps(record.addrs);
        const std::string time = timestampToString(record.timestamp);
+2 −7
Original line number Diff line number Diff line
@@ -51,25 +51,20 @@ class DnsQueryLog {

    DnsQueryLog() : DnsQueryLog(getLogSizeFromSysProp()) {}

    // Allow the tests to set the capacity and the validaty time in milliseconds.
    DnsQueryLog(size_t size, std::chrono::milliseconds time = kDefaultValidityMinutes)
        : mQueue(size), mValidityTimeMs(time) {}
    // Allow the tests to set the capacity.
    DnsQueryLog(size_t size) : mQueue(size) {}

    void push(Record&& record);
    void dump(netdutils::DumpWriter& dw) const;

  private:
    LockedRingBuffer<Record> mQueue;
    const std::chrono::milliseconds mValidityTimeMs;

    // The capacity of the circular buffer.
    static constexpr size_t kDefaultLogSize = 200;
    // The upper bound of the circular buffer.
    static constexpr size_t kMaxLogSize = 10000;

    // Limit to dump the queries within last |kDefaultValidityMinutes| minutes.
    static constexpr std::chrono::minutes kDefaultValidityMinutes{60};

    uint64_t getLogSizeFromSysProp();
};

+0 −22
Original line number Diff line number Diff line
@@ -141,28 +141,6 @@ TEST_F(DnsQueryLogTest, CapacityFull) {
    verifyDumpOutput(output, expectedNetIds);
}

TEST_F(DnsQueryLogTest, ValidityTime) {
    DnsQueryLog::Record r1(30, 1000, 1000, "www.example.com", serversV4, 10);
    DnsQueryLog queryLog(3, 100ms);
    queryLog.push(std::move(r1));

    // Dump the output and verify the correctness by checking netId.
    std::string output = captureDumpOutput(queryLog);
    verifyDumpOutput(output, {30});

    std::this_thread::sleep_for(150ms);

    // The record is expired thus not shown in the output.
    output = captureDumpOutput(queryLog);
    verifyDumpOutput(output, {});

    // Push another record to ensure it still works.
    DnsQueryLog::Record r2(31, 1000, 1000, "example.com", serversV4V6, 10);
    queryLog.push(std::move(r2));
    output = captureDumpOutput(queryLog);
    verifyDumpOutput(output, {31});
}

TEST_F(DnsQueryLogTest, SizeCustomization) {
    const size_t logSize = 3;
    const ScopedSystemProperties sp(kQueryLogSize, std::to_string(logSize));