Skip to content

Fix paged fetch counting the first page twice - #26

Merged
rkosegi merged 1 commit into
dNationCloud:mainfrom
lgonczarik:fix/pagination-starts-at-page-1
Oct 15, 2026
Merged

rkosegi merged 1 commit into
dNationCloud:mainfrom
lgonczarik:fix/pagination-starts-at-page-1

Conversation

@lgonczarik

Copy link
Copy Markdown
Contributor

PagedResourceHelper.fetchItemsnow starts at page 1 instead of page 0. Multi-page results no longer contain the first page twice, sogetAllServersandgetAllPrimaryIps` return the correct count.

Hetzner Cloud API pages are 1-based, and the API serves page=0 as page 1.
Checked against the live API: GET /v1/servers?page=0&per_page=2 answers with meta.pagination.page: 1, next_page: 2 and the same servers as page=1.
The old loop therefore read page 1 twice before moving on, adding 25 duplicates once a result spans more than one page.

In the Jenkins hetzner-cloud plugin this makes a cloud with 26 servers count as 51, so it reports "Cloud capacity reached" with about half of the instance cap actually running.

The new test in BasicTest emulates the API's page=0 behaviour with a mock server and asserts that only pages 1..n are requested and that the result has no duplicates.
It fails on the old code (expected:<[1, 2]> but was:<[0, 1, 2]>) and passes with the fix.

PagedResourceHelper.fetchItems started at page 0, but Hetzner Cloud API
pages are 1-based and page=0 is served as page 1. Whenever a result
spans more than one page, the first page was returned twice, so
getAllServers and getAllPrimaryIps reported 25 extra items.

Verified against the live API: GET /v1/servers?page=0 returns
meta.pagination.page=1 and the same items as page=1.

In the Jenkins hetzner-cloud plugin this makes a cloud with 26 servers
count as 51, so it hits its instance cap with about half the agents
actually running.

Start the loop at page 1 and add a test that emulates the API's
page=0 behaviour and asserts pages 1..n are requested without
duplicates.
@sonarqubecloud

Copy link
Copy Markdown

@lgonczarik

Copy link
Copy Markdown
Contributor Author

@rkosegi could you take a look?
Once this is merged, a client release and a hetzner-cloud plugin bump would let users with more than 25 servers per cloud get correct counts.

@rkosegi
rkosegi merged commit 7316982 into dNationCloud:main Oct 15, 2026
2 of 3 checks passed
@rkosegi

rkosegi commented Oct 15, 2026

Copy link
Copy Markdown
Member

Hi @lgonczarik, thanks for contribution. Do you mind to also bump version in Jenkins plugin itself?

@lgonczarik
lgonczarik deleted the fix/pagination-starts-at-page-1 branch October 15, 2026 10:44
@lgonczarik

Copy link
Copy Markdown
Contributor Author

Hi @lgonczarik, thanks for contribution. Do you mind to also bump version in Jenkins plugin itself?

Sure, here it is:
jenkinsci/hetzner-cloud-plugin#121

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants