8000 feat: support offline executors by alaeddine-13 · Pull Request #2935 · jina-ai/serve · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: support offline executors #2935

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

Merged
merged 9 commits into from
Jul 14, 2021
Merged

feat: support offline executors #2935

merged 9 commits into from
Jul 14, 2021

Conversation

alaeddine-13
Copy link
Contributor
  • default to disk cache when fetching hubble executor meta information if there's no internet connection
  • skip pulling the docker image if there's no internet connection and the docker image was already pulled

@alaeddine-13 alaeddine-13 requested a review from a team as a code owner July 13, 2021 07:30
@github-actions
Copy link

This PR closes: #120

@jina-bot jina-bot added size/S area/core This issue/PR affects the core codebase labels Jul 13, 2021
@codecov
Copy link
codecov bot commented Jul 13, 2021

Codecov Report

Merging #2935 (11dc2f0) into master (e089375) will increase coverage by 0.13%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2935      +/-   ##
==========================================
+ Coverage   88.85%   88.99%   +0.13%     
==========================================
  Files         138      138              
  Lines        9578     9607      +29     
==========================================
+ Hits         8511     8550      +39     
+ Misses       1067     1057      -10     
Flag Coverage Δ
daemon 43.16% <37.50%> (-0.18%) ⬇️
jina 88.98% <100.00%> (+0.13%) ⬆️

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

Impacted Files Coverage Δ
jina/hubble/helper.py 85.81% <100.00%> (+2.07%) ⬆️
jina/hubble/hubio.py 87.95% <100.00%> (+4.62%) ⬆️
jina/peapods/runtimes/jinad/client.py 91.71% <0.00%> (+1.18%) ⬆️
jina/peapods/runtimes/jinad/__init__.py 97.05% <0.00%> (+1.47%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e089375...11dc2f0. Read the comment docs.

@alaeddine-13 alaeddine-13 force-pushed the feat-offline-executor-120 branch 2 times, most recently from a37a734 to d9cba05 Compare July 13, 2021 11:35
@jina-bot jina-bot added the area/testing This issue/PR affects testing label Jul 13, 2021
def test_disk_cache():
@disk_cache((Exception,))
def test_disk_cache(tmpdir):
global first_time
Copy link
Contributor

Choose a reason for hiding this comment

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

what is first_time needed? Isn't there a better way? globals are scary

Copy link
Contributor Author
@alaeddine-13 alaeddine-13 Jul 13, 2021

Choose a reason for hiding this comment

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

disk_cache works this way:

  • if exception is raised but no entry in cache => raise exception
  • if exception is raised but there's an entry in cache exists => use it
  • if no exception is raised, store the result in cache
    So I wanted to simulate all 3 cases, first by raising an exception when the cache is empty (first_time=False)
    then by having a successful call and storing result in cache (first_time=True) and finally raising an exception, but this time we find a result in a cache so we use it (first_time=True)
    I can't use it as a function parameter because it would change the cache key.
    Do you have another idea ?

Copy link
Contributor

Choose a reason for hiding this comment

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

but u do not need a global. U can have a local variable inside the test and manipulate it there

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can't access it : UnboundLocalError: local variable 'first_time' referenced before assignment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

never mind I know now why that shows up

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

def disk_cache(
exceptions: Iterable[Exception],
cache_file: str = 'disk_cache.db',
message: str = "Calling {func_name} failed, using cached results",
Copy link
Contributor

Choose a reason for hiding this comment

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

single quote

@@ -250,3 +251,40 @@ def upload_file(
response = getattr(requests, method)(url, data=data, headers=headers, stream=stream)

return response


def disk_cache(
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's do this one more explicit and do not let add Exceptions as one wants.

Handling exceptions as normal behavior is a little dangerous and while it makes sense for this case, I would prefer to discourage it and specialize better this decorator

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So this means hardcoding the exception right ?
Should I rename the decorator ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

def _myfunc() -> bool:
global first_time
if not first_time:
raise _Exception("Failing")
Copy link
Contributor

Choose a reason for hiding this comment

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

single quote

@alaeddine-13 alaeddine-13 force-pushed the feat-offline-executor-120 branch 2 times, most recently from ca35980 to 19dc7e9 Compare July 13, 2021 14:13
def test_disk_cache():
@disk_cache((Exception,))
def test_disk_cache(tmpdir):
global first_time
Copy link
Contributor

Choose a reason for hiding this comment

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

but u do not need a global. U can have a local variable inside the test and manipulate it there

self._client.images.get(executor.image_name)
except docker.errors.ImageNotFound:
img_not_found = True
if img_not_found:
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems weird, why not just raising and avoid this extra boolean?

Copy link
Contributor Author
@alaeddine-13 alaeddine-13 Jul 13, 2021

Choose a reason for hiding this comment

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

Actually I need to re-raise APIError.
Maybe I can create a helper function docker_image_exists(image_name) because the same logic is also used in other places (dockerize.py, container/__init__.py).
I'm worried about the usage of docker (if I'll put it in a helper function) since docker is not installed in all tags.
What do you think ?

Copy link
Contributor

Choose a reason for hiding this comment

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

anyway, u can do except APIError as apiex, and then raise apiex. And u would not need this variable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@alaeddine-13 alaeddine-13 force-pushed the feat-offline-executor-120 branch from 198d444 to 0ee09a5 Compare July 14, 2021 05:53
@jina-bot jina-bot added size/M and removed size/S labels Jul 14, 2021
self._client.images.get(executor.image_name)
except docker.errors.ImageNotFound:
img_not_found = True
if img_not_found:
Copy link
Contributor

Choose a reason for hiding this comment

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

anyway, u can do except APIError as apiex, and then raise apiex. And u would not need this variable

@alaeddine-13 alaeddine-13 force-pushed the feat-offline-executor-120 branch 2 times, most recently from 0b030dd to 2ec8fb9 Compare July 14, 2021 07:59
@alaeddine-13 alaeddine-13 force-pushed the feat-offline-executor-120 branch from 2ec8fb9 to 11dc2f0 Compare July 14, 2021 08:31
@JoanFM JoanFM merged commit 4e72338 into master Jul 14, 2021
@JoanFM JoanFM deleted the feat-offline-executor-120 branch July 14, 2021 09:02
@github-actions
Copy link

Thanks for your contribution ❤️
💔 Unfortunately, this PR has one ore more bad commit messages, it can not be merged. To fix this problem, please refer to:

Note, other CI tests will not start until the commit messages get fixed.

This message will be deleted automatically when the commit messages get fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core This issue/PR affects the core codebase area/testing This issue/PR affects testing size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0