diff --git a/Dockerfiles/alpine.Dockerfile b/Dockerfiles/alpine.Dockerfile index 0e633239..5a54e206 100644 --- a/Dockerfiles/alpine.Dockerfile +++ b/Dockerfiles/alpine.Dockerfile @@ -9,18 +9,17 @@ LABEL maintainer="team@gnes.ai" \ org.label-schema.build-date=$BUILD_DATE \ org.label-schema.name="GNES is Generic Nerual Elastic Search" -RUN apk add --no-cache \ - --virtual=.build-dependencies \ - build-base g++ gfortran file binutils zeromq-dev \ - musl-dev python3-dev py-pgen cython openblas-dev && \ - apk add --no-cache libstdc++ openblas libzmq - WORKDIR /gnes/ ADD setup.py MANIFEST.in requirements.txt README.md ./ ADD gnes ./gnes/ -RUN ln -s locale.h /usr/include/xlocale.h && \ +RUN apk add --no-cache \ + --virtual=.build-dependencies \ + build-base g++ gfortran file binutils zeromq-dev \ + musl-dev python3-dev py-pgen cython openblas-dev && \ + apk add --no-cache libstdc++ openblas libzmq && \ + ln -s locale.h /usr/include/xlocale.h && \ pip install . --no-cache-dir --compile && \ find /usr/lib/python3.7/ -name 'tests' -exec rm -r '{}' + && \ find /usr/lib/python3.7/site-packages/ -name '*.so' -print -exec sh -c 'file "{}" | grep -q "not stripped" && strip -s "{}"' \; && \ diff --git a/gnes/cli/parser.py b/gnes/cli/parser.py index 8979297b..ac3b858a 100644 --- a/gnes/cli/parser.py +++ b/gnes/cli/parser.py @@ -308,7 +308,8 @@ def set_frontend_parser(parser=None): read_only=True) parser.add_argument('--max_concurrency', type=int, default=10, help='maximum concurrent connections allowed') - + parser.add_argument('--dump_route', type=argparse.FileType('w', encoding='utf8'), + help='dumping route information to a file') return parser diff --git a/gnes/service/frontend.py b/gnes/service/frontend.py index ebe687c7..1f2dd2f6 100644 --- a/gnes/service/frontend.py +++ b/gnes/service/frontend.py @@ -18,6 +18,7 @@ from concurrent.futures import ThreadPoolExecutor import grpc +from google.protobuf.json_format import MessageToJson from .. import __version__, __proto_version__ from ..client.base import ZmqClient @@ -80,7 +81,8 @@ def remove_envelope(self, m: 'gnes_pb2.Message'): if self.args.route_table: self.logger.info('route: %s' % router2str(m)) self.logger.info('route table: \n%s' % make_route_table(m.envelope.routes, exclude_frontend=True)) - + if self.args.dump_route: + self.args.dump_route.write(MessageToJson(m.envelope, indent=0).replace('\n', '') + '\n') return resp def Call(self, request, context): @@ -115,7 +117,8 @@ def StreamCall(self, request_iterator, context): num_request -= 1 except TimeoutError: if num_request > max_outstanding: - self.logger.warning("the network traffic exceed max outstanding (%d > %d)" % (num_request, max_outstanding)) + self.logger.warning("the network traffic exceed max outstanding (%d > %d)" % ( + num_request, max_outstanding)) continue break zmq_client.send_message(self.add_envelope(request, zmq_client), -1) diff --git a/tests/test_dict_indexer.py b/tests/test_dict_indexer.py index c0f58905..ee158fe0 100644 --- a/tests/test_dict_indexer.py +++ b/tests/test_dict_indexer.py @@ -33,7 +33,9 @@ def setUp(self): def test_pymode(self): os.unsetenv('http_proxy') os.unsetenv('https_proxy') - args = set_frontend_parser().parse_args([]) + args = set_frontend_parser().parse_args([ + '--dump_route', 'test.json' + ]) p_args = set_preprocessor_parser().parse_args([ '--port_in', str(args.port_out),