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

Implement cache in Znoyder #165

Merged
merged 9 commits into from
Jan 25, 2024
Merged

Implement cache in Znoyder #165

merged 9 commits into from
Jan 25, 2024

Conversation

sdatko
Copy link
Member

@sdatko sdatko commented Jan 24, 2024

It turned out that the upstream jobs specification does not change that often like we initially assumed. However, with passing time and project growing, we begin to be overwhelmed by number of calls to GitHub and OpenDev for fetching the Zuul sources. This pull request introduces cache mechanism that would allow us to rely on a single local file providing us all the information about upstream jobs. Such file can be generated/updated periodically. It will be added to repository with a separate pull request.

Example of generated cache:

---
discover_upstream_jobs('files-upstream/stable/2023.1/gnocchixyz/python-gnocchiclient'): []
discover_upstream_jobs('files-upstream/stable/2023.1/openstack-dev/hacking'): []
discover_upstream_jobs('files-upstream/stable/2023.1/openstack-infra/requestsexceptions'): []
discover_upstream_jobs('files-upstream/stable/2023.1/openstack-infra/shade'): []
discover_upstream_jobs('files-upstream/stable/2023.1/openstack-k8s-operators/edpm-image-builder'): []
discover_upstream_jobs('files-upstream/stable/2023.1/openstack-k8s-operators/tcib'): []
discover_upstream_jobs('files-upstream/stable/2023.1/openstack/ansible-role-atos-hsm'):
  - !ZuulJob
    name: openstack-tox-linters
    parameters: {}
    pipeline: check
  - !ZuulJob
    name: openstack-tox-linters
    parameters: {}
    pipeline: gate
...

List of changes:

– Move NestedDumper to dedicated submodule

There will be additional Dumper introduced later,
so lets keep them in the same place.

– Move utils to lib.utils submodule

There are two utils submodules right now,
so lets merge them together.

– Add persistent cache

This commit introduces additional class that implements
the persistent cache. It will be useful for reducing
the actual queries to GitHub and OpenDev, as it turned out
that there not many/often changes to list of upstream jobs.

– Make ZuulJob dumpable with PyYAML

It is all about inheriting from PyYAML base class
and setting custom tag name and declaring this object
as recognized by SafeLoader.

– Use cache in generator

Later we can preserve the generated cache
and stop querying GitHub hundreds of times.

– Make cache decorator callable in two ways

It is possible now to specify it both with
and without parentheses, e.g. @cache and @cache().
This opens a way to extend the functionality
further with additional options passed.

– Add selective cache option

This commit customizes the cache decorator so it is possible
to specify what parameters will be used as cache keys ~ i.e.
for function that we actually care about selected parameters that
makes the actual difference we can consider only specified ones
(by default all function parameters are considered).
Additionally it is possible to produce a human-readable string
instead of a calculated hash – this would make the generated
cache file browseable for us in case we need that...

– Make cache for generator predictable

This commit adds sorting of ZuulJobs entries so when cached
the produced output is always predictable and repeatable
across multiple calls to generator, no matter who, where
and when executes the code. This should allow us to include
small incremental changes in cache file when regenerating
the cache periodically for any upstream changes.

– Use relative paths in generator

The existing code relied on absolute paths to files,
which would result in generated cache to be specific
for a given environment where the Znoyder is called.
Using relative paths would make the calls universal
and properly cacheable.

There will be additional Dumper introduced later,
so lets keep them in the same place.
There are two utils submodules right now,
so lets merge them together.
This commit introduces additional class that implements
the persistent cache. It will be useful for reducing
the actual queries to GitHub and OpenDev, as it turned out
that there not many/often changes to list of upstream jobs.
It is all about inheriting from PyYAML base class
and setting custom tag name and declaring this object
as recognized by SafeLoader.
Later we can preserve the generated cache
and stop querying GitHub hundreds of times.
It is possible now to specify it both with
and without parentheses, e.g. @cache and @cache().
This opens a way to extend the functionality
further with additional options passed.
This commit customizes the cache decorator so it is possible
to specify what parameters will be used as cache keys ~ i.e.
for function that we actually care about selected parameters that
makes the actual difference we can consider only specified ones
(by default all function parameters are considered).

Additionally it is possible to produce a human-readable string
instead of a calculated hash – this would make the generated
cache file browsable for us in case we need that...
This commit adds sorting of ZuulJobs entries so when cached
the produced output is always predictable and repeatable
across multiple calls to generator, no matter who, where
and when executes the code. This should allow us to include
small incremental changes in cache file when regenerating
the cache periodically for any upstream changes.
The existing code relied on absolute paths to files,
which would result in generated cache to be specific
for a given environment where the Znoyder is called.
Using relative paths would make the calls universal
and properly cacheable.
Copy link
Member

@adrianfusco adrianfusco left a comment

Choose a reason for hiding this comment

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

I just can say this is wonderful +1

@sdatko sdatko merged commit 42883eb into RedHatCRE:main Jan 25, 2024
1 check passed
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.

2 participants