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

build: ensure request hash is the same as build hash #1188

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

efahl
Copy link
Contributor

@efahl efahl commented Feb 3, 2025

When using 'packages_versions' the request hash that is calculated before request validation in 'api_v1_build_post' often differs from the one calculated in 'build'. This is due to 'validate_request' modifying the request's package lists.

We extract the request hash from the job, thus making them consistent again.

Copy link

codecov bot commented Feb 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.36%. Comparing base (5e65dec) to head (8a28caf).
Report is 207 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1188       +/-   ##
===========================================
+ Coverage   80.75%   91.36%   +10.61%     
===========================================
  Files          15       13        -2     
  Lines         977     1170      +193     
===========================================
+ Hits          789     1069      +280     
+ Misses        188      101       -87     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@aparcar
Copy link
Member

aparcar commented Feb 4, 2025

Thanks, good point. Isn't something like below the "better" solution?

diff --git a/asu/util.py b/asu/util.py
index 0bf1b87..8704b74 100644
--- a/asu/util.py
+++ b/asu/util.py
@@ -141,7 +141,12 @@ def get_request_hash(build_request: BuildRequest) -> str:
                 build_request.version_code,
                 build_request.target,
                 build_request.profile.replace(",", "_"),
-                get_packages_hash(build_request.packages),
+                get_packages_hash(
+                    x.removeprefix("+")
+                    for x in (
+                        build_request.packages_versions.keys() or build_request.packages
+                    )
+                ),
                 get_manifest_hash(build_request.packages_versions),
                 str(build_request.diff_packages),
                 "",  # build_request.filesystem

@efahl
Copy link
Contributor Author

efahl commented Feb 4, 2025

Yeah, I like that (my first inclination was to do a least-intrusive patch).

What do you think about adding that to my current patch, rather than replacing it altogether? Then we get reproducible results, plus we save the time recomputing the hash...

@aparcar
Copy link
Member

aparcar commented Feb 4, 2025

How are the results more reproducible? I think the computation of the hash is negligible, I don't know what the "get current job" function does in the background.

@efahl
Copy link
Contributor Author

efahl commented Feb 4, 2025

Reproducible in the sense that you can call get_request_hash before or after the validation step and you get the same result.

Looks like get_current_job is how we get job in the build function. The job parameter is completely ignored, never used by rq at all so we can get rid of it altogether.

I see no way of passing the actual job into build, since it's created after the call to enqueue and not included in the call (just the *args and **kwds are passed to the queued function, meaning we could actually pass the request hash in as an argument; I'll mangle this PR and you can take a look at it).

https://github.com/rq/rq/blob/master/rq/queue.py#L965
https://python-rq.org/docs/jobs/#job-creation

@efahl efahl force-pushed the consistent-hashes branch 2 times, most recently from 23bb9e0 to 45a762e Compare February 4, 2025 22:03
When using 'packages_versions' the request hash that is calculated
before request validation in 'api_v1_build_post' often differs from
the one calculated in 'build'.  This is due to 'validate_request'
modifying the request's package lists.

We pass the same request hash used when creating the job, thus
making them consistent again.

Signed-off-by: Eric Fahlgren <[email protected]>
@efahl efahl force-pushed the consistent-hashes branch from 45a762e to 8a28caf Compare February 4, 2025 22:04
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