Skip to content

Rework accounting scripts - #288

Open
anish-mudaraddi wants to merge 10 commits into
masterfrom
wip-accounting
Open

Rework accounting scripts #288
anish-mudaraddi wants to merge 10 commits into
masterfrom
wip-accounting

Conversation

@anish-mudaraddi

@anish-mudaraddi anish-mudaraddi commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

make accounting scripts run as a docker container

requirements:

  1. the docker container must run continuously - to get accounting data every interval

  2. also, the container can be used to collect past accounting data by providing timestamps from the past.

  3. there should be good logs so it can run on kayobe and be debugged easily

  4. there should be a dry-run feature - so we can test improvements in the future without sending data anywhere

  5. there should be good testing and linting to keep up with our coding standards

  6. it should work on a supported python version and the dependencies should be up-to-date

Still TODO:

  • more testing on monitoring nodes
  • acceptance testing on dev
  • automated CI to run test
  • moving this out into https://github.com/stfc/cloud-image-builders
    so that we can auto-build and version the docker container
  • getting a playbook together in our kayobe config to install this alongside monitoring containers
  • setting up perms on dev db to allow these scripts to run on monitoring nodes

@gmatthews20 gmatthews20 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I haven't yet reviewed any of the tests. Will take a look once we're happy with the functionality

Comment thread OpenStack-accounting/thecount/__init__.py Outdated
Comment thread OpenStack-accounting/thecount/cli.py Outdated
Comment thread OpenStack-accounting/thecount/cli.py Outdated
Comment thread OpenStack-accounting/thecount/jobs.py Outdated
Comment thread OpenStack-accounting/thecount/jobs.py Outdated
Comment thread OpenStack-accounting/thecount/source.py Outdated
Comment thread OpenStack-accounting/Dockerfile
Comment thread OpenStack-accounting/Dockerfile Outdated
Comment thread OpenStack-accounting/pyproject.toml Outdated
Comment thread OpenStack-accounting/README.md
Comment thread OpenStack-accounting/thecount/cli.py Outdated
@anish-mudaraddi
anish-mudaraddi force-pushed the wip-accounting branch 2 times, most recently from 93a8215 to 817a236 Compare August 28, 2026 14:20
Comment thread OpenStack-accounting/tests/conftest.py
Comment thread OpenStack-accounting/tests/conftest.py
Comment thread OpenStack-accounting/thecount/__main__.py Outdated
Comment thread OpenStack-accounting/thecount/__main__.py Outdated
Comment thread OpenStack-accounting/thecount/cli.py Outdated
Comment thread OpenStack-accounting/thecount/sink.py Outdated
Comment thread OpenStack-accounting/thecount/sink.py Outdated
Comment thread OpenStack-accounting/thecount/source.py
Comment thread OpenStack-accounting/thecount.conf.example Outdated
Comment thread OpenStack-accounting/uv.lock
move jobs into subdirectory - parsers, rename to match

use python influxdb client library instead of requests
- required us to setup https connection for influxdb

remove --interval in favor of hardcoding - for simplicity

simplify parsing --start-time and --end-time to accept only yyyy-mm-dd not iso timestamps - and default to starting at midnight current day

update readme to match changes

ensure tests pass, and linting fixes
provides additional security and prevents passwords from accidentally
being leaked
@anish-mudaraddi

Copy link
Copy Markdown
Collaborator Author

Changes made since last review:

using influxdb client library for talking to influxdb

  • influxdb protocol is https - with self-signed certs - hence tls verify turned off

  • removed --interval option - hardcoded to 24hours

  • simplified --start-time and --end-time to just accept yyyy-mm-dd rather than full ISO timestamps - if omitted - start-time is hardcoded to be midnight of from the date it is run

  • using influxdb python client library for Sink instead of requests library

    • using HTTPS protocol by default, with verify-tls as false as we use self-signed certs currently
  • using env-vars for setting username, password, host for source and sink for added security - specify them in .env file

  • updated readme

  • fixed tests

  • a bunch of linting fixes

  • bumped the version to 1.1.0

  • tested and working on staging kayobe

so that logging works - doesn't seem to register the logger if not

@DavidFair DavidFair left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Partial re-review
Some minor bits just as I'm going through....

Comment thread OpenStack-accounting/thecount/cli.py Outdated
Comment thread OpenStack-accounting/thecount/run_jobs.py
@anish-mudaraddi
anish-mudaraddi marked this pull request as ready for review September 3, 2026 09:18
@anish-mudaraddi
anish-mudaraddi requested a review from a team as a code owner September 3, 2026 09:18

@DavidFair DavidFair left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Full review - some security bits to validate and tighten up

Some doc / usability improvements where I noticed the version is mismatched in the README already and would need updating every time someone bumped this

Comment thread OpenStack-accounting/thecount/source.py
Comment thread OpenStack-accounting/Dockerfile Outdated
Comment thread OpenStack-accounting/README.md
Comment thread OpenStack-accounting/README.md Outdated
set default --start-date as yesterday so that parsing is done
immediately so we don't have to wait 24hours before we find out
something's broken

modify the docker build script to do pip install as monitoring user
rather than root for added security

use verison.txt to set the version of docker container
@anish-mudaraddi

Copy link
Copy Markdown
Collaborator Author

changes since last review

  • default --start-time is yesterday - so the full query + parsing + upload is run immediately, then the script waits 24 hours to parse the next interval

  • pip install --no-cache-dir . is run as monitoring user and not root for added security in docker container

  • set a global variable for hardcoded interval

  • use version.txt to set the docker container version - I manually set the python package version in pyproject.toml - to fix in later PR - less so concerned with this as its intended to run inside the docker container and we're not shipping it as a standalone package

@DavidFair DavidFair changed the title WIP: rework accounting scripts Rework accounting scripts Sep 3, 2026
@DavidFair
DavidFair requested a review from a team September 3, 2026 14:18
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.

3 participants