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

Log results of requests.utils.super_len() when DANDI_DEVEL_INSTRUMENT_REQUESTS_SUPERLEN is set #1267

Merged
merged 3 commits into from
Apr 5, 2023

Conversation

jwodder
Copy link
Member

@jwodder jwodder commented Apr 5, 2023

Part of #1257.

@jwodder jwodder added the patch Increment the patch version when merged label Apr 5, 2023
@codecov
Copy link

codecov bot commented Apr 5, 2023

Codecov Report

Patch coverage: 80.00% and project coverage change: +0.03 🎉

Comparison is base (394b190) 89.02% compared to head (2afb540) 89.06%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1267      +/-   ##
==========================================
+ Coverage   89.02%   89.06%   +0.03%     
==========================================
  Files          76       76              
  Lines        9753     9767      +14     
==========================================
+ Hits         8683     8699      +16     
+ Misses       1070     1068       -2     
Flag Coverage Δ
unittests 89.06% <80.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
dandi/upload.py 86.95% <80.00%> (-0.55%) ⬇️

... and 1 file with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

dandi/files/zarr.py Outdated Show resolved Hide resolved
json_resp=False,
retry_if=_retry_zarr_file,
headers={"Content-MD5": item.base64_digest},
)
Copy link
Member

Choose a reason for hiding this comment

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

nice design pattern on many aspects!

@asmacdo @candleindark - please review/take into your toolbelt on how to

  • add optional context managers to the piece of code without duplication
  • instrument/patch some functionality (outside or not) temporarily

@jwodder jwodder marked this pull request as draft April 5, 2023 14:45
@jwodder
Copy link
Member Author

jwodder commented Apr 5, 2023

@yarikoptic I just realized that this approach will be a disaster, as Zarr entries are uploaded in a thread pool run within another set of threads for parallel asset uploads, yet monkeypatching is process-wide; hence, the patches to super_len() will all interfere with each other, with the most likely outcome involving the wrong filepaths being logged for super_len() return values.

@yarikoptic
Copy link
Member

  • don't patch within that method but rather "process wide" at e.g. import of dandi.upload stage. No need even to unpatch
  • just log that o within super_len, no need for any exterior variables.

with this patch to requests

diff --git a/requests/utils.py b/requests/utils.py
index a367417f..dc4df067 100644
--- a/requests/utils.py
+++ b/requests/utils.py
@@ -131,6 +131,7 @@ def dict_to_sequence(d):
 
 
 def super_len(o):
+    print(f"super_len on str={o} repr={o!r}")
     total_length = None
     current_position = 0
 

I see

super_len on str=<_io.BufferedReader name='/home/yoh/.tmp/pytest-of-yoh/pytest-39/test_upload_zarr0/example.zarr/arr_0/0'> repr=<_io.BufferedReader name='/home/yoh/.tmp/pytest-of-yoh/pytest-39/test_upload_zarr0/example.zarr/arr_0/0'>

while running our tests -- so either of those (str or repr) would be good enough to identify the location.

this way patched function would need only the content which is given to it.

@jwodder jwodder marked this pull request as ready for review April 5, 2023 16:18
@yarikoptic
Copy link
Member

somehow the run in that instrumented nfs environment resulted in

_________________ test_dandi_file_zarr_with_excluded_dotfiles __________________
dandi/tests/test_files.py:309: in test_dandi_file_zarr_with_excluded_dotfiles
    zf = dandi_file(zarr_path)
dandi/files/__init__.py:195: in dandi_file
    return factory(filepath, path, dandiset_path)
dandi/files/_private.py:71: in __call__
    return self.CLASSES[DandiFileType.classify(filepath)](
dandi/files/_private.py:42: in classify
    raise UnknownAssetError("Empty directories cannot be Zarr assets")
E   dandi.exceptions.UnknownAssetError: Empty directories cannot be Zarr assets

I didn't check if that is a flaky or whatnot, just restarting for a good check on that

@yarikoptic
Copy link
Member

Ok, green now, let's proceed

@github-actions
Copy link

🚀 PR was released in 0.53.0 🚀

@jwodder jwodder added the HIFNI Zarr uploads failing with "A header you provided implies functionality that is not implemented" label May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
HIFNI Zarr uploads failing with "A header you provided implies functionality that is not implemented" patch Increment the patch version when merged released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants