AAP-54476 : library.collectors - move collectors to library#248
Merged
himdel merged 4 commits intoansible:develfrom Nov 7, 2025
Merged
AAP-54476 : library.collectors - move collectors to library#248himdel merged 4 commits intoansible:develfrom
himdel merged 4 commits intoansible:develfrom
Conversation
0ea9ad0 to
5d3bdbf
Compare
41cae5c to
9e56102
Compare
* make sure none of them read environment variables anymore * make sure there are no assumptions about files being present somewhere in the filesystem * db= is always a psycopg connection handle (v2 or v3) copy_table now supports output_dir or output_file, and optional params= for query params Issue: AAP-54476
use pytest.approx for float comparisons in tests
….collectors.others
|
MilanPospisil
pushed a commit
to MilanPospisil/metrics-utility
that referenced
this pull request
Jan 6, 2026
* library.collectors: move collectors to library * make sure none of them read environment variables anymore * make sure there are no assumptions about files being present somewhere in the filesystem * db= is always a psycopg connection handle (v2 or v3) copy_table now supports output_dir or output_file, and optional params= for query params Issue: AAP-54476 * move CsvFileSplitter, to stop sonarqube complaining about duplicate code * claude tests use pytest.approx for float comparisons in tests * Split library.collectors into library.collectors.controller & library.collectors.others
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.



Issue: AAP-54476
Move all collectors into
metrics_utility.library.collectors. (Technically, copy, removing the originals is a second PR.)A collector is a function decorated with
@collector, it either returns a dict, or a list of csv filenames (fromcopy_table),it always takes a
db=parameter if it's supposed to talk to a db, or credentials for other services,it never reads environment variables directly, always using params,
it takes
since=anduntil=timestamp-with-timezone params if the collector supports collecting within time contraints,sinceis included (>=),untilexcluded (<),it only takes args it uses, no extra
**kwargs.The
@collectordecorator wraps these into a class instance such thatcollector_fn(params).gather()actually calls the originalcollector_fnwithparams. This is to allow splitting collector config (which should happen outside of global tempdir handling) from actual gather (which should happen while holding a db lock).Notes:
output_dir=is needed for compatibility with the cli, but omitting it will work too (and create a new tempdir per collect)output_file=(unused but supported incopy_table) allows streaming the data without creating tempfiles - just writes to a filehandle objectController collectors (
metrics_utility.library.collectors.controller.*)config(db, billing_provider_params).gather() -> Dictexecution_environments(db, [output_dir]).gather() -> [filenames]job_host_summary(db, since, until, [output_dir]).gather() -> [filenames]job_host_summary_service(db, since, until, [output_dir]).gather() -> [filenames]main_host(db, [output_dir]).gather() -> [filenames]main_indirectmanagednodeaudit(db, since, until, [output_dir]).gather() -> [filenames]main_jobevent(db, since, until, [output_dir]).gather() -> [filenames]main_jobevent_service(db, since, until, [output_dir]).gather() -> [filenames]unified_jobs(db, since, until, [output_dir]).gather() -> [filenames]Other collectors (
metrics_utility.library.collectors.others.*)total_workers_vcpu(cluster_name, metering_enabled, prometheus_url, ca_cert_path, token) -> DictSeparate PR (#260):
The original collectors file retains all the collector functions, original decorators, any get_optional_collectors logic,
but otherwise the functions end up calling the library functions.
Later: