Skip to content

auth api: new endpoint to get the size of a zone#17568

Open
miodvallat wants to merge 2 commits into
PowerDNS:masterfrom
miodvallat:cantally
Open

auth api: new endpoint to get the size of a zone#17568
miodvallat wants to merge 2 commits into
PowerDNS:masterfrom
miodvallat:cantally

Conversation

@miodvallat

Copy link
Copy Markdown
Contributor

Short description

This PR introduces a /size endpoint for zones, which returns the number of records found in the zone (not counting the ENT).

Checklist

I have:

  • read the CONTRIBUTING.md document
  • read and accepted the Developer Certificate of Origin document, including the AI Policy, and added a "Signed-off-by" to my commits
  • compiled this code
  • tested this code
  • included documentation (including possible behaviour changes)
  • documented the code
  • added or modified regression test(s)
  • added or modified unit test(s)

Signed-off-by: Miod Vallat <miod.vallat@powerdns.com>
Signed-off-by: Miod Vallat <miod.vallat@powerdns.com>
@zeha

zeha commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

ISTM size and record count could be very different things. if the API returns the count of records, it should IMO also be called like that.

(F.e. size could also be count of rrsets, or count of characters of a BIND zone text representation, or ...)

@miodvallat

Copy link
Copy Markdown
Contributor Author

That name was intentional to force people to bikeshed which name would be more appropriate 😁 I'm waiting for people's ideas!

@zeha

zeha commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

That name was intentional to force people to bikeshed

:-D

It could just return all of these things in json fields!

@miodvallat

Copy link
Copy Markdown
Contributor Author

It could just return all of these things in json fields!

I considered that too, but I think the user asking for that feature would prefer something simple.

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 27420422207

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage increased (+11.4%) to 71.092%

Details

  • Coverage increased (+11.4%) from the base build.
  • Patch coverage: 2 uncovered changes across 1 file (18 of 20 lines covered, 90.0%).
  • 21604 coverage regressions across 290 files.

Uncovered Changes

File Changed Covered %
pdns/ws-auth.cc 20 18 90.0%

Coverage Regressions

21604 previously-covered lines in 290 files lost coverage.

Top 10 Files by Coverage Loss Lines Losing Coverage Coverage
pdns/lua-record.cc 809 0.17%
pdns/dnsdistdist/dnsdist-lua.cc 741 52.0%
pdns/recursordist/rec-main.cc 690 64.97%
modules/lmdbbackend/lmdbbackend.cc 573 71.91%
pdns/recursordist/syncres.cc 570 81.43%
pdns/recursordist/rec_channel_rec.cc 563 35.34%
pdns/dnsdistdist/dnsdist.cc 541 68.33%
pdns/auth-main.cc 520 50.03%
pdns/recursordist/ws-recursor.cc 502 22.03%
pdns/tcpiohandler.cc 472 60.03%

Coverage Stats

Coverage Status
Relevant Lines: 171260
Covered Lines: 133459
Line Coverage: 77.93%
Relevant Branches: 81882
Covered Branches: 46505
Branch Coverage: 56.8%
Branches in Coverage %: Yes
Coverage Strength: 5612428.94 hits per line

💛 - Coveralls

Comment thread pdns/ws-auth.cc
static void apiServerZoneRecordCount(HttpRequest* req, HttpResponse* resp)
{
ZoneData zoneData{req};
size_t recordCount{0};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should cache/store this value in the backend and update it whenever a record change is made to ensure we don't need to list huge zones every time. That would of course require users who directly edit things in the database to update this themselves as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would require a schema change to store that data in the domain table, and probably a lot of painful procedures in order to be sure to trust the data. While this would be much better, I am not ready to force a database schema change down the throat of our users yet.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That said, this could be added as a new, optional, backend entrypoint, so that e.g. sql backends could perform a better query to only get a count of records.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code still beats the previous practice, which is "list everything and let the client count"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants