Skip to content

The query log

An answered query, or a dynamic update, becomes a row in SQLite. You read the rows back over the API by time range, client and limit. Two settings decide what a row carries. The server redacts at the moment of writing, not at the moment of reading.

The server writes in batches through a bounded queue. A burst larger than the queue drops rows and does not slow the answers down. A read says how many rows it dropped inside the range you asked for.

Set telemetry_storage = "memory" in node.toml to keep the query log and the statistics on a tmpfs at the runtime root. No file of them is on a disk. A reboot empties them. A restart of the packaged service keeps them.

Its room, telemetry_memory_mib, holds the data, and the hourly counts of stats_retention_days are part of the data. A change of stats_retention_days whose days no longer fit the room turns the log off at the next pass of its writer. It stays off until a restart. Both settings wait for a restart (The query log in memory). The telemetry field of the health says where the log is asked to run and where it runs, and why it is off or full.

A query log in memory, on a tmpfs, has a guard of memory. While the log runs a statement, the guard reads the resident size of the whole server process. It stops the statement where that size grew by more than a quarter of the room of the log. The size counts from the start of the pass of the writer, or from the open of the reader. The guard stops writes as well as reads.

So memory pressure can stop a batch of rows. The pressure comes from a busy cache, or from a burst of long rows that wait in the queue of the log. The rows of the batch are dropped and counted under write_failed in dns_querylog_dropped_total, with the line could not write query log rows. A read of their range reports them as dropped. A query log on the disk has no such guard.

The server opens the query log beside its start, and answers DNS before the log is open. On most starts that takes a moment. After an upgrade, the server first brings the database up to date. For a large log that can take minutes.

The upgrade to this build runs these steps, in this order:

  • It copies the log once. It needs free space of about twice the size of the log on the disk of the state root. It also needs room for a temporary sort, which the server does not check.
  • A log that a build between two releases wrote can also need its names written in lower case. The server checks the free space for that before it begins, and asks for at most about twice the size of the log.
  • It builds an index for the sort by time taken. It first checks for free space of about 128 bytes for each row. The sort that builds the index needs temporary room too, which the server does not check.
  • It adds the column of the path of an answer, and the columns of the transport and of the AA bit. It adds the columns and the table of the new counts of each hour. It adds three tables of the lists of each hour: by record type, by response code and by blocked name. It adds the bands of time of each hour. These steps rewrite no row, so the server checks no free space before them.
  • It copies the record types and the response codes of every hour once, into a smaller layout. It first checks for free space of twice their size. That is a few megabytes on a home network, and up to a few hundred for five years of the busiest hours. With less space, it does not open the log, as for the copy above.
  • It copies the log a second time. Each row then holds the bytes of its addresses in place of their text, and the index by client and the index by name go. So each write of the log changes 40 to 50 percent fewer pages than before. The copy first checks for free space of about twice the log, as the first copy does. With less space, it does not open the log.

An hour that the server counted before the upgrade has none of the three lists. It has no bands of time either. They come with the next new row of that hour.

On a test machine with a network disk, a full log of 450 MiB took 43 to 57 seconds to be ready at its first start, and 45 seconds in the middle of five runs. That time includes the check of the whole file and the give-back of the pages that the copy freed. The file was in the memory of the system. A file that the system must first read from the disk takes longer. Meanwhile 4096 rows wait. A server that answers more than about 100 queries a second loses some of them, and counts them.

During the copy, the file and its write-ahead log take up to about twice the size of the log. The file comes back below its old size once the free pages go back. A log in memory whose room does not hold the copy starts empty, and the health says so under emptied. An older build does not open the log after this build copied it. Going back to an older build says what to do.

Until the open ends, the routes of the log answer 503 query-log-starting. The rows of the queries wait in memory, 4096 of them at most. Past that, a row is lost and counted. A crash, or a stop that comes while the log still opens, loses the rows that wait. The query log answers query-log-starting has more.

The health report says where the log is, in the query_log field of GET /api/health and in the line of tadoru health:

  • opening is the wait above.
  • ready means the database is open and the routes of the log answer. A later write that fails shows as lost rows in the server log and the loss counter, not in this field.
  • off means the database did not open, and the server logs why. It stays off until the next start. The rows of its queries are counted as lost, and the routes of the log answer 503 unavailable.

The log is off too in two cases:

  • A start cannot write or sync telemetry.place in the state root, where the place of the query log, or its directory in memory, changes.
  • A start cannot sync the state root after it reads that file.

So the file names the place of each store that took rows, or its pending record, for the backup and the rewrite. In both cases, free room on the disk of the state root, or fix its owner, and start again.

Where telemetry.place does not read, the place is not known. On the disk the log still runs in the state root. No backup carries it and no rewrite takes it until the file is reset. None of the three makes tadoru health fail, because the server answers DNS.

A file of the log can be damaged, such as by a copy of the state root that was taken while the server ran and that has no -wal beside it. Such a file can open and answer for days, because no read takes the whole table. Then the copy of an upgrade reads one row twice, and the log stays off.

So before an upgrade copies a table of the log, the server checks the whole file with PRAGMA quick_check. It first reads the file once from start to end, where the file fits in half of the free memory, so the check reads from memory. On a test machine with a network disk, the read and the check of a log of 1 GB took 6 seconds. Without the read first, the check took 132 seconds, and on an SD card it takes longer. The health says opening meanwhile.

Where the check finds damage, the server moves the file aside as telemetry.sqlite.damaged-<time>, with the time in UTC, such as telemetry.sqlite.damaged-20261124T101530Z. Then it starts a new, empty log, as on a first start. One warning names the damage, the kept file, and the command that gets its rows back. Run that command as the account of the server:

Terminal window
sudo -u tadoru sh -c 'umask 077; sqlite3 /var/lib/tadoru/telemetry.sqlite.damaged-20261124T101530Z .recover | sqlite3 /var/lib/tadoru/telemetry.sqlite.damaged-20261124T101530Z.recovered'

sudo -u tadoru gives the new file the owner of the server, and umask 077 keeps it readable by that account alone, as the store is.

The server never reads or deletes the kept file, and it takes its full size on the disk until you delete it. A damaged query log was moved aside says how to get its rows back.

While a backup reads the log, or while another program holds the file open, the server does not move it. The log is then off for this start, and the next start tries again.

The check has these limits:

  • It runs only before an upgrade copies a table, not at each start. A file that is damaged after its upgrade stays hidden until a read meets the damage.
  • It does not run on a query log in memory. A damaged log there stays off until a reboot, or until you delete it with the server stopped.
  • A file whose first page or schema is damaged does not open at all. The log is off with the error of the open, and you move the file aside by hand, as the troubleshooting page says.
  • A check that cannot read a page, such as for an input error of the disk, says nothing about the file. The log is then off for this start, and the file stays where it is.

A row holds six facts: when the query arrived, which client asked, what was asked for, what was answered, how long this server took, and where the answer came from. The source is cache, stale, synthesized, forwarded, recursed, local or blocked.

The name is written in lower case. DNS does not tell WWW.Example.COM from www.example.com, so the log keeps one form, and the busiest names count the two as one name. Only the letters A to Z change. A byte outside ASCII is written as \ and three digits, such as \195, and it stays as it is. Some resolvers mix the case of the names they ask on purpose, and the log does not keep that case.

The upgrade to this build wrote the rows of an earlier release in lower case as well. The hourly lists of the busiest names that an earlier release made keep the case the client sent. The list of a range adds the cases of a name together.

recursed is an answer the server walked to from the root. stale is an answer from the cache past its time to live, because no current answer came in time. Its rows show which names an outage touched. synthesized is an answer the server built from the proof of a signed zone that a range of names does not exist. It is an NXDOMAIN, an empty answer or a wildcard answer, and no query went upstream. The cache hit count leaves it out, because the cache held no answer under the name asked.

A refresh that the server makes on its own, to renew an answer before it expires, writes no row. So an upstream sees more queries than the log holds.

Which client asked is two columns: the address, and the name that clients.toml gives the client. An entry matches by address, by subnet, or by the address the query arrived on. So the two columns can tell you different things. A query that no entry names reads client_name as default, the client that every other query falls back to. The column holds the name and not a number, so a row still reads the same after you rewrite the file. A row written before this column existed has no name at all, because nothing recorded one. The three ways to recognize a client has the entries that give a name. Which entry wins gives the order they are read in.

Each query and each dynamic update also keeps client_group. It is the group whose policy the client ran under, and default for a client that no group claims. A blocked row repeats it in block_group. A blocked row that an older build wrote has block_group and no client_group. store_clients off leaves both out of new rows, and a redaction of client clears both from every row.

A query that came through a load balancer or a proxy has a third column, via:

  • A load balancer in proxy_protocol_from names the client in a PROXY header.
  • A proxy in http_trust names the client in an HTTP header.
  • The address column then holds that client, and via holds the machine that relayed the query.

A query that came straight from its client has no via. A request on doh.sock has none either, because a peer on that socket has no address. A row written before this column existed has none.

A blocked row carries four more things:

  • The kind of rule that matched. It is source for a list, and baseline for an entry at the top of blocking.toml. It is group for an entry of the client’s own group, and regex for a pattern rule.
  • The list that holds the rule. It is empty for one of your own entries and for a pattern rule, because neither is a list’s.
  • The rule as this server compiled it. For a pattern rule, the column holds the pattern, written the way you wrote it.
  • The group whose policy applied. It is the group the client is in, and default where no group claims it.

With store_names off, the rule is left out as well as the name. A rule is a name, and a server that must not store one must not store the other.

Two more kinds name no rule at all. canary is the Firefox canary domain, and private-relay is an Apple Private Relay start-up name. This server answers both from a table of its own and not from a list. The list, the rule and the name are all empty on such a row. Keeping a device on this server has the two settings that turn them on and off.

These two kinds stay in the row with store_names off, and each of them names its name. Every Firefox and every Apple device asks these names on every network it joins. So the row says which device features are on, and not what somebody read.

A row blocked for a name inside its answer carries two more:

  • block_name is the name in the alias chain that matched.
  • chain is the whole walk as a list of names, with the name asked for first.

Both are empty for a row that the name asked for blocked. That is how a row says which of the two tests fired. Both follow store_names, because both are names. A chain too long for one column is left out whole, and block_name still says what matched. The API answers chain as a list of names, so jq reads it without a second parse.

Every row also carries policy. It says whether the blocking test ran at all:

  • applied is a query that the test ran for, whether or not a rule matched it. It also covers a query that the test never reached: a malformed one, and one from a client this server does not resolve for. Neither had a rule skipped for it, which is what the other three values say.
  • bypassed is a client in bypass, which the test skipped entirely.
  • disabled is a query while blocking is off for every client. Either the switch of tadoru blocking disable is off, or the setting enabled = false of blocking.toml says so. GET /api/blocking/state tells which of the two, and so does tadoru blocking status.
  • group-off is a group with blocking = false, which tests nothing for the machines in it.

The three columns above can be empty under applied too, so policy names only one reason among them. A row written before this column existed reads applied, because nothing recorded what a build that old did not know to ask.

Every row carries dnssec, the state that the signature check reached:

  • secure means a chain of signatures runs from the keys of the root to the answer.
  • insecure means a proof says the zone is not signed.
  • bogus means a chain has to run to the answer and is broken. Such a row went out as SERVFAIL, unless the client set the CD bit to ask for the data anyway.
  • indeterminate means this server cannot decide: it does not trust its clock, or it lost a trust point.
  • unchecked means nobody looked. It is the state of a server with dnssec_validation off.

The column is empty for an answer that this server wrote itself: a zone it holds, a blocked name, and a refusal.

Every row carries extended_errors, the Extended DNS Error codes that the client received, in the order they went out. The API answers them as a list of numbers, for example [6] for an answer that failed its signature check. The list is empty where the answer carried no code, and for a query with no OPT record, because the codes go in that record. A row that an older build wrote has no such field, because that build did not record its codes. The text of each code is not kept. Neither privacy setting clears the numbers, because a number names neither a machine nor a name. An EDE: line in dig says what each code means.

upstream names the upstream that answered a forwarded query. It is its address and port, such as 9.9.9.9:853. For a forwarder with no addresses that a SOCKS5 proxy reaches by its name, it is the name and port, such as dns.example:853. It is the server whose reply the client got. Where every upstream failed, it is the one whose failure code the client got, and not one that stayed silent after it.

These queries have no upstream:

  • A query that no upstream replied to.
  • An answer from the cache or from a zone of this server.
  • A recursed query whose walk failed, because the SERVFAIL is this server’s.
  • A recursed query whose walk had more steps than the log keeps.
  • A row that an older build wrote.

For a recursed query, upstream is the name server whose reply ended the walk, and not the servers that sent the walk on to it.

path shows how the server got the answer. It lists each exchange that forwarding or recursion had with a server for the query, in the order they started. Each step holds:

  • the server, as an address and a port or a name and a port, as upstream does, and its transport
  • the zone that the walk asked, which is absent when forwarding
  • the name and the type that went out
  • the reply
  • the number of queries sent
  • the time it took, in microseconds
  • what it was for

The reply is one of these words:

  • answer, referral, nodata or nxdomain
  • unusable for a reply that the server does not use
  • timeout
  • failed for a connection that failed
  • lost for the slower half of two servers asked at once
  • the name of another response code, such as SERVFAIL

What a step was for is one of these:

  • answer for the question itself
  • lookup for the address of a name server
  • chain for a DNSSEC key or signature that the answer needed
  • probe for the server’s own check of an upstream that was resting

A truncated reply that the server asked again over TCP is one step with 2 queries.

The log keeps 64 steps for one query and 8 KiB of text for one path. Past either, it keeps the first steps and counts the rest in left_out. Queries that waited for the same answer all show the path of the one resolution that answered them. A stale answer that went out because its refresh failed shows the path of that refresh.

These answers have no path:

  • A stale answer that went out while its refresh still ran.
  • A stale answer whose refresh did not start.
  • A stale answer held after a failure.
  • An answer from the cache or from a zone of this server.
  • A row that an older build wrote.

Turning store_names off also stops the server from building a path at all.

transport says how the query came:

  • udp or tcp
  • tls for DNS over TLS
  • https for DNS over HTTPS on HTTP/2 or HTTP/1.1
  • quic for DNS over QUIC
  • h3 for DNS over HTTPS on HTTP/3

A query that a proxy sent on the local socket of DNS over HTTPS is https. Rows from before this version say https for DNS over HTTPS on HTTP/3 too, and they keep that word. store_clients covers the column, because on a network with one client of DNS over HTTPS, https names that machine.

authoritative is true where the answer has the AA bit, which a zone of this server sets. An alias in a zone that leads to a name outside it keeps the bit, though an upstream answered the rest. That row is forwarded or recursed, and authoritative. It is false for these answers:

  • an answer from the cache or from upstream alone, though the upstream set the bit
  • a failure or a refusal that this server wrote
  • an update

Neither privacy setting clears it. Rows that an older build wrote have neither field.

A dynamic update is a row too, with kind set to update. Its name is the zone it changes, and its qtype is 6 (SOA). Its rcode is the code that answered it:

  • REFUSED for a sender outside the policy or outside query_from
  • NOTAUTH for a zone this server does not hold
  • SERVFAIL for a zone that is stopped

An update that could not be read has no name. source is local, and policy means nothing for an update. Every other row, and every row from before this version, is query.

An update whose client goes away before the answer still has its row. The row shows the code that the server came to, or SERVFAIL where the server dropped the update without applying it. A message that the rate limit stops has no row.

Updates are left out of the statistics, and an hour that held only updates has no hourly statistics. The metric dns_updates_total counts each update once by what the server did: applied, unchanged, refused or failed.

A zone transfer request is a row too, with kind set to query, as for any query. Its qtype is 252 (AXFR) or 251 (IXFR). Its rcode is the code of its first message: NOERROR for a transfer, or the code of its refusal, such as REFUSED. The row of a transfer has source set to local.

The server writes the row as the transfer starts, so the row does not say whether the transfer went on to its end. The log line sent a zone transfer or cut a zone transfer says that. So does the metric dns_transfers_total, which Logs and metrics lists.

Terminal window
S=./data/run/api.sock
A="authorization: Bearer $TOK"
# The last hundred rows, newest first.
curl -s --unix-socket $S -H "$A" "http://localhost/api/queries?limit=100"
# One client, between two moments, in milliseconds since the Unix epoch.
curl -s --unix-socket $S -H "$A" \
"http://localhost/api/queries?client=192.0.2.10&from=1788900000000&to=1788999999999"
# Why each blocked row was blocked.
curl -s --unix-socket $S -H "$A" "http://localhost/api/queries?limit=100" \
| jq '.rows[] | select(.source=="blocked")
| {client_name, name, block_group, block_origin, block_list, block_rule,
block_name, chain}'
# Hour by hour for the last 31 days, and the busiest names.
curl -s --unix-socket $S -H "$A" http://localhost/api/stats/hourly
curl -s --unix-socket $S -H "$A" "http://localhost/api/stats/top?kind=domains&limit=20"

Those eight fields answer “why was this name blocked for that machine”. block_group is the policy that ran. What a query is tested against says what each group tests against.

Every role reads the log and the statistics. API Reference has each parameter, its range, and what the answer carries.

Filters narrow the rows. A row has to match each filter that you send. A filter takes several values separated by commas, 16 at most. A row matches if it matches one of them:

Terminal window
# The failed answers of one device, for a name and the names under it.
curl -s --unix-socket $S -H "$A" \
"http://localhost/api/queries?client_name=kids-tablet&name=example.com&subtree=true&failure=true"
# Every name that holds "ads", such as ads.example.com. and myads.example.net.
curl -s --unix-socket $S -H "$A" "http://localhost/api/queries?name_contains=ads"
# Two response codes, and then the blocked rows of one group.
curl -s --unix-socket $S -H "$A" "http://localhost/api/queries?rcode=SERVFAIL,REFUSED"
curl -s --unix-socket $S -H "$A" "http://localhost/api/queries?group=kids&source=blocked"

failure=true finds the answers that failed: a query that was not blocked, with a code other than NOERROR and NXDOMAIN. name finds the name in any case, and subtree=true adds the names under it. Send a name with letters outside ASCII in its xn-- form, such as xn--mnchen-3ya.de. The server refuses name=münchen.de.

name_contains finds each name that holds a text, in any case. It is a plain substring with no wildcard, so % and _ are characters too. It matches the name as the log shows it: in lower case, with its last dot, and with each byte outside ASCII as its escape. So search the ASCII text of the log:

  • A name with letters outside ASCII that a client sent in its xn-- form holds that form, such as xn--mnchen-3ya.de..
  • A name that a client sent with those bytes holds their escapes, such as m\195\188nchen.de..
  • Neither text finds the other.

The text takes 1 to 255 characters from ! to ~. That is a limit of the search, not of DNS. A name with many escapes can be longer. To find it, send a part of it. name_contains=. finds every row that holds a name. name_contains combines with name, subtree and every other filter, and name and subtree work as before. A server of an earlier version does not know name_contains, and answers as if it was not sent. In a URL, + is a space, so name_contains=a+b is refused.

name_contains uses no index, so each answer can count up to 65 536 rows that it reads and does not give. These reads count them too:

  • each other filter, name and client included
  • a page sorted by duration with no after
  • a page with before
  • a read with after that sends a filter, a from above 0 or a to below 9223372036854775807

A read with after, no filter, no from above 0 and no lower to waits for nothing, whatever its sort. The server runs two such reads at once, and the others wait in turn. A read that gets no place within a second gets 429 with the type /problems/busy and Retry-After: 1. Ask again a second later. The query log refuses a filter lists these reads.

qtype and rcode take a name, such as AAAA or SERVFAIL, or a number. A filter does not find a new row that was written with its privacy setting off:

  • With store_names off, name and name_contains find no new row.
  • With store_clients off, client, client_name and group find no new row.

Older rows keep those values until a redaction clears them, as Privacy says. A row from before this version has no group, so group does not find it. A value that does not read is a 400, and the problem says what the filter takes.

An answer holds 1000 rows at most, and limit in the answer says how many it holds at most. To read more, page with the cursors of the answer, and do not move to:

Terminal window
# The next page, older rows newest first: send back the before of the answer, as it came.
curl -s --unix-socket $S -H "$A" "http://localhost/api/queries?limit=100&before=$BEFORE"
# The rows written since: send back its after. Ask again at once while caught_up is false.
curl -s --unix-socket $S -H "$A" "http://localhost/api/queries?after=$AFTER"

Each row comes once across the pages, while the server writes new rows. A row that the server wrote late, with an older at than rows already read, comes with after. An answer without before is the last page. The after of a before answer is that of the first page, so a poll keeps the after of its own last answer.

A cursor carries no filter. If you change a filter, from or to, the read starts at the place of the cursor with the new filter. Send before or after, not both. Both is a 400. So is a cursor that this server did not write, with the type /problems/bad-cursor. After a restore of the query log, start again without a cursor. unreadable counts the rows that this build cannot read and passed over.

One answer reads 65 536 rows of the log at most, whether they match or not. Where it stops there, it holds the rows that it found and a cursor at the place it reached. So an answer can hold fewer rows than limit, or none, and still carry before. Send it back to go on. An after read that stops there answers caught_up as false, so ask again at once. A filter that few rows match, over a long range, takes a few answers.

The answer says how many rows were dropped inside the range, so an incomplete answer says so and does not look complete. A log with gaps and no way to know is worse than one that reports what it lost.

The hourly buckets carry the counts and the latency at the middle and at the tail. A bucket is kept for five years (1826 days) after the hour it counts, so it outlives the rows it was folded from. A question about last month has an answer after those rows are gone.

Each hour also keeps lists: its busiest names, its busiest clients and its most blocked names. Together they take a quarter of the size bound of the log at most. Past it, the lists of the oldest hours go before any row does, and those hours keep their counts. So the top lists of an old range can name less than they did, while the counts of the range stay whole. The rows keep at least half of the size.

The server counts the pages of the lists as it writes them, so it knows their size without reading them. It measures them again in two cases: once after the upgrade to this release, and after it compacts a file of an older layout with VACUUM. On a log with more than 128 MiB of data, a thread of its own does this, while the log goes on taking rows. The log says when the measure starts and when it ends. It gives the time it took and the bytes of the lists.

Until the measure ends, rows still go by retention_days, but no row goes to make room. So the file can pass retention_mib for that time. At the top of retention_mib, with 16 GiB of lists, that can be a few minutes. If the measure fails, rows go to make room again, and the server tries again a minute later.

So both top lists say how far back they name anything. The answer of /api/stats/top is { "ranks": [...], "names_since": 1789134000000, "names_missing": false }. It holds:

  • the list
  • the start of the oldest hour of the range whose list names a key, in milliseconds since the Unix epoch
  • whether a later hour lost its names

The questions of an older hour are in other alone.

names_since is absent where no hour of the range names one, as in these cases:

  • a range with no question
  • a range so old that its lists went to the size bound
  • a range after a purge of name, until a later hour holds names
  • a range that the server counted with store_names off

A later names_since does not always mean lost names, because a quiet hour has no list. Names were lost only in two cases. Either /api/stats/hourly shows an hour with questions before names_since, or it shows a later hour with questions that the list does not name.

names_missing says the second. It is true where an hour after names_since had questions and its list names nothing. The cause is one of these: the setting was off then, a purge cleared the list, or its questions named nothing. It is false where names_since is absent.

/api/stats/top-blocked has both fields too, for the blocked names. For kind=clients, both follow the clients, and store_clients and a purge of client move them. An earlier release answered the list alone, so a script that reads it needs .ranks now.

One answer of /api/stats/hourly holds 744 hours (31 days) at most. Both ends of a range are inside, so the hour that starts at to is in the answer. With no from, it answers the 744 hours that end with the hour of to, or of now. A range that holds more hours is refused with 400 and the type /problems/range-too-long. Ask for a long range, such as a year, in parts of 744 hours at most. Start each part at the start of the hour after the hour of the to of the part before. If that to is 12:30, the next part starts at 13:00. The detail of the 400 names the timestamps.

Each hour also says how the questions were answered and how they came:

  • devices counts the devices that asked. A client that clients.toml names counts once, whatever addresses it used. A client with no name counts once for each address, so a phone with temporary IPv6 addresses can count more than once. An hour has no devices where no question names a client, or where the server first counted the hour with store_clients off. An hour that it counted before you turned the setting off keeps its count.
  • forwarded, recursed, local, stale and synthesized count the answers of each source, as the source of a row says. authoritative counts the local answers from a zone of this server, so it is at most local.
  • failures counts the answers that failure=true finds. failed counts SERVFAIL alone.
  • transports counts the questions that came over udp, tcp, tls, https, quic and h3. A row written with store_clients off has no transport, so the sum can be less than queries. An hour that an older version counted holds its questions over HTTP/3 in https, and h3 reads 0 for it.
  • qtypes counts the questions by record type, such as A, AAAA or TYPE65280 for a type with no name. rcodes counts them by response code, such as NOERROR or RCODE23. Each hour holds its 32 most frequent types, or its 16 most frequent codes. other holds the rest, so each sums to queries. No privacy setting covers them, and no purge drops them.

An hour that an earlier release counted has none of these fields.

The server folds the query log into the hourly counts every five minutes. The fold reads the log beside the writes, so a busy hour does not make the new rows wait. The following drop a fold that is reading, and the next one starts at once:

  • a redaction
  • a purge
  • a change of store_names or store_clients

So the counts can wait longer than five minutes while these repeat.

While a fold reads, the file can be over retention_mib by about two sixteenths of it. That is 32 MiB at least, and about 64 MiB at the default size. It is made of two parts:

  • On the disk, the data can pass its size by the margin of the prune below.
  • The write-ahead log can pass it by the allowance of the fold, a sixteenth of retention_mib and 16 MiB at least.

The write-ahead log grows with the new rows, and no row is removed to make room for it. A fold stops where it grows the write-ahead log past its allowance, or where it reads for 10 minutes. The next fold then waits five minutes. The file comes back under its size after the fold stops and the prune removes what came in meanwhile.

At the default retention_mib, a high rate of queries for a long time stops the folds of a busy hour late in the hour. The counts of that hour then wait until the rate falls. On the machine where it was measured, an estimate that counts the log of the new rows alone gives about 1,800 queries a second. At such a rate the file fills within the hour, and old rows give way to new ones. That grows the log too, so the real rate is lower: down to about 900. A larger retention_mib raises the limit. The log says when a fold starts, ends or stops. It warns when the folds of one hour keep stopping, and when no fold was written for 30 minutes.

Two hours can come from the query log itself: the hour that holds now, and the hour before it in the minutes after it ended. This holds where the counts do not hold all of such an hour yet. One count of those rows answers every read for 10 seconds, so the answer is at most 10 seconds behind the log. The overview asks three routes at once, and it counts the rows once. A redaction or a purge drops that count at once.

Two cases answer what was folded of such an hour instead, which can be some minutes behind:

  • an hour with more than 30 000 rows
  • a read that waits more than a second for a count that another read runs

In the 10 seconds after a prune of the log by size, a count can also still hold rows that the prune removed.

Such an hour, and the hour that holds now, carry "counting": true. That holds whether the answer counted the hour from the query log or took what was folded of it. Every other hour carries false, and can still change too, where a later fold or a row written late into it moves its counts. An older hour shows what was counted of it, or is absent, until the folding reaches it. The passes after a start do that first.

An hour that took what was folded of it, in one of the two cases above, also carries "behind": true. Every other hour carries "behind": false, and so does an hour counted from the query log, which is at most 10 seconds behind it. So a chart can mark an hour that can be some minutes behind. After a restart, the first fold has not yet reached the rows that the server wrote since. Until it does, the server cannot tell which rows of an hour of more than 30 000 rows wait. Such an hour can then carry "behind": true though it is folded.

The 50th, 95th and 99th percentiles of each hour are exact, but the percentiles of two hours do not add up to those of both. /api/stats/latency gives the three for a whole range of hours:

Terminal window
# The response time of the last 7 days, in milliseconds since the Unix epoch.
curl -s --unix-socket $S -H "$A" "http://localhost/api/stats/latency?from=$(( ($(date +%s) - 7*86400) * 1000 ))"

It takes from and to as /api/stats/top does, with no limit on the number of hours, and every role reads it. The answer:

{"answers": 51234, "queries": 51300, "since": 1789134000000, "counting": true, "behind": false,
"p50": {"from_us": 0, "to_us": 100}, "p95": {"from_us": 31600, "to_us": 42200},
"p99": {"from_us": 10000000}}

Each figure is a band of time, in microseconds: the answers that took at least from_us and less than to_us. The exact percentile of the same answers is inside the band. Each hour counts its answers in 42 bands: one under 0.1 ms, eight in each tenfold step from 0.1 ms to 10 s, and one of 10 s and more. The last has no to_us. Within those 10 s, the upper edge of a band is at most 34 % above its lower edge. So "p50": {"from_us": 0, "to_us": 100} says that half of the answers took less than 0.1 ms, and nothing finer. That is common for a network whose answers come from the cache.

An hour that an earlier release counted has no bands, and is left out of the figures. answers counts the answers that the figures cover, and queries counts all the questions of the range. The two differ where some hours are left out. since is the oldest hour with bands. An hour after it can still have none, where a late row made the server count an old hour again. After the upgrade, the figures of a range of 30 days cover all of it once the server has run for 30 days. The figures are absent where no answer is covered.

counting is true where the range holds an hour that is still being counted, as on /api/stats/hourly. behind is true where such an hour took what was folded of it, in the same two cases. The figures can then be some minutes behind.

/api/stats/top ranks names by the questions asked. A name that is blocked often and asked less than your busiest names is not in its first rows. /api/stats/top-blocked ranks by the blocked questions instead:

Terminal window
curl -s --unix-socket $S -H "$A" "http://localhost/api/stats/top-blocked?limit=20"

It takes from, to and limit as /api/stats/top does, and every role reads it. The answer is { "names": [...], "exact": true, "names_since": 1789134000000, "names_missing": false }. Each name has its key and its blocked count, the most blocked first. names_since is the oldest hour that names a blocked name, as on /api/stats/top.

names_missing is true where a later hour had blocked questions and its list names none. The cause is one of these: store_names was off then, a purge of name cleared the list, an earlier release counted the hour, or its blocked questions named nothing. An hour with questions and no blocked question loses no blocked name. One other row holds the blocked questions that the list leaves out, so the rows add up to the blocked questions of the range.

Both top lists count two hours from the query log, as /api/stats/hourly does. They are the hour that holds now, and the hour before it in the minutes after it ended. So in the normal case they are at most 10 seconds behind it. With store_names off, such an hour keeps the names that the last fold left, and other takes its new questions. store_clients does the same for /api/stats/top?kind=clients.

Each hour keeps its 1000 most blocked names. A name that is 1001st in every hour of a long range can still have the most blocks in the range. It is then not in the list. So exact says whether the list is the whole truth. It is false in these cases:

  • any hour of the range has more than 1000 blocked names
  • an earlier release counted an hour
  • the server counted an hour with store_names off
  • a redaction of name cleared the names of an hour
  • the answer took what was folded of the current hour while rows of it wait. That means an hour of more than 30 000 rows, or a read that waited a second for another count

A home network blocks tens or hundreds of names an hour, so exact is true in the normal case. An hour that the server counts with store_names off adds no name, and its blocked questions are in other. Hours that it counted with the setting on keep their names.

exact and names_missing answer two questions. exact says whether the list can be wrong. An hour with more than 1000 blocked names makes it false. So does an hour before names_since that had blocked questions. names_missing says whether names are gone after names_since. So exact: false with names_missing: false means a list that can miss a name, and no later hour that lost its names. Where names_missing is true, exact is false.

The rows come newest first. sort=duration sorts them by the time that the answer took, and order=asc turns any sort round:

Terminal window
# The slowest answers of one hour first.
curl -s --unix-socket $S -H "$A" \
"http://localhost/api/queries?sort=duration&order=desc&from=1788900000000&to=1788903600000"

sort takes time, the default, or duration. order takes desc, the default, or asc. Answers of the same duration come newest first with desc, and oldest first with asc. The answer names the sort and order that it used. Filters work with every sort. No other column sorts.

The cursors work in every order, and each row still comes once. Send before back with the same sort and order. A before of another sort is a 400 with the type /problems/bad-cursor. When you change the sort, start again without a cursor. after works in every order too. It takes the rows written since, in the order that the server wrote them, limit at a time. It sorts each answer in the order that you ask for.

With sort=duration, a range of 32 768 rows or fewer gives full answers. It counts every row of the range, with client or an exact name too, as with the other filters. With subtree, a range of more than about 21 800 rows can give an answer with fewer rows than limit, and before. In a larger range, the bound of 65 536 rows counts the rows outside the range too. So an answer can hold few rows, or none, with before. Send it back to go on.

store_names and store_clients decide what a row carries, and both are on by default. Turning one off stops new rows from carrying that value. What is not written cannot leak: not through a backup, not through a stolen disk, and not through a route somebody adds in two years.

store_names off also keeps the name out of a line that the server logs at warn. The server logs that line when a reply comes back in another letter case. The line names the question only for the client’s own question and the steps of its walk, and only with store_names on. A log at debug or trace is different:

  • A debug line names the zone of a refused transfer.
  • trace names every query, whatever store_names says, in the ring and in the file as well.

Where names must stay out, keep resolver and pipeline below debug. Logs and metrics says how.

store_names off also turns the cache snapshot off and deletes its file, because the file holds the names the house asked. When the setting comes back on, the next snapshot leaves out every answer that arrived while it was off.

Each of the two covers every column that holds the same fact:

  • store_clients off leaves out the address, the client name, via, the group of the client, the group of a blocked row, and the transport. The address of a load balancer can name one machine as well. So can https on a network with one client of DNS over HTTPS. A row that says kids-tablet still says which machine asked, and a group of one machine says it again.
  • store_names off leaves out the name asked for and the rule that matched it. It also leaves out the name and the chain of a blocked alias, the upstream that answered, and the path of the answer. A [[forward]] sends one suffix, such as home.lan, to its own servers, so its address tells which suffix the name was under. The steps of a walk name the zones it crossed.

Clearing name clears the upstream and the path as well. The count of rows that still carry the name counts a row that holds an upstream or a path alone.

Turning a setting off does not erase the rows already there. The answer to that change says how many rows still carry the value. Saying nothing leaves you believing the rows are clean. To clear them as well:

Terminal window
curl -s -X POST --unix-socket $S -H "$A" \
-H 'content-type: application/json' -d '{"column":"name","purge":true}' \
http://localhost/api/queries/redact

purge drops the aggregates built from that column too. A cleared row and a kept top list leave the value readable in the list. Somebody who asks for a value to be gone means the list as well. A purge of name drops the lists of the busiest names and of the most blocked names. The counts of each hour by record type and by response code stay, because a type and a code name no machine and no name.

A redaction of client, with or without purge, keeps the hourly counts of devices and of transports. A count names no address, so the statistics of the overview stay right after a redaction. But a count can still say something about one machine. On a network with one client of DNS over HTTPS, the https count of an hour says when that machine asked, and how much. The redaction does not clear that.

Those counts include the rows that wait for the fold of their hour. A redaction of client folds them first, by the privacy settings. Before the query log has read those settings, a redaction of client answers 503 with the type /problems/privacy-not-read. Nothing is cleared, and no record is written. A running server reads the settings before it serves the API, so it does not send this answer. The answer is a guard. A redaction answers privacy-not-read says what to do where it comes. A redaction of name keeps no counts, so it does not wait.

The clearing is written down in the query log’s own record: when, which column, how many rows, and who asked. Clearing a column is a thing somebody did, so it is a thing the record holds.

A redaction rewrites about the whole log, and each page of the rows goes to the write-ahead log once. No index holds a column that a redaction clears. So the redaction first measures what it can write. It refuses where the disk of the state root does not hold that, before it changes anything. The answer is 507 with the type /problems/no-room, and its detail names what the redaction can write and what is free. Nothing is cleared, and no record is written.

The first figure of a redaction of name reads only the header of the file and a few entries of its indexes. It is about twice the log without its lists.

A redaction of client also folds the rows that wait. Its first figure reads those rows too, up to 65,536 of them, with a budget of 2 seconds. It finds the hours that they are in, whatever the clock of the machine did. It counts each time that the fold rebuilds an hour:

  • all three lists of the hour at the longest names, written and freed, about 30 MiB at pages of 4 KiB
  • the pages of its counts

It counts all three lists whatever the privacy switches, because a reload of the configuration can turn a switch on while the fold runs. It also counts as freed every list page that the file holds, or every live page of the file where that count is not known. The reason is that the fold clears all the lists of an hour that holds only updates, with the switches on or off.

Where more rows wait, or the read takes longer, it counts every hour of the log, and each waiting row as a rebuild. This read holds the writer. It checks its budget after each row, so a slow read of the disk can run past it. A seek in each hour that it found follows the read, with no limit of time.

Where the first figure does not fit, the server measures the rows and the waiting hours for 5 seconds at most. That gives a figure about the size of the rows of the log. If the measure does not end in time, the server uses the first figure. The server reads the free space before the measure and again before its answer. Where it cannot read the free space of the disk of the state root, the redaction runs without that check, and the log says so.

The temporary files of SQLite count too, for a redaction of either column. They count on the disk of the directory that SQLite uses for them: SQLITE_TMPDIR, TMPDIR, /var/tmp, /usr/tmp or /tmp, the first one that the server can write. Where that directory is on another disk, the redaction checks it on its own, also where the disk of the state root cannot be read. Where the server cannot read the free space of that disk, it does not check the temporary files, and the log says so.

A request that waits more than 20 seconds for the writer answers 503 still-clearing. Then the server log says whether the redaction cleared or was refused.

The answer of a redaction means that the values are cleared from every row, and that the change is on the disk. The cells that it dropped and the pages that it freed are zeroed in the same commit. Every other write of the log zeroes the cell that it drops too, a row that the prune removes included.

Some bytes stay in the files after the answer:

  • the pages that earlier prunes freed
  • older copies of the changed pages, in the main file and in the write-ahead log, telemetry.sqlite-wal, until the log is cut

So after the answer, the server scrubs the file. It gives back every free page and cuts the write-ahead log, between the rows that it writes. Then no free page and no older copy in the log keeps what was cleared. The scrub does not reach the unused space inside pages that are still in use, as the list below says.

The scrub runs for up to 0.1 s of each pass of the writer, a pass every half second. In a measure it needed about 4 s of work at 256 MiB and about 76 s at 2 GiB. So it takes about 15 s and about 3 minutes at that pace. When the scrub ends, the log of the server says the query log gave back its free pages and cut its write-ahead log, and dns_querylog_scrub_pending goes from 1 to 0.

The server scrubs once at each start too, so a stop or a crash before the end is scrubbed at the next start. A query log in memory can turn off while its scrub runs. The scrub then waits for the next start too, and the gauge goes to 0 at once. A scrub at a start also gives back the free pages that the prune left for new rows. So the file shrinks at a start and grows again with the rows.

A read that holds the write-ahead log delays the scrub until it ends, and the log says so once. A read of the API ends in a moment. A long read is a backup or the measure of the lists of a large log. It can also be a sqlite3 shell that you left open on the file.

A redaction cannot reach these:

  • a backup archive, or any copy of the file, made before it
  • the blocks of the disk itself: a file that was cut or deleted, a snapshot of the file system, the way an SSD moves its blocks, and swap
  • the temporary files that SQLite writes while it works
  • the unused space inside pages that are still in use. SQLite can leave copies of old rows there, in this release too. It does so when it rebuilds a page, or reuses a free page and does not fill it. A release before this one left more there: rows that it pruned, columns that it cleared, and the old spelling of names that the upgrade to lower case rewrote. A prune after the scrub can free such a page with its copies in it, and no new scrub follows. Only a rewrite of the whole file clears that space. tadoru rewrite does it with --only telemetry, with the server stopped.

A log made by hand without auto-vacuum cannot give its free pages back. Its scrub ends with the query log was made without auto-vacuum instead, and its free pages keep what earlier deletions left. tadoru rewrite --only telemetry clears them, and gives the file auto-vacuum.

Only an operator or an administrator clears a column.

keep_one_row_in in server.toml keeps one question in N as a row of the log. It is 1 by default, which keeps every question, and it takes 1 to 1000. The other questions are not written as rows. The writer counts them in memory and adds the counts to the statistics. So a busy server writes fewer rows, and the log keeps up with more queries.

The server keeps one question of each N that it answers, by one counter that every listener shares. Updates and zone transfers are always rows, and they do not move the counter. A change of the setting applies to the next question, with no restart, and does not start the count again.

Some figures stay exact for every question. These are the questions of an hour, and the blocked, cached and failed ones. So are how they were answered, the transports, the record types, the response codes and the bands of time. So GET /api/stats/hourly and GET /api/stats/latency count every question.

These come from the kept rows:

  • The busiest names, the busiest clients and the most blocked names. Each kept row stands for the N questions of its sample, and the list of an hour sums to its exact counts. The figure of each name is an estimate.
  • devices, which counts the devices of the kept rows alone, so it can be lower than the truth.
  • The 50th, 95th and 99th percentiles, which stay inside the right band of time: a question that no row holds counts at the mean time of the counted questions of its band.

An hour of more than 256 record types counts the rest in one row. So its 32 most frequent types can miss a type that came late in a flood. The list of the most blocked names of a sampled hour is never exact. An hour that holds counts and no kept row has a list of other alone. So names_missing is true for it, as for an hour whose names a switch or a purge took.

GET /api/stats/top and GET /api/stats/top-blocked say how the rows of their range were kept, in kept, and each hour of GET /api/stats/hourly says it for its devices and its percentiles:

  • all: every question is a row, so nothing is estimated.
  • one_in: each row was kept as one question in N, and one_in gives N.
  • mixed: the rows were kept under more than one N, or beside questions skipped under an N that no row shows. A range whose rows were kept under more than one N reads mixed.
  • counts_alone: no row holds an N, so the questions are in other alone.

The counts of each hour (queries, blocked, the parts, the types and the codes) and GET /api/stats/latency carry no such mark, as they count every question. An hour counted before the upgrade to this version keeps no N. It reads all if the log kept every question of it, and mixed if it kept one question in N above 1 there, until a new row in that hour makes the server fold it again.

A change from one N above 1 to another does not start the count of the questions again. So at each such change, up to (old N - 1) + (new N - 1) questions can be counted in an hour whose rows show the other N, or in an hour of counts alone. The first hour reads one_in with the N of its rows. A range that holds the hour of counts alone and hours of the other N reads one_in with that N.

GET /api/queries and the log page show the kept rows: one question in N, and every update and transfer. A search by name or by client finds kept rows alone.

The counts wait in memory for 5 seconds at most, so a crash loses the counts of those seconds. A clean stop writes them. Where a write of the counts fails, or a log in memory has no room for it, the counts wait for the next write. Counts that still wait at the stop count as dropped.

retention_days is 30 by default, and it takes 1 to 3650. Pruning has a size bound as well. It is retention_mib, 512 MiB by default. So a busy server does not fill a disk before the days run out. The bound covers the hourly counts and their lists too. The counts are kept for stats_retention_days, five years by default. server.toml: how this server resolves has the settings.

A row of an answer that came from upstream carries its path, so it is larger than the others. On a server that forwards or walks most of its queries, the size bound can end the log before retention_days does.

The size bound counts the data of the log: its pages in use. For a log on the disk, the write-ahead log beside the file (telemetry.sqlite-wal) does not count. For a log in memory it counts, because it takes the room of the mount, and the prune waits while a read holds it.

A read of the console or of the API holds that log while it reads. A checkpoint cannot cut the write-ahead log then, so every write makes it grow until the read ends. No row is removed for it, because a delete makes a held log larger, not smaller. The server’s own reads end, so the log comes back to its size soon after.

A program of your own can hold a read open on the file, such as a sqlite3 shell with an open transaction. Then the log grows for as long as that program stays, with no bound. The log says this once, with the size, when it grows past the larger of two sizes:

  • an eighth of retention_mib
  • the room that a fold can hold: a sixteenth of retention_mib, 16 MiB at least

The line is another connection holds the query log's write-ahead log, so its space stays until it lets go. The log says it again each time the size doubles. It says nothing while a fold of the server, or its measure of the lists, holds the log. Close that program to give the space back.

could not fold the query log's write-ahead log into its file, so its space stays means that the checkpoint failed instead, for example on a full disk. A change from one cause to the other gives a new line. When the log is back under that size, the line the query log's write-ahead log is back to a size that needs no warning says so. The metric dns_querylog_wal_bytes gives the size of the log at each prune.

The writer of the log prunes between its batches of rows. It spends about 100 ms at a time on the prune, and takes the rows that wait before it goes on. One delete removes 1000 rows at most. Where old rows are left past retention_days, the next prune follows at once.

A log over its size by its data is the exception. Once a prune ends over the size, the next one removes at least what came in since, even past the 100 ms. So the data does not keep growing past its size. On a disk that deletes slower than queries come, rows can then drop as queue_full.

On the disk, the prune by size waits while a fold of the hourly counts reads. It waits where the data is over its size by no more than the margin of a fold: a sixteenth of retention_mib, and 16 MiB at least. Each delete of the prune grows the write-ahead log that the fold holds. Without the wait, the fold stopped at its allowance and the hourly counts fell behind.

The wait ends when the fold has read to its end, stops or is cancelled. The next turn of the writer prunes, before the next fold starts. After the wait, the data comes back to where it was before it, a little at a time. Each pass then goes past its budget of 100 ms, but removes 20,000 rows at most.

On a disk that deletes slower than queries come, these turns hold the writer, and rows can drop as queue_full, as in the catch-up above. So the data falls by up to 20,000 rows a turn, less the rows that come in. It is back at its size within a few turns, also where queries come faster than the budget alone removes them.

Three things end the wait:

  • The fold reads to its end, stops or is cancelled.
  • The waits add up to 10 minutes, until the data is under its size again. So a chain of folds after a long backlog does not hold the size for longer.
  • The prune by age takes the data under its size.

Meanwhile the data can pass retention_mib by the margin, plus the rows of one turn of the writer. The write-ahead log can pass it by the allowance of the fold. Past the margin the prune does not wait. The log says the prune by size waits while a fold of the query log reads once at each such wait. A log in memory does not wait, because there the room comes first.

Nothing is pruned until the server has read its configuration, so a start never prunes to limits that you did not set. Where the counts and the lists of the hours take all the room and no row is left to remove, the log says once: the query log is over its size limit and has no row left to remove.

A measure of the writer on one test machine (16 cores, a network disk) gives these rates. The file was near the default retention_mib, and its hourly counts were behind. On the disk, rows waited 12 to 14 seconds in the queue, and the log dropped rows at 500 queries a second and above. The same file on a tmpfs kept every row up to 2,000 queries a second, and dropped some at 4,000.

The cause on the disk was the prune by size. One delete of 1000 old rows changed about 2,000 pages of the indexes by client and by time taken. Its commit waited about 0.6 seconds for the disk to flush them. In that build a turn of the writer wrote 256 rows at most, so the writer kept up with about 340 rows a second.

Two changes helped. On the disk, a turn now waits for up to 256 rows. It then also takes the rows that wait behind it, up to 2048 in one write. A log in memory still takes 256 rows a turn. A probe gives rough figures for this change. It ran on the same machine, at a load average of 8 to 12, while other builds ran beside it. The file was over its size. The log kept every row at 500 queries a second. At 1,000 a second it wrote about 690 a second, and dropped the rest.

The rows of this build hold each address as its bytes, and no index by client or by name. Those two indexes took each new row on a page of their own, and the prune took each old row off another. So they changed about as many pages as the rest of the file. Probes of the bench of the writer ran on the same machine, at a load average of 15 to 23. The file was over its size, and the names repeated as real names do. With both indexes, the log wrote 383 of 1,000 queries a second. Without them it kept every row, with a fold in the trial.

A full measure of this build ran on the same machine while no test ran beside it, at a load average of 0.3 to 3.2. The file was full: its size was set 4 MiB under its data, at 544 to 567 MiB, a little over the default retention_mib. So the prune by size ran from the start. Each trial ran for 390 seconds. The figures at 1,500, 1,750 and 12,000 queries a second held in 3 trials of 3, and the others are of one trial.

  • On the disk, the log kept every row and its hourly counts at 1,500 queries a second. At 1,750 a second it dropped about 7 percent of the rows. The build before kept every row only at 250 a second, and dropped some at 500.
  • On a tmpfs, the log kept every row at 12,000 queries a second. In one trial at 16,000 a second it dropped about 8 percent. But from 3,000 a second up, the fold of the hour stopped at the room of its write-ahead log, so the counts of that hour waited until the rate fell.

The tmpfs figures are of the file on a tmpfs, with the writer as on the disk. A log with telemetry_storage = "memory" takes 256 rows a turn and has a guard of memory, and it was not measured.

The target of the server is 100,000 cached queries a second. The query log keeps every row only far below that: up to about 1,500 queries a second on the disk of that machine, and about 12,000 on a tmpfs. On a busy server run it in memory with telemetry_storage = "memory", or keep one question in N as a row with keep_one_row_in.

You see the dropped rows in dns_querylog_dropped_total{reason="queue_full"}, and a read of a range says how many rows it dropped. If that counter grows on a busy server, run the log in memory with telemetry_storage = "memory", or raise keep_one_row_in. In the full measure above, the log on a tmpfs kept every row up to 12,000 queries a second.