Skip to content
Permalink
Browse files

refactor(cli): refactor parser for healthcheck

  • Loading branch information...
hanxiao committed Sep 26, 2019
1 parent a3e22db commit aa0f994e7693d049480b5dc5a5e09fb0b5979cbe
Showing with 11 additions and 11 deletions.
  1. +1 −1 gnes/cli/api.py
  2. +8 −8 gnes/cli/parser.py
  3. +2 −2 tests/test_healthcheck.py
@@ -69,7 +69,7 @@ def healthcheck(args):
from ..service.base import send_ctrl_message
from ..proto import gnes_pb2, add_version
import time
ctrl_addr = 'tcp://%s:%d' % (args.host_out, args.port_out)
ctrl_addr = 'tcp://%s:%d' % (args.host, args.port)
msg = gnes_pb2.Message()
add_version(msg.envelope)
msg.request.control.command = gnes_pb2.Request.ControlRequest.STATUS
@@ -244,17 +244,17 @@ def set_preprocessor_parser(parser=None):


def set_healthcheck_parser(parser=None):
import os
if not parser:
parser = set_base_parser()
set_service_parser(parser)

parser.add_argument('--host', type=str, default='127.0.0.1',
help='host address of the checked service')
parser.add_argument('--port', type=int, required=True,
help='control port of the checked service')
parser.add_argument('--timeout', type=int, default=1000,
help='timeout (ms) of one check, -1 for waiting forever')
parser.add_argument('--retries', type=int, default=3,
help='number of health checks retried before exit')
# we cant wait for health check signal forever, thus set to 5 seconds
parser.set_defaults(timeout=5)
ctrl_port = os.environ.get('GNES_CONTROL_PORT')
if ctrl_port:
parser.set_defaults(port_out=int(ctrl_port))
help='max number of tried health checks before exit 1')
return parser


@@ -17,8 +17,7 @@ def test_health_check(self):
])
a1 = copy.deepcopy(a)
b = set_healthcheck_parser().parse_args([
'--host_out', a.host_in,
'--port_out', str(a.port_ctrl)
'--port', str(a.port_ctrl)
])

# before - fail
@@ -54,6 +53,7 @@ def test_hc_os_env(self):
])
a1 = copy.deepcopy(a)
b = set_healthcheck_parser().parse_args([
'--port', os.environ.get('GNES_CONTROL_PORT')
])

# before - fail

0 comments on commit aa0f994

Please sign in to comment.
You can’t perform that action at this time.