Skip to content

fix: Avoid paging in ListHypervisors#520

Closed
dsanader wants to merge 1 commit intoopenstack-exporter:mainfrom
dsanader:fix_hypervisors_list_paging
Closed

fix: Avoid paging in ListHypervisors#520
dsanader wants to merge 1 commit intoopenstack-exporter:mainfrom
dsanader:fix_hypervisors_list_paging

Conversation

@dsanader
Copy link
Copy Markdown

Proposal to fix #519

@Sharpz7
Copy link
Copy Markdown
Collaborator

Sharpz7 commented Dec 16, 2025

Hey @dsanader. I was wondering if you see this being dependent or independent of #505?

@dsanader
Copy link
Copy Markdown
Author

At first glance #505 includes the same fix. If #505 is merged, you should be able to safely drop this PR. I will build the #505 code just to check though and report back If I find anything wrong on my side.

@dsanader
Copy link
Copy Markdown
Author

dsanader commented Dec 17, 2025

Well, it happens to be more complicated than I thought. My initial "fix" was in fact ugly. It actually uses an exporter.ClientV2 where Microversion is unset, so the API answers a single page. It should be more explicit that we downgrade Microversion on purpose to fallback to single page mechanism (which has the advantage to work consistently accross versions, see below).

Regarding #505, it does indeed automatically sets the latest supported Microversion, but since hypervisors.ListOpts is missing, limit is not added to the query params. So the Nova API returns here the api.max_limit (default to 1000) objects, without including the link to the next page. If Microversion > 2.33, a default limit should be defined to trigger pagination, maybe like this:

@@ -167,8 +167,17 @@ func ListNovaAgentState(ctx context.Context, exporter *BaseOpenStackExporter, ch
 func ListHypervisors(ctx context.Context, exporter *BaseOpenStackExporter, ch chan<- prometheus.Metric) error {
        var allHypervisors []hypervisors.Hypervisor
        var allAggregates []aggregates.Aggregate
+       var listOpts hypervisors.ListOpts
 
-       allPagesHypervisors, err := hypervisors.List(exporter.ClientV2, nil).AllPages(ctx)
+       apiMv, _ := strconv.ParseFloat(exporter.ClientV2.Microversion, 64)
+       if apiMv >= 2.33 {
+               limit := 1000
+               listOpts = hypervisors.ListOpts{Limit: &limit}
+       } else {
+               listOpts = hypervisors.ListOpts{}
+       }
+
+       allPagesHypervisors, err := hypervisors.List(exporter.ClientV2, listOpts).AllPages(ctx)
        if err != nil {
                return err
        }

Lastly, on older versions of Nova, the hypervisors_links key containing the next page is not always included in the results, which makes pagination not that useful in that case. I haven't sorted that point yet: I don't know what fixed it and when.

The python SDK includes a fallback logic which covers that (see: https://opendev.org/openstack/openstacksdk/src/commit/fb794edea9c1d1e9e4da8397f0dc9adc73bd1de1/openstack/resource.py#L2213). So, that behavior can't be seen with the openstack CLI.

@dsanader dsanader force-pushed the fix_hypervisors_list_paging branch from bcb575d to c7efd41 Compare December 18, 2025 09:12
@dsanader dsanader changed the title fix: Use gophercloud v2 to enable paging in Hypervisors.List fix: Avoid paging in ListHypervisors Dec 18, 2025
@dsanader dsanader force-pushed the fix_hypervisors_list_paging branch from c7efd41 to e9c9fb6 Compare December 18, 2025 09:23
@dsanader
Copy link
Copy Markdown
Author

I've changed my code to explicitly set a microversion not supporting pagination for the hypervisors list call for the time being.

Since having >1000 compute nodes is not that common, I guess it can wait a more proper fix when the gophercloud v2 is merged.

@Sharpz7
Copy link
Copy Markdown
Collaborator

Sharpz7 commented Dec 27, 2025

Appreciate the detailed breakdown @dsanader . Thank you!

vooon added a commit to vooon/openstack-exporter that referenced this pull request Dec 29, 2025
Fix openstack-exporter#519 which is proposed in openstack-exporter#520

Co-authored-by: Dejan Sanader <dejan.sanader@ovhcloud.com>
Signed-off-by: Vladimir Ermakov <vooon341@gmail.com>
@vooon
Copy link
Copy Markdown
Contributor

vooon commented Dec 29, 2025

@dsanader i've added your fix to v2.

vooon added a commit to vooon/openstack-exporter that referenced this pull request Dec 29, 2025
Fix openstack-exporter#519 which is proposed in openstack-exporter#520

Co-authored-by: Dejan Sanader <dejan.sanader@ovhcloud.com>
Signed-off-by: Vladimir Ermakov <vooon341@gmail.com>
@Sharpz7 Sharpz7 mentioned this pull request Jan 3, 2026
@Sharpz7 Sharpz7 closed this Jan 10, 2026
vooon added a commit to vooon/openstack-exporter that referenced this pull request Feb 27, 2026
Fix openstack-exporter#519 which is proposed in openstack-exporter#520

Co-authored-by: Dejan Sanader <dejan.sanader@ovhcloud.com>
Signed-off-by: Vladimir Ermakov <vooon341@gmail.com>
vooon added a commit to vooon/openstack-exporter that referenced this pull request Feb 27, 2026
Fix openstack-exporter#519 which is proposed in openstack-exporter#520

Co-authored-by: Dejan Sanader <dejan.sanader@ovhcloud.com>
Signed-off-by: Vladimir Ermakov <vooon341@gmail.com>
vooon added a commit to vooon/openstack-exporter that referenced this pull request Feb 28, 2026
Fix openstack-exporter#519 which is proposed in openstack-exporter#520

Co-authored-by: Dejan Sanader <dejan.sanader@ovhcloud.com>
Signed-off-by: Vladimir Ermakov <vooon341@gmail.com>
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.

Hypervisors list paging is broken

3 participants