Hi,
I manage to sort out the problem with response paging. It was stupid! I was using OpenStack-API-Version header as suggested by https://docs.openstack.org/api-ref/compute/#list-tenant-usage-statistics-for-all-tenants but running Ussuri, it seems that the microversion used by default is < 2.27 and it is necessary to use the "historical header" X-OpenStack-Nova-API-Version instead (as explained in the same page when microversion is < 2.27). My script is now perfectly working. A bit more explanation in the Nova API documentation on how to handle paging (I used the presence of "tenant-usages-links" in the response as an indication more data where available, not sure if it is the right indicator, getting the last seen instance ID for the last entry in the tenant-usages list).
BTW, as for me, I think "openstack use list" is buggy as doesn't return the proper number of entries when you have a number of instances involved in the period larger than max_limit. Paging seems to occur only once, I didn't look at the code to understand what happens (as the API itself is working fine and easy to use once the described problems have been sorted out).
Hope it helps others... Best regards,
Michel
Hi,
I made significant progresses! I identified the source of the problem and found a workaround. Still fighting to implement the proper solution.
The reason of my problem is response pagination as documented in Nova API documentation. I was able to identify this when I realized I could identify the requests done by the dashboard by looking at nova-api.log rather than digging into the code: I saw that the requests were including "marker=xxx" parameters and that the number of requests was proportional to the period length. For the time being, as a workaround, I was able to get the appropriate accounting data after setting Nova API max_limit=10000: I now have the same number of vCPUsxhours reported as the dashboard.
I tried to validate this with curl but so far I have not been able to get limit and marker parameters be taken into account, not clear why. Also I saw that the dashboard is not using limit parameter and I don't know how it decides another request is needed (may be just doing a new request until the last response returns nothing). One thing that could be better documented is that the limit applies to the number of instances processed, even if none are returned is you don't use detailed=1 (this is hidding the problem in fact, making more difficult to understand that there is a limit problem).
Cheers,
Michel
Le 29/11/2023 à 11:21, Michel Jouvin a écrit :
To add one more information. I just ran the script on the Horizon server, in the same Python environment where I run the dashboard and using the Nova admin or internal interface rather than the public one. It makes absolutely no difference... I'm really wondering what could be done differently by the dashboard...
Best regards,
Michel
Le 29/11/2023 à 09:56, Michel Jouvin a écrit :
Hi Michael,
Sure there is nothing secret or fancy in this script, I attach it! It is typically run with something like
python get_accounting_data.py --first-y 2022 --first-m 12 --last-m 11 --output openstack-accounting_data.csv [--debug]
Adding --debug produces a very verbose (so better redirected to a file) but allow to get the raw data received from the API for each request, before all the data manipulations with Pandas.
Not sure how you can assess if it works properly for you. Probably the easiest is to count the lines in the CSV file produced and compare with the lines returned by Overview menu in Dashboard admin section. In my case, I could easily identify some big projects present in the dashboard output and missing in the CSV file. After checking with --debug, I saw that these projects are present in the project list but have no entries in any month (where they are among our bigger consumers!).
I really have no clue what I'm doing wrong. The API has not so many parameters so it's pretty easy to use if you respect the date format. One obvious difference between my script/openstack client and the dashboard is the Python version. Dashboard is run under Python 3.6 where my interactive environment is Python 3.11. But I cannot imagine any real influence on the API responses because of this...
Thanks in advance for your help. Cheers,
Michel
Le 29/11/2023 à 00:23, Michael Knox a écrit :
Are you able to provide a code snippet? Might help, but also understand if you can not.
My team has dozens of python scripts for operational use, reporting etc, on a number of clouds. We haven't observed any limits. Our scripts are using the "admin-rc" so assuming the user account you run the script as is scoped, it shouldn't have any issues.
CheersMichael
On Tue, Nov 28, 2023 at 5:08 PM Michel Jouvin <michel.jouvin@ijclab.in2p3.fr> wrote:
Hi,
Thanks for the answer. But in fact I am using the /os-simple-tenant-usage API as an admin so I'd really expected it to list all projects/tenants like Horizon does... I'm surely missing something but not clear what...
Best regards,
MichelSent from my mobile
Le 28 novembre 2023 19:27:33 smooney@redhat.com a écrit :
so the openstack client is calling the nova simple tenant usage api
maps to
the openstack client does not have a --all-tenants flag or simplar to call
so the difference is the openstack client uses/os-simple-tenant-usage/{tenant_id} which is aviabel to anyone with the member or reader role in a given project
the all tenats version is /os-simple-tenant-usageand that endpoint is admin only.
osc has only ever support the tenant specific version so if you wantted to supprot the admin versionyou would need to modify osc to add a --all-tenant option to the cli.
horizon presumably support the multi tenant view as an admin usign the /os-simple-tenant-usage endpoint.
On Tue, 2023-11-28 at 18:47 +0100, Michel Jouvin wrote:Hi,
I've been struggling today to understand the problem. I wrote a (Python)script that uses directly the API instead of going through the"openstack usage list". I had some hope of something related to thelimit parameter but unfortunately it is not the case and the resultusing the API is the same as using the openstack client. Only horizonreturns all the information.
Does somebody has any clue about what is done differently by Horizoncompared to the openstack client (I assume it is using the API ratherthan the client)?
Any input would be very much appreciated as going month by month (weneed a month-level detail) through the dashboard is not very sustainableand potentially very error prone...
Best regards,
Michel
Le 27/11/2023 à 18:39, Michel Jouvin a écrit :Hi,
We are using "openstack usage list" to follow resource usage byprojects at our cloud. We recently discovered that ~1/3 of theresource consumed (mostly "big projects") are missing from theJSON/CSV produced where the Admin Overview menu in the Horizondashboard displays everything. Is there a trivial reason for this?
We tried both with a pretty old openstackclient (5.8) and the last oneafter applying the patch into fix the problem with date conversion. The result is the same.
Thank you in advance for any help. Cheers,
Michel