Skip to content

Commit

Permalink
refactor: move port monitoring to pods parsing (#5100)
Browse files Browse the repository at this point in the history
* refactor: move port monitoring to pods parsing

* style: fix overload and cli autocomplete

Co-authored-by: Jina Dev Bot <dev-bot@jina.ai>
  • Loading branch information
samsja and jina-bot committed Aug 30, 2022
1 parent 6df36ce commit 90fa81f
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 33 deletions.
2 changes: 1 addition & 1 deletion docs/fundamentals/flow/executor-args.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
| `shards` | The number of shards in the deployment running at the same time. For more details check https://docs.jina.ai/fundamentals/flow/create-flow/#complex-flow-topologies | `number` | `1` |
| `replicas` | The number of replicas in the deployment | `number` | `1` |
| `monitoring` | If set, spawn an http server with a prometheus endpoint to expose metrics | `boolean` | `False` |
| `port_monitoring` | The port on which the prometheus server is exposed, default is a random port between [49152, 65535] | `number` | `random in [49152, 65535]` |
| `port_monitoring` | The port on which the prometheus server is exposed, default is a random port between [49152, 65535] | `string` | `random in [49152, 65535]` |
| `retries` | Number of retries per gRPC call. If <0 it defaults to max(3, num_replicas) | `number` | `-1` |
| `floating` | If set, the current Pod/Deployment can not be further chained, and the next `.add()` will chain after the last Pod/Deployment not this current one. | `boolean` | `False` |
| `install_requirements` | If set, install `requirements.txt` in the Hub Executor bundle to local | `boolean` | `False` |
Expand Down
2 changes: 1 addition & 1 deletion docs/fundamentals/flow/gateway-args.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@
| `shards` | The number of shards in the deployment running at the same time. For more details check https://docs.jina.ai/fundamentals/flow/create-flow/#complex-flow-topologies | `number` | `1` |
| `replicas` | The number of replicas in the deployment | `number` | `1` |
| `monitoring` | If set, spawn an http server with a prometheus endpoint to expose metrics | `boolean` | `False` |
| `port_monitoring` | The port on which the prometheus server is exposed, default is a random port between [49152, 65535] | `number` | `random in [49152, 65535]` |
| `port_monitoring` | The port on which the prometheus server is exposed, default is a random port between [49152, 65535] | `string` | `random in [49152, 65535]` |
| `retries` | Number of retries per gRPC call. If <0 it defaults to max(3, num_replicas) | `number` | `-1` |
| `floating` | If set, the current Pod/Deployment can not be further chained, and the next `.add()` will chain after the last Pod/Deployment not this current one. | `boolean` | `False` |
2 changes: 1 addition & 1 deletion jina/orchestrate/flow/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def __init__(
output_array_type: Optional[str] = None,
polling: Optional[str] = 'ANY',
port: Optional[int] = None,
port_monitoring: Optional[int] = None,
port_monitoring: Optional[str] = None,
prefetch: Optional[int] = 1000,
protocol: Optional[str] = 'GRPC',
proxy: Optional[bool] = False,
Expand Down
7 changes: 3 additions & 4 deletions jina/parsers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
from jina.parsers.orchestrate.runtimes.head import mixin_head_parser


def set_pod_parser(parser=None, port_monitoring=True):
def set_pod_parser(parser=None):
"""Set the parser for the Pod
:param parser: an optional existing parser to build upon
:param port_monitoring: if to include the port parsing
:return: the parser
"""
if not parser:
Expand All @@ -33,7 +32,7 @@ def set_pod_parser(parser=None, port_monitoring=True):
mixin_container_runtime_parser(parser)
mixin_remote_runtime_parser(parser)
mixin_distributed_feature_parser(parser)
mixin_pod_parser(parser, port_monitoring=port_monitoring)
mixin_pod_parser(parser)
mixin_hub_pull_options_parser(parser)
mixin_head_parser(parser)

Expand All @@ -51,7 +50,7 @@ def set_deployment_parser(parser=None):

parser = set_base_parser()

set_pod_parser(parser, port_monitoring=False)
set_pod_parser(parser)

from jina.parsers.orchestrate.deployment import mixin_base_deployment_parser

Expand Down
8 changes: 0 additions & 8 deletions jina/parsers/orchestrate/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,3 @@ def mixin_base_deployment_parser(parser):
default=False,
help='If set, connect to deployment using tls encryption',
)

gp.add_argument(
'--port-monitoring',
type=str,
default=str(helper.random_port()),
dest='port_monitoring',
help=f'The port on which the prometheus server is exposed, default is a random port between [49152, 65535]',
)
18 changes: 8 additions & 10 deletions jina/parsers/orchestrate/pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
from jina.parsers.helper import _SHOW_ALL_ARGS, KVAppendAction, add_arg_group


def mixin_pod_parser(parser, port_monitoring=True):
def mixin_pod_parser(parser):
"""Mixing in arguments required by :class:`Pod` into the given parser.
:param parser: the parser instance to which we add arguments
:param port_monitoring: if to include the port parsing
"""

gp = add_arg_group(parser, title='Pod')
Expand Down Expand Up @@ -97,14 +96,13 @@ def mixin_pod_parser(parser, port_monitoring=True):
help='If set, spawn an http server with a prometheus endpoint to expose metrics',
)

if port_monitoring:
gp.add_argument(
'--port-monitoring',
type=int,
default=helper.random_port(),
dest='port_monitoring',
help=f'The port on which the prometheus server is exposed, default is a random port between [49152, 65535]',
)
gp.add_argument(
'--port-monitoring',
type=str,
default=str(helper.random_port()),
dest='port_monitoring',
help=f'The port on which the prometheus server is exposed, default is a random port between [49152, 65535]',
)

gp.add_argument(
'--retries',
Expand Down
4 changes: 3 additions & 1 deletion jina/serve/runtimes/monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ def _setup_monitoring(self):

from prometheus_client import start_http_server

start_http_server(self.args.port_monitoring, registry=self.metrics_registry)
start_http_server(
int(self.args.port_monitoring), registry=self.metrics_registry
)
2 changes: 1 addition & 1 deletion jina_cli/autocomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@
'--replicas',
'--port',
'--monitoring',
'--port-monitoring',
'--retries',
'--floating',
'--install-requirements',
Expand All @@ -318,7 +319,6 @@
'--external',
'--deployment-role',
'--tls',
'--port-monitoring',
],
'client': [
'--help',
Expand Down
15 changes: 9 additions & 6 deletions tests/integration/monitoring/test_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,22 @@ def test_monitoring_head_few_port(port_generator, executor):
assert resp.status_code == 200


def test_monitoring_replicas_and_shards(port_generator, executor):
@pytest.mark.parametrize('protocol', ['websocket', 'grpc', 'http', None])
def test_monitoring_replicas_and_shards(port_generator, executor, protocol):
n_shards = 2
n_replicas = 3
port_shards_list = [port_generator() for _ in range(n_shards * n_replicas)]
port_head = port_generator()
port_monitoring = ','.join([str(port) for port in [port_head] + port_shards_list])
port1 = port_generator()

f = Flow(monitoring=True, port_monitoring=port1).add(
flow = (
Flow(protocol=protocol, monitoring=True, port_monitoring=port1)
if protocol
else Flow(monitoring=True, port_monitoring=port1)
)

f = flow.add(
uses=executor,
port_monitoring=port_monitoring,
shards=n_shards,
Expand Down Expand Up @@ -186,9 +193,6 @@ def test_monitoring_replicas_and_shards(port_generator, executor):
assert f'jina_sending_request_seconds' in str(resp.content)


# GOOD


def test_document_processed_total(port_generator, executor):
port0 = port_generator()
port1 = port_generator()
Expand Down Expand Up @@ -309,7 +313,6 @@ def _get_request_bytes_size():
assert measured_request_bytes_sum > measured_request_bytes_sum_init


# GOOD
def test_failed_successful_request_count(port_generator, failing_executor):
port0 = port_generator()
port1 = port_generator()
Expand Down

0 comments on commit 90fa81f

Please sign in to comment.