-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: make accessible shard and replica info at container rt (#3822)
- Loading branch information
Showing
16 changed files
with
238 additions
and
45 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import os | ||
|
||
import docker | ||
import pytest | ||
|
||
from jina import __default_host__ | ||
from daemon.clients import JinaDClient | ||
|
Empty file.
7 changes: 7 additions & 0 deletions
7
tests/integration/container_runtime_args/replica-exec/Dockerfile
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM jinaai/jina:test-pip | ||
|
||
# setup the workspace | ||
COPY . /workspace | ||
WORKDIR /workspace | ||
|
||
ENTRYPOINT ["jina", "executor", "--uses", "config.yml"] |
16 changes: 16 additions & 0 deletions
16
tests/integration/container_runtime_args/replica-exec/__init__.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from jina import Executor, requests | ||
|
||
|
||
class ReplicatedExec(Executor): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.replica_id = self.runtime_args.replica_id | ||
self.shard_id = self.runtime_args.shard_id | ||
self.shards = self.runtime_args.shards | ||
|
||
@requests | ||
def foo(self, docs, **kwargs): | ||
for doc in docs: | ||
doc.tags['replica_id'] = self.replica_id | ||
doc.tags['shard_id'] = self.shard_id | ||
doc.tags['shards'] = self.shards |
4 changes: 4 additions & 0 deletions
4
tests/integration/container_runtime_args/replica-exec/config.yml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
jtype: ReplicatedExec | ||
metas: | ||
py_modules: | ||
- __init__.py |
58 changes: 58 additions & 0 deletions
58
tests/integration/container_runtime_args/test_container_get_args.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import pytest | ||
import time | ||
import os | ||
|
||
from jina import Flow, Executor, Document, DocumentArray, requests | ||
|
||
cur_dir = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
img_name = 'jina/replica-exec' | ||
|
||
|
||
@pytest.fixture(scope='module') | ||
def docker_image_built(): | ||
import docker | ||
|
||
client = docker.from_env() | ||
client.images.build(path=os.path.join(cur_dir, 'replica-exec'), tag=img_name) | ||
client.close() | ||
yield | ||
time.sleep(2) | ||
client = docker.from_env() | ||
client.containers.prune() | ||
|
||
|
||
@pytest.mark.parametrize('shards', [1, 2]) | ||
@pytest.mark.parametrize('replicas', [1, 3, 4]) | ||
def test_containerruntime_args(docker_image_built, shards, replicas): | ||
f = Flow().add( | ||
name='executor', | ||
uses=f'docker://{img_name}', | ||
replicas=replicas, | ||
shards=shards, | ||
polling='ANY', | ||
) | ||
with f: | ||
ret1 = f.index( | ||
inputs=DocumentArray([Document() for _ in range(200)]), | ||
return_results=True, | ||
request_size=10, | ||
) | ||
|
||
assert len(ret1) == 20 | ||
replica_ids = set() | ||
shard_ids = set() | ||
for r in ret1: | ||
assert len(r.docs) == 10 | ||
for replica_id in r.docs.get_attributes('tags__replica_id'): | ||
replica_ids.add(replica_id) | ||
for shard_id in r.docs.get_attributes('tags__shard_id'): | ||
shard_ids.add(shard_id) | ||
for doc in r.docs: | ||
assert doc.tags['shards'] == shards | ||
|
||
if replicas > 1: | ||
assert replica_ids == set(range(replicas)) | ||
else: | ||
assert replica_ids == {-1.0} | ||
assert shard_ids == set(range(shards)) |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.