commands: add new clear-usage command to reset a bank's job usage#804
commands: add new clear-usage command to reset a bank's job usage#804mergify[bot] merged 6 commits intoflux-framework:masterfrom
clear-usage command to reset a bank's job usage#804Conversation
|
@ryanday36 if you want to take a high-level look at this and let me know if this looks like what you had in mind in #801, let me know! |
382e04d to
a1dabb2
Compare
16393c1 to
516746f
Compare
516746f to
0b04de9
Compare
Problem: There is a need for flux-accounting to be able to reset the usage for a given bank at any given time. To do this, the database needs to a) know which banks are being reset, and b) which jobs that exist in the "jobs" table to ignore. Add a new column to bank_table called "ignore_older_than", which will store a timestamp (in the format of seconds-since-epoch) that will signal to all scripts updating job usage and fair-share values to ignore jobs that have completed before this time. Update DB_SCHEMA_VERSION as a result of adding a new column to bank_table. Update tests that look at columns output by the view-bank and list-banks commands to account for the addition of the ignore_older_than column.
Problem: The flux-accounting database from before the addition of the new "ignore_older_than" column to the bank_table is not in the testsuite, but it should be a part of the update-db tests since the schema has changed. Add a flux-accounting DB with schema version 31 to the testsuite.
Problem: The add-bank and edit-bank commands don't accept an --ignore-older-than option to set and modify a timestamp for a bank to ignore jobs older than said timestamp. Add a new optional argument to the add-bank and edit-bank commands to do so.
Problem: If a bank has an ignore_older_than timestamp configured, then the query that fetches new jobs needs to account for the fact that jobs older than that timestamp need to be filtered out. Add a LEFT JOIN to the query that fetches new jobs to filter any jobs that should be ignored by a bank with an ignore_older_than timestamp configured.
0b04de9 to
14fc807
Compare
jameshcorbett
left a comment
There was a problem hiding this comment.
Looks great! Just a couple of small things
t/python/t1008_banks_output.py
Outdated
| """ | ||
| ) | ||
| test = b.list_banks(conn) | ||
| print(test) |
There was a problem hiding this comment.
Do you mean for this to remain in the PR?
There was a problem hiding this comment.
No I did not 🤦 thanks for catching this. Will remove
| ignore_older_than: The timestamp in which all older jobs will not be considered | ||
| towards job usage. | ||
| """ | ||
| if len(banks) > 0: |
| # one or more banks has been passed in to have their usage wiped | ||
| for bank in banks: | ||
| # first, get the current usage for this bank and reset it | ||
| cur.execute("SELECT job_usage FROM bank_table WHERE bank=?", (bank,)) |
There was a problem hiding this comment.
Where are the records returned by this SELECT call used?
There was a problem hiding this comment.
Ah, good catch! That query was left over by accident for some troubleshooting and I never removed it. I will remove this query
Problem: There is no way to clear and reset the usage for a given bank in bank_table. New grant cycles generally have a mix of new and returning / continuing projects. For returning / continuing projects, the same bank name tends to be kept while *also* zeroing out and resetting the usage for the bank at the start of the new grant. Add a new clear-usage command to the flux-accounting command suite. clear-usage takes one positional argument: a list of banks to have their usage reset. When a bank's usage is reset, their job_usage value is reset to 0. Any users under this bank will also have their job_usage value reset to 0. When the bank's usage is reset, the job usage for the rest of the hierarchy is updated to account for the change in overall usage. An option to then set ignore_older_than is also provided to set a new date for which flux-accounting will no longer consider jobs towards usage that are older than that date. If no date is provided, the bank's ignore_older_than attribute is automatically set to the time in which the clear-usage command is run.
Problem: There are no tests for the clear_usage() function and its helper functions. Add some tests.
14fc807 to
7525ede
Compare
|
Thanks for approving this @jameshcorbett! Going to set MWP here |
Merge Queue StatusRule:
This pull request spent 6 seconds in the queue, with no time running CI. Required conditions to merge
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #804 +/- ##
=======================================
Coverage 82.93% 82.93%
=======================================
Files 27 27
Lines 2479 2479
=======================================
Hits 2056 2056
Misses 423 423 🚀 New features to boost your workflow:
|
Problem
There is no way to clear and reset the usage for a given bank in
bank_tablewithout fully deleting the bank and re-adding it. New grant cycles generally have a mix of new and returning / continuing projects. For returning / continuing projects, the same bank name tends to be kept while also zeroing out and resetting the usage for the bank at the start of the new grant.This PR adds a new
clear-usagecommand to the flux-accounting command suite.clear-usagetakes one positional argument: a list of banks to have their usage reset. When a bank's usage is reset, theirjob_usagevalue is reset to 0. Any users under this bank will also have theirjob_usagevalue reset to 0.Example usage:
flux account clear-usage my_bankWhen the bank's usage is reset, the job usage for the rest of the hierarchy is updated to account for the change in overall usage.
Even though a bank's usage is reset to 0, the old jobs submitted under this bank are still kept in the
jobstable. These jobs are ignored in subsequent usage updates by filtering the table against anignore_older_thantimestamp, a new column added to thebank_tablewhich represents a timestamp for which all jobs that have completed before said timestamp are ignored:If the
clear-usagecommand is run without any additional arguments, theignore_older_thantimestamp is set to the time in which the command is run, i.e. that bank will begin to ignore any jobs older than whenclear-usagewas run. An optional--ignore-older-thanoptional argument has also been added toclear-usage(as well asadd-bankandview-bank) to allow further customization for banks in relation to which jobs are or are not ignored. The format can be any timestamp accepted by Flux'sparse_datetime()function.Some basic unit tests and sharness tests are added which test clearing usage for a bank and ensuring that all of its users' usage also gets cleared along with any and all parent banks.
Fixes #801