Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(daemon): add env to partial daemon (#3996)
* feat: add env to partial daemon and store * feat: add docstrings * feat: set envs in partial flow and peapod * feat(daemon): use dict as default env value * feat(daemon): add unit test for env setting * feat: add env setting test * feat(daemon): refine test structure * feat(daemon): adjust jina d test * feat(daemon): finish distributed testing * feat(daemon): fix test ip * feat(daemon): refine default host * test: refactor env var tests * ci: cleanup check for distributed * feat(daemon): fix partial client test * test: fix docs csv path Co-authored-by: Deepankar Mahapatro <deepankar.mahapatro@jina.ai>
- Loading branch information
1 parent
9db3de1
commit 2cd9f31
Showing
21 changed files
with
131 additions
and
24 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
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
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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: EnvExecutor | ||
metas: | ||
py_modules: | ||
- exec.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,12 @@ | ||
import os | ||
|
||
from jina import Executor, requests | ||
|
||
|
||
class EnvExecutor(Executor): | ||
@requests | ||
def set_env(self, docs, **kwargs): | ||
for doc in docs: | ||
doc.tags['key1'] = os.environ.get('context_var_1') | ||
doc.tags['key2'] = os.environ.get('context_var_2') | ||
doc.tags['replicas'] = os.environ.get('num_replicas') |
10 changes: 10 additions & 0 deletions
10
tests/distributed/test_env_vars/envvars_ws2/flow_with_env.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,10 @@ | ||
jtype: Flow | ||
with: | ||
port_expose: 12345 | ||
envs: | ||
key1: ${{ context_var_1 }} | ||
key2: ${{ context_var_2 }} | ||
executors: | ||
- name: env_executor | ||
uses: config.yml | ||
replicas: ${{ num_replicas }} |
50 changes: 50 additions & 0 deletions
50
tests/distributed/test_env_vars/test_remote_flow_executor.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,50 @@ | ||
import os | ||
from contextlib import contextmanager | ||
|
||
import pytest | ||
|
||
from daemon.clients import JinaDClient | ||
from jina import Document, Client | ||
|
||
NUM_DOCS = 10 | ||
|
||
cur_dir = os.path.dirname(os.path.abspath(__file__)) | ||
jinad_client = JinaDClient(host='localhost', port=8000) | ||
|
||
|
||
@contextmanager | ||
def RemoteFlow(filename, envs): | ||
flow_id = None | ||
try: | ||
workspace_id = jinad_client.workspaces.create( | ||
paths=[os.path.join(cur_dir, 'envvars_ws2')] | ||
) | ||
flow_id = jinad_client.flows.create( | ||
workspace_id=workspace_id, filename=filename, envs=envs | ||
) | ||
yield | ||
finally: | ||
if flow_id: | ||
assert jinad_client.flows.delete(flow_id), 'Flow termination failed' | ||
print(f'Remote Flow {flow_id} successfully terminated') | ||
|
||
|
||
@pytest.mark.parametrize('replicas', ['1', '2']) | ||
def test_remote_flow_local_executors(replicas): | ||
with RemoteFlow( | ||
filename='flow_with_env.yml', | ||
envs={ | ||
'context_var_1': 'val1', | ||
'context_var_2': 'val2', | ||
'num_replicas': replicas, | ||
}, | ||
): | ||
resp = Client(host='localhost', port=12345).post( | ||
on='/', | ||
inputs=[Document(id=idx) for idx in range(NUM_DOCS)], | ||
return_results=True, | ||
) | ||
for doc in resp[0].data.docs: | ||
assert doc.tags['key1'] == 'val1' | ||
assert doc.tags['key2'] == 'val2' | ||
assert doc.tags['replicas'] == replicas |
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