Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python: add AccountingFormatter class, SQLite utility file #520

Merged
merged 4 commits into from
Oct 30, 2024

Conversation

cmoussa1
Copy link
Member

@cmoussa1 cmoussa1 commented Oct 22, 2024

Problem

flux-accounting has lots of different tables that can be viewed with view-* and list-* commands, but each one has its own function that could probably be cleaned up with some common utility. Better yet, if the formatting options for all of these commands was centralized, it might make for easier changes in the future and/or customization of output by users.


This PR begins to centralize the formatting for flux-accounting by adding a new AccountingFormatter class to the Python bindings. The class takes a SQLite Cursor object that has the results of running a query on the flux-accounting database and offers two methods of formatting its data: data in an adjustable table or data in JSON format. Since this class just takes a Cursor object, this means it can support customization of what fields are formatted and returned (because the query itself can just be customized to not fetch every field).

I've also added a SQLite utility file to the Python bindings to also help centralize some of the basic SQL helpers I have throughout the bindings. I've started with just a simple validation function where, given a custom list of columns passed in, that list is then validated against what is actually defined in the flux-accounting database.

I've added some basic unit tests for the AccountingFormatter class and the utilization of the sql_util helper function.

@cmoussa1 cmoussa1 added the new feature new feature label Oct 22, 2024
@cmoussa1 cmoussa1 force-pushed the add.formatter.class branch 3 times, most recently from edd543b to d3b5538 Compare October 28, 2024 17:36
@cmoussa1 cmoussa1 changed the title [WIP] python: add AccountingFormatter class, restructure list-banks to use new class python: add AccountingFormatter class, SQLite utility file Oct 28, 2024
@cmoussa1 cmoussa1 force-pushed the add.formatter.class branch from d3b5538 to 7e44485 Compare October 28, 2024 18:31
@cmoussa1 cmoussa1 marked this pull request as ready for review October 28, 2024 18:39
Problem: flux-accounting has lots of different tables that can be viewed
with view-* and list-* commands, but each one has its own function that
could probably be cleaned up with some common utility.

Begin to clean up this code by creating a new AccountingFormatter class.
Take a SQLite Cursor object (the object responsible for executing a SQL
query) as part of initialization. Define some formatting methods for
this class, such as as_table and as_json(), which will take the Cursor
object and format its result in table format or JSON format,
respectively, as well as some basic metadata methods, like
get_column_names() or get_rows().
Problem: the flux-accounting Python bindings have lots of separate
(and probably duplicate) helper code for validating and interacting
with the SQLite database. It would be cleaner and easier to maintain if
it was centralized in one file that could be referenced throughout the
bindings.

Add a new SQL utility file to the Python bindings that will have helper
functions for interacting with the SQLite database. Add a function to
this file that will validate a custom list of table column names
against a valid list of table column names.
Problem: The default fields for the relevant tables in the
flux-accounting DB are defined manually throughout the bindings,
so it makes sense to define these globally in the accounting Python
fluxacct.accounting package.

Create a definition for the names of the columns in some of the tables
in __init__.py so that they can be referenced throughout the Python
bindings for flux-accounting.
Problem: flux-accounting does not have tests that use the common
formatter in the Python bindings.

Add some unit tests for construction of AccountingFormatter objects and
ensuring the correct amount of data is returned from executing a query.
Test that column names can be fetched from AccountingFormatter objects
and are consistent with the ones defined in the flux-accounting DB.
Test that the correct exceptions are raised when invalid column names
are passed through validation.
@cmoussa1 cmoussa1 force-pushed the add.formatter.class branch from 7e44485 to 1432f8e Compare October 29, 2024 15:31
@cmoussa1 cmoussa1 requested a review from wihobbs October 29, 2024 17:39
Copy link
Member

@wihobbs wihobbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometime down the road, I think it'd be good to have a flux-account(1) manual page. Maybe a good doc day activity :)

Overall, nicely done.

@cmoussa1
Copy link
Member Author

Great suggestion @wihobbs! I'll open an issue on getting a flux-account(1) man page written. Probably should do that sooner rather than later since flux-accounting is getting used more and more. Setting MWP here

@mergify mergify bot merged commit 9d71a04 into flux-framework:master Oct 30, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants