Skip to content

Commit

Permalink
fix: properly load gateway arguments from YAML (#5664)
Browse files Browse the repository at this point in the history
  • Loading branch information
alaeddine-13 authored Feb 8, 2023
1 parent 96e990d commit 8117000
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
27 changes: 27 additions & 0 deletions jina/jaml/parsers/gateway/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,33 @@ def parse(
cls._init_from_yaml = True
# tmp_p = {kk: expand_env_var(vv) for kk, vv in data.get('with', {}).items()}

for key in {
'name',
'port',
'protocol',
'host',
'tracing',
'graph_description',
'graph_conditions',
'deployments_addresses',
'deployments_metadata',
'deployments_no_reduce',
'timeout_send',
'retries',
'compression',
'runtime_name',
'prefetch',
'meter',
'log_config',
}:
if runtime_args and not runtime_args.get(key) and data.get(key):
runtime_args[key] = data.get(key)
if runtime_args.get('default_port'):
yaml_port = data.get('port')
if isinstance(yaml_port, int):
yaml_port = [yaml_port]
runtime_args['port'] = yaml_port or runtime_args.get('port')

obj = cls(
**data.get('with', {}),
metas=data.get('metas', {}),
Expand Down
1 change: 1 addition & 0 deletions jina/serve/runtimes/gateway/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ async def async_setup(self):
'aio_tracing_client_interceptors': self.aio_tracing_client_interceptors(),
'tracing_client_interceptor': self.tracing_client_interceptor(),
'log_config': self.args.log_config,
'default_port': getattr(self.args, 'default_port', False),
},
py_modules=self.args.py_modules,
extra_search_paths=self.args.extra_search_paths,
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/test_yamlparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ def test_load_gateway_external_success(yaml_file, gateway_name):
assert gateway.arg1 == 'hello'
assert gateway.arg2 == 'world'
assert gateway.arg3 == 'default-arg3'
assert gateway.runtime_args.timeout_send == 10
assert gateway.runtime_args.retries == 10
assert gateway.runtime_args.compression == 'Deflate'
assert gateway.runtime_args.prefetch == 100


@pytest.mark.parametrize(
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/yaml/test-custom-gateway.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ py_modules: dummy_gateway.py
with:
arg1: hello
arg2: world
timeout_send: 10
retries: 10
compression: Deflate
prefetch: 100
4 changes: 4 additions & 0 deletions tests/unit/yaml/test-fastapi-gateway.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ py_modules: dummy_fastapi_gateway.py
with:
arg1: hello
arg2: world
timeout_send: 10
retries: 10
compression: Deflate
prefetch: 100

0 comments on commit 8117000

Please sign in to comment.