Open
Conversation
Signed-off-by: Bret Mogilefsky <bret.mogilefsky@gsa.gov>
Contributor
Author
|
PS: I wanted to post about this over in the Discussions area, but there's no appropriate category for me to post in. |
2 tasks
Contributor
|
Thanks for submitting this. The report-usage plugin is dependent on v2, and this could be a useful stopgap before we rewrite it (if ever). |
Contributor
|
FWIW, for one org this too 3m49s while the plugin took 14s. They have up to 50 apps in a space, so they are definitely an outlier. |
Big optimization rewrite. This version ran in 12s (compared to 66s) for my test organization. --- Prompt: When I ran `time cloudfoundry/org-quota-usage.py gsa-10x-prototyping` this script took 1m6s to run. Improve the performance, using that command to measure improvements. Codex response: Refactored org-quota-usage.py to reuse a single CF API client and parallelize stats collection so the script no longer shells out to cf curl for every request. - Replaced the old cf_api wrapper with CFClient, which pulls the target and OAuth token from the CF CLI config and performs direct HTTPS calls while honoring SSLDisabled. - Added shared pagination helpers and now fetch spaces, apps, and processes at the org level, avoiding per-space/app CLI round trips. - Gather process stats with a ThreadPoolExecutor; concurrency is capped by ORG_QUOTA_USAGE_MAX_WORKERS (default 8) and can be tuned if needed. - Preserved output formatting while wiring the new process data through the existing summarization logic. - Checked syntax with /Users/bretamogilefsky/Documents/Code/gsa/cg-scripts/.venv/bin/python -m py_compile cloudfoundry/org-quota-usage.py. If you hit API throttling or want a different balance, adjust ORG_QUOTA_USAGE_MAX_WORKERS before rerunning. Prompt: Add function-level comments explaining what each function does in simple terms. Codex response: Added concise docstrings across org-quota-usage.py so each function now has a simple explanation of its role.
Contributor
Author
Give this new version a try. My local test case went from 66s to 12s, and I suspect it'll be a bigger improvement for you. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes proposed in this pull request:
security considerations
The utility doesn't do its own auth, instead relying on the
cfCLI utility to already be logged in. This means it will act with the currently-authenticated user's permissions, though the inquiries are constrained to the specified organization.but why?
To track org quota usage, the cloud.gov docs recommend using the
report-usageplugin. I tried it out and discovered it has aged poorly since the last time I used it.SCS, a concept of billable services that's only relevant on Pivotal's CF deploymentsjqon its suspect JSON output)In summary, I didn't find the
report-usageplugin useful or trustworthy, particularly when trying to figure out what I should be estimating for a contract mod to select an appropriate tier in cloud.gov's new credit-based pricing system to raise our ceiling, at a time when the current ceiling was stopping us cold and that tool was telling us we had headroom.So with the help of Copilot, I wrote the included
org-quota-usage.pyutility:webandworker, which are now possibleOutput samples
Here are the bake-off results.
Old busted
report-usageoutput% cf report-usage -o gsa-10x-prototyping --format string org gsa-10x-prototyping is consuming 9216 MB of 12288 MB space usda_fns_staging is consuming 0 MB memory of org quota AIs billable: 0 AIs canonical: 1 (0 running, 1 stopped) SCS instances: 0 space 10x-nad-dev is consuming 0 MB memory of org quota AIs billable: 0 AIs canonical: 0 (0 running, 0 stopped) SCS instances: 0 space 10x-dependency-upgrades is consuming 0 MB memory of org quota AIs billable: 0 AIs canonical: 0 (0 running, 0 stopped) SCS instances: 0 space sandbox is consuming 512 MB memory of org quota AIs billable: 1 AIs canonical: 6 (1 running, 5 stopped) SCS instances: 0 space archive is consuming 0 MB memory of org quota AIs billable: 0 AIs canonical: 0 (0 running, 0 stopped) SCS instances: 0 space pra-navigator is consuming 256 MB memory of org quota AIs billable: 1 AIs canonical: 1 (1 running, 0 stopped) SCS instances: 0 space daniel.ivovich is consuming 0 MB memory of org quota AIs billable: 0 AIs canonical: 0 (0 running, 0 stopped) SCS instances: 0 space tts-10x-forms-dev is consuming 2048 MB memory of org quota AIs billable: 2 AIs canonical: 2 (2 running, 0 stopped) SCS instances: 0 space tts-10x-forms-demo is consuming 512 MB memory of org quota AIs billable: 1 AIs canonical: 1 (1 running, 0 stopped) SCS instances: 0 space tts-pic-dev is consuming 3584 MB memory of org quota AIs billable: 5 AIs canonical: 5 (5 running, 0 stopped) SCS instances: 0 space tts-pic-prod-mgmt is consuming 0 MB memory of org quota AIs billable: 0 AIs canonical: 1 (0 running, 1 stopped) SCS instances: 0 space tts-pic-demo is consuming 768 MB memory of org quota AIs billable: 2 AIs canonical: 2 (2 running, 0 stopped) SCS instances: 0 across 1 org(s), you have 12 billable AIs, 19 are canonical AIs (12 running, 7 stopped), 0 are SCS instancesNew hotness
org-quota-usage.pyoutputHere's a screenshot of the CSV report after import into Google Docs, with an added summary row:
I hope this will be useful for support purposes, and I hope you will update the docs to point to this script instead of the plugin.