Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
refactor(cli): refactor parser for healthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
hanhxiao committed Sep 26, 2019
1 parent a3e22db commit aa0f994
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gnes/cli/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions gnes/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
4 changes: 2 additions & 2 deletions tests/test_healthcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit aa0f994

Please sign in to comment.