From 08c41cf6fb822b1d98c0e0f4a35c9145d10b5a72 Mon Sep 17 00:00:00 2001 From: huawei Date: Sun, 31 May 2020 18:51:00 +0800 Subject: [PATCH 01/20] add requests plugin --- skywalking/plugins/sw_requests/__init__.py | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 skywalking/plugins/sw_requests/__init__.py diff --git a/skywalking/plugins/sw_requests/__init__.py b/skywalking/plugins/sw_requests/__init__.py new file mode 100644 index 00000000..393aa75e --- /dev/null +++ b/skywalking/plugins/sw_requests/__init__.py @@ -0,0 +1,77 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# -*- coding:utf-8 -*- +# author:huawei +import logging +import traceback + +from skywalking import Layer, Component +from skywalking.trace import tags +from skywalking.trace.carrier import Carrier +from skywalking.trace.context import get_context +from skywalking.trace.tags import Tag + +logger = logging.getLogger(__name__) + +def requests_install(): + # noinspection PyBroadException + try: + from requests import Session + + _request = Session.request + + def _sw_request(this: Session, method, url, + params=None, data=None, headers=None, cookies=None, files=None, + auth=None, timeout=None, allow_redirects=True, proxies=None, + hooks=None, stream=None, verify=None, cert=None, json=None): + + from urllib.parse import urlparse + url_param = urlparse(url) + + context = get_context() + carrier = Carrier() + with context.new_exit_span(op=url_param.path, peer=url_param.netloc, carrier=carrier) as span: + span.layer = Layer.Http + span.component = Component.General + + if headers is None: + headers = {} + for item in carrier: + headers[item.key] = item.val + else: + for item in carrier: + headers[item.key] = item.val + + try: + res = _request(this, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, + proxies, + hooks, stream, verify, cert, json) + + span.tag(Tag(key=tags.HttpMethod, val=method)) + span.tag(Tag(key=tags.HttpUrl, val=url)) + span.tag(Tag(key=tags.HttpStatus, val=res.status_code)) + if res.status_code >= 400: + span.error_occurred = True + except BaseException as e: + span.raised() + raise e + return res + + Session.request = _sw_request + except Exception: + logger.warning('failed to install plugin %s', __name__) + traceback.print_exc() From a09932a3106091c3f498c2b7fd25dbf2c5833d74 Mon Sep 17 00:00:00 2001 From: huawei Date: Sun, 31 May 2020 18:52:38 +0800 Subject: [PATCH 02/20] add requests plugin --- skywalking/plugins/sw_requests/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skywalking/plugins/sw_requests/__init__.py b/skywalking/plugins/sw_requests/__init__.py index 393aa75e..49b2ad19 100644 --- a/skywalking/plugins/sw_requests/__init__.py +++ b/skywalking/plugins/sw_requests/__init__.py @@ -27,7 +27,7 @@ logger = logging.getLogger(__name__) -def requests_install(): +def install(): # noinspection PyBroadException try: from requests import Session From e6df0cc4e7f5db13721d0b168a1d93efd0ee2cde Mon Sep 17 00:00:00 2001 From: huawei Date: Sun, 31 May 2020 19:03:36 +0800 Subject: [PATCH 03/20] update file license --- skywalking/plugins/sw_requests/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/skywalking/plugins/sw_requests/__init__.py b/skywalking/plugins/sw_requests/__init__.py index 49b2ad19..eb7bf8a7 100644 --- a/skywalking/plugins/sw_requests/__init__.py +++ b/skywalking/plugins/sw_requests/__init__.py @@ -14,8 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # -# -*- coding:utf-8 -*- -# author:huawei import logging import traceback @@ -27,6 +25,9 @@ logger = logging.getLogger(__name__) + +# -*- coding:utf-8 -*- +# author:huawei def install(): # noinspection PyBroadException try: @@ -57,7 +58,8 @@ def _sw_request(this: Session, method, url, headers[item.key] = item.val try: - res = _request(this, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, + res = _request(this, method, url, params, data, headers, cookies, files, auth, timeout, + allow_redirects, proxies, hooks, stream, verify, cert, json) From 1ad4e4fbcdfb78962063c823ca181fcdb11d376d Mon Sep 17 00:00:00 2001 From: huawei Date: Sun, 31 May 2020 19:06:43 +0800 Subject: [PATCH 04/20] update file license --- skywalking/plugins/sw_requests/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/skywalking/plugins/sw_requests/__init__.py b/skywalking/plugins/sw_requests/__init__.py index eb7bf8a7..fab46475 100644 --- a/skywalking/plugins/sw_requests/__init__.py +++ b/skywalking/plugins/sw_requests/__init__.py @@ -26,8 +26,6 @@ logger = logging.getLogger(__name__) -# -*- coding:utf-8 -*- -# author:huawei def install(): # noinspection PyBroadException try: From 7ce700120e32d5752698c590fb447c18faf397aa Mon Sep 17 00:00:00 2001 From: huawei Date: Mon, 8 Jun 2020 21:49:09 +0800 Subject: [PATCH 05/20] add testCase --- skywalking/plugins/sw_requests/__init__.py | 2 +- tests/plugin/requests/__init__.py | 17 +++++++ tests/plugin/requests/docker-compose.yml | 54 ++++++++++++++++++++++ tests/plugin/requests/expected.data.yml | 52 +++++++++++++++++++++ tests/plugin/requests/provider.py | 48 +++++++++++++++++++ tests/plugin/requests/test_request.py | 48 +++++++++++++++++++ 6 files changed, 220 insertions(+), 1 deletion(-) create mode 100644 tests/plugin/requests/__init__.py create mode 100644 tests/plugin/requests/docker-compose.yml create mode 100644 tests/plugin/requests/expected.data.yml create mode 100644 tests/plugin/requests/provider.py create mode 100644 tests/plugin/requests/test_request.py diff --git a/skywalking/plugins/sw_requests/__init__.py b/skywalking/plugins/sw_requests/__init__.py index fab46475..f24acef4 100644 --- a/skywalking/plugins/sw_requests/__init__.py +++ b/skywalking/plugins/sw_requests/__init__.py @@ -43,7 +43,7 @@ def _sw_request(this: Session, method, url, context = get_context() carrier = Carrier() - with context.new_exit_span(op=url_param.path, peer=url_param.netloc, carrier=carrier) as span: + with context.new_exit_span(op=url_param.path or "/", peer=url_param.netloc, carrier=carrier) as span: span.layer = Layer.Http span.component = Component.General diff --git a/tests/plugin/requests/__init__.py b/tests/plugin/requests/__init__.py new file mode 100644 index 00000000..62229721 --- /dev/null +++ b/tests/plugin/requests/__init__.py @@ -0,0 +1,17 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + diff --git a/tests/plugin/requests/docker-compose.yml b/tests/plugin/requests/docker-compose.yml new file mode 100644 index 00000000..c43fee3c --- /dev/null +++ b/tests/plugin/requests/docker-compose.yml @@ -0,0 +1,54 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +version: '2.1' + +services: + collector: + build: + context: ../docker + dockerfile: Dockerfile.tool + ports: + - 19876:19876 + - 12800:12800 + networks: + - beyond + healthcheck: + test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/12800"] + interval: 5s + timeout: 60s + retries: 120 + + provider: + build: + context: ../../../ + dockerfile: tests/plugin/docker/Dockerfile.agent + networks: + - beyond + ports: + - 9091:9091 + volumes: + - ./provider.py:/app/provider.py + environment: + SW_AGENT_COLLECTOR_BACKEND_SERVICES: collector:19876 + command: ['python3', '/app/provider.py'] + depends_on: + collector: + condition: service_healthy + +networks: + beyond: diff --git a/tests/plugin/requests/expected.data.yml b/tests/plugin/requests/expected.data.yml new file mode 100644 index 00000000..7c77c021 --- /dev/null +++ b/tests/plugin/requests/expected.data.yml @@ -0,0 +1,52 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +segmentItems: + - serviceName: provider + segmentSize: 1 + segments: + - segmentId: not null + spans: + - operationName: / + operationId: 0 + parentSpanId: -1 + spanId: 0 + spanLayer: Http + startTime: gt 0 + endTime: gt 0 + componentId: 7000 + isError: false + spanType: Entry + peer: not null + skipAnalysis: false + tags: + - {key: http.method, value: POST} + - operationName: /apache/skywalking + operationId: 0 + parentSpanId: 0 + spanId: 1 + spanLayer: Http + startTime: gt 0 + endTime: gt 0 + componentId: 7000 + isError: false + spanType: Exit + peer: not null + skipAnalysis: false + tags: + - {key: http.method, value: POST} + - {key: url, value: https://github.com/apache/skywalking} diff --git a/tests/plugin/requests/provider.py b/tests/plugin/requests/provider.py new file mode 100644 index 00000000..9d48006a --- /dev/null +++ b/tests/plugin/requests/provider.py @@ -0,0 +1,48 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import time + +import requests + +from skywalking import agent, config + +if __name__ == '__main__': + config.service_name = 'provider' + config.logging_level = 'DEBUG' + agent.start() + + import socketserver + from http.server import BaseHTTPRequestHandler + + class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): + + def do_POST(self): + time.sleep(0.5) + self.send_response(200) + self.send_header('Content-Type', 'application/json') + self.end_headers() + requests.post("https://github.com/apache/skywalking") + self.wfile.write('{"song": "Despacito", "artist": "Luis Fonsi"}'.encode('ascii')) + + + + PORT = 9091 + Handler = SimpleHTTPRequestHandler + + with socketserver.TCPServer(("", PORT), Handler) as httpd: + httpd.serve_forever() diff --git a/tests/plugin/requests/test_request.py b/tests/plugin/requests/test_request.py new file mode 100644 index 00000000..1619dd8b --- /dev/null +++ b/tests/plugin/requests/test_request.py @@ -0,0 +1,48 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import os +import time +import unittest +from os.path import abspath, dirname + +import requests +from testcontainers.compose import DockerCompose + +from tests.plugin import BasePluginTest + + +class TestRequestPlugin(BasePluginTest): + @classmethod + def setUpClass(cls): + docker_dir = dirname(dirname(abspath(__file__))) + + cls.compose = DockerCompose(filepath=os.path.join(docker_dir, 'http')) + cls.compose.start() + + cls.compose.wait_for(cls.url(cls.collector_address())) + + def test_request_plugin(self): + print('traffic: ', requests.post(url=self.url(('provider', '9091')))) + + time.sleep(3) + + self.validate(expected_file_name=os.path.join(dirname(abspath(__file__)), 'expected.data.yml')) + + +if __name__ == '__main__': + unittest.main() From 2cfc6bfece5301b2641653554d046dec483b9981 Mon Sep 17 00:00:00 2001 From: huawei Date: Mon, 8 Jun 2020 21:56:46 +0800 Subject: [PATCH 06/20] fix testCase package error --- tests/plugin/{requests => requests_scenario}/__init__.py | 0 tests/plugin/{requests => requests_scenario}/docker-compose.yml | 0 tests/plugin/{requests => requests_scenario}/expected.data.yml | 0 tests/plugin/{requests => requests_scenario}/provider.py | 0 tests/plugin/{requests => requests_scenario}/test_request.py | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename tests/plugin/{requests => requests_scenario}/__init__.py (100%) rename tests/plugin/{requests => requests_scenario}/docker-compose.yml (100%) rename tests/plugin/{requests => requests_scenario}/expected.data.yml (100%) rename tests/plugin/{requests => requests_scenario}/provider.py (100%) rename tests/plugin/{requests => requests_scenario}/test_request.py (100%) diff --git a/tests/plugin/requests/__init__.py b/tests/plugin/requests_scenario/__init__.py similarity index 100% rename from tests/plugin/requests/__init__.py rename to tests/plugin/requests_scenario/__init__.py diff --git a/tests/plugin/requests/docker-compose.yml b/tests/plugin/requests_scenario/docker-compose.yml similarity index 100% rename from tests/plugin/requests/docker-compose.yml rename to tests/plugin/requests_scenario/docker-compose.yml diff --git a/tests/plugin/requests/expected.data.yml b/tests/plugin/requests_scenario/expected.data.yml similarity index 100% rename from tests/plugin/requests/expected.data.yml rename to tests/plugin/requests_scenario/expected.data.yml diff --git a/tests/plugin/requests/provider.py b/tests/plugin/requests_scenario/provider.py similarity index 100% rename from tests/plugin/requests/provider.py rename to tests/plugin/requests_scenario/provider.py diff --git a/tests/plugin/requests/test_request.py b/tests/plugin/requests_scenario/test_request.py similarity index 100% rename from tests/plugin/requests/test_request.py rename to tests/plugin/requests_scenario/test_request.py From 3c07cbecefaa8ecbfccfd0d4c211ca5e2f0032ad Mon Sep 17 00:00:00 2001 From: huawei Date: Mon, 8 Jun 2020 22:38:56 +0800 Subject: [PATCH 07/20] update testcase expected.data.yml --- tests/plugin/requests_scenario/expected.data.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/plugin/requests_scenario/expected.data.yml b/tests/plugin/requests_scenario/expected.data.yml index 7c77c021..51069756 100644 --- a/tests/plugin/requests_scenario/expected.data.yml +++ b/tests/plugin/requests_scenario/expected.data.yml @@ -17,7 +17,7 @@ segmentItems: - serviceName: provider - segmentSize: 1 + segmentSize: 2 segments: - segmentId: not null spans: From 55ad3bbab90acf790040ec180208918d0b75261e Mon Sep 17 00:00:00 2001 From: huawei Date: Mon, 8 Jun 2020 22:51:58 +0800 Subject: [PATCH 08/20] update testcase provider.py --- tests/plugin/requests_scenario/provider.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/plugin/requests_scenario/provider.py b/tests/plugin/requests_scenario/provider.py index 9d48006a..d566a9bb 100644 --- a/tests/plugin/requests_scenario/provider.py +++ b/tests/plugin/requests_scenario/provider.py @@ -33,10 +33,10 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): def do_POST(self): time.sleep(0.5) + requests.post("https://github.com/apache/skywalking") self.send_response(200) self.send_header('Content-Type', 'application/json') self.end_headers() - requests.post("https://github.com/apache/skywalking") self.wfile.write('{"song": "Despacito", "artist": "Luis Fonsi"}'.encode('ascii')) From a3339583251b71bf8cf6f1ea7d46583b54ebcc24 Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Mon, 8 Jun 2020 23:37:24 +0800 Subject: [PATCH 09/20] Update test_request.py --- tests/plugin/requests_scenario/test_request.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/plugin/requests_scenario/test_request.py b/tests/plugin/requests_scenario/test_request.py index 1619dd8b..160879e1 100644 --- a/tests/plugin/requests_scenario/test_request.py +++ b/tests/plugin/requests_scenario/test_request.py @@ -29,9 +29,7 @@ class TestRequestPlugin(BasePluginTest): @classmethod def setUpClass(cls): - docker_dir = dirname(dirname(abspath(__file__))) - - cls.compose = DockerCompose(filepath=os.path.join(docker_dir, 'http')) + cls.compose = DockerCompose(filepath=dirname(abspath(__file__))) cls.compose.start() cls.compose.wait_for(cls.url(cls.collector_address())) From c31d0991426971eb8f04603eeb9560a25c006d06 Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Tue, 9 Jun 2020 10:44:12 +0800 Subject: [PATCH 10/20] Fix plugin test --- skywalking/plugins/sw_requests/__init__.py | 2 +- .../__init__.py | 0 .../docker-compose.yml | 0 .../expected.data.yml | 33 ++++++++++--------- .../provider.py | 2 +- .../test_request.py | 0 6 files changed, 19 insertions(+), 18 deletions(-) rename tests/plugin/{requests_scenario => sw_requests}/__init__.py (100%) rename tests/plugin/{requests_scenario => sw_requests}/docker-compose.yml (100%) rename tests/plugin/{requests_scenario => sw_requests}/expected.data.yml (72%) rename tests/plugin/{requests_scenario => sw_requests}/provider.py (95%) rename tests/plugin/{requests_scenario => sw_requests}/test_request.py (100%) diff --git a/skywalking/plugins/sw_requests/__init__.py b/skywalking/plugins/sw_requests/__init__.py index f24acef4..dc028fe2 100644 --- a/skywalking/plugins/sw_requests/__init__.py +++ b/skywalking/plugins/sw_requests/__init__.py @@ -61,7 +61,7 @@ def _sw_request(this: Session, method, url, proxies, hooks, stream, verify, cert, json) - span.tag(Tag(key=tags.HttpMethod, val=method)) + span.tag(Tag(key=tags.HttpMethod, val=method.upper())) span.tag(Tag(key=tags.HttpUrl, val=url)) span.tag(Tag(key=tags.HttpStatus, val=res.status_code)) if res.status_code >= 400: diff --git a/tests/plugin/requests_scenario/__init__.py b/tests/plugin/sw_requests/__init__.py similarity index 100% rename from tests/plugin/requests_scenario/__init__.py rename to tests/plugin/sw_requests/__init__.py diff --git a/tests/plugin/requests_scenario/docker-compose.yml b/tests/plugin/sw_requests/docker-compose.yml similarity index 100% rename from tests/plugin/requests_scenario/docker-compose.yml rename to tests/plugin/sw_requests/docker-compose.yml diff --git a/tests/plugin/requests_scenario/expected.data.yml b/tests/plugin/sw_requests/expected.data.yml similarity index 72% rename from tests/plugin/requests_scenario/expected.data.yml rename to tests/plugin/sw_requests/expected.data.yml index 51069756..4cfacd53 100644 --- a/tests/plugin/requests_scenario/expected.data.yml +++ b/tests/plugin/sw_requests/expected.data.yml @@ -17,10 +17,26 @@ segmentItems: - serviceName: provider - segmentSize: 2 + segmentSize: 1 segments: - segmentId: not null spans: + - operationName: /apache/skywalking + operationId: 0 + parentSpanId: 0 + spanId: 1 + spanLayer: Http + startTime: gt 0 + endTime: gt 0 + componentId: 7000 + isError: false + spanType: Exit + peer: not null + skipAnalysis: false + tags: + - {key: http.method, value: GET} + - {key: url, value: https://github.com/apache/skywalking} + - {key: status.code, value: '200'} - operationName: / operationId: 0 parentSpanId: -1 @@ -35,18 +51,3 @@ segmentItems: skipAnalysis: false tags: - {key: http.method, value: POST} - - operationName: /apache/skywalking - operationId: 0 - parentSpanId: 0 - spanId: 1 - spanLayer: Http - startTime: gt 0 - endTime: gt 0 - componentId: 7000 - isError: false - spanType: Exit - peer: not null - skipAnalysis: false - tags: - - {key: http.method, value: POST} - - {key: url, value: https://github.com/apache/skywalking} diff --git a/tests/plugin/requests_scenario/provider.py b/tests/plugin/sw_requests/provider.py similarity index 95% rename from tests/plugin/requests_scenario/provider.py rename to tests/plugin/sw_requests/provider.py index d566a9bb..36db31ca 100644 --- a/tests/plugin/requests_scenario/provider.py +++ b/tests/plugin/sw_requests/provider.py @@ -33,7 +33,7 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): def do_POST(self): time.sleep(0.5) - requests.post("https://github.com/apache/skywalking") + requests.get("https://github.com/apache/skywalking") self.send_response(200) self.send_header('Content-Type', 'application/json') self.end_headers() diff --git a/tests/plugin/requests_scenario/test_request.py b/tests/plugin/sw_requests/test_request.py similarity index 100% rename from tests/plugin/requests_scenario/test_request.py rename to tests/plugin/sw_requests/test_request.py From 7efd2bb80fc782f9ddf5c23f0246d9591249a051 Mon Sep 17 00:00:00 2001 From: huawei Date: Fri, 26 Jun 2020 11:14:53 +0800 Subject: [PATCH 11/20] fix sw_requests test conflict --- tests/plugin/sw_requests/docker-compose.yml | 2 +- tests/plugin/sw_requests/expected.data.yml | 52 +++++++++++++++---- tests/plugin/sw_requests/provider.py | 47 ----------------- tests/plugin/sw_requests/services/__init__.py | 2 +- tests/plugin/sw_requests/services/consumer.py | 2 +- tests/plugin/sw_requests/services/provider.py | 6 +-- 6 files changed, 45 insertions(+), 66 deletions(-) delete mode 100644 tests/plugin/sw_requests/provider.py diff --git a/tests/plugin/sw_requests/docker-compose.yml b/tests/plugin/sw_requests/docker-compose.yml index 3f0d3059..87dd49ee 100644 --- a/tests/plugin/sw_requests/docker-compose.yml +++ b/tests/plugin/sw_requests/docker-compose.yml @@ -75,4 +75,4 @@ services: condition: service_healthy networks: - beyond: + beyond: \ No newline at end of file diff --git a/tests/plugin/sw_requests/expected.data.yml b/tests/plugin/sw_requests/expected.data.yml index 4cfacd53..e85480f4 100644 --- a/tests/plugin/sw_requests/expected.data.yml +++ b/tests/plugin/sw_requests/expected.data.yml @@ -21,33 +21,63 @@ segmentItems: segments: - segmentId: not null spans: - - operationName: /apache/skywalking + - operationName: /users + operationId: 0 + parentSpanId: -1 + spanId: 0 + spanLayer: Http + tags: + - key: http.method + value: POST + refs: + - parentEndpoint: /users + networkAddress: provider:9091 + refType: CrossProcess + parentSpanId: 1 + parentTraceSegmentId: not null + parentServiceInstance: not null + parentService: consumer + traceId: not null + startTime: gt 0 + endTime: gt 0 + componentId: 7000 + spanType: Entry + peer: not null + skipAnalysis: false + - serviceName: consumer + segmentSize: 1 + segments: + - segmentId: not null + spans: + - operationName: /users operationId: 0 parentSpanId: 0 spanId: 1 spanLayer: Http + tags: + - key: http.method + value: POST + - key: url + value: http://provider:9091/users + - key: status.code + value: '200' startTime: gt 0 endTime: gt 0 componentId: 7000 - isError: false spanType: Exit - peer: not null + peer: provider:9091 skipAnalysis: false - tags: - - {key: http.method, value: GET} - - {key: url, value: https://github.com/apache/skywalking} - - {key: status.code, value: '200'} - operationName: / operationId: 0 parentSpanId: -1 spanId: 0 spanLayer: Http + tags: + - key: http.method + value: POST startTime: gt 0 endTime: gt 0 componentId: 7000 - isError: false spanType: Entry peer: not null - skipAnalysis: false - tags: - - {key: http.method, value: POST} + skipAnalysis: false \ No newline at end of file diff --git a/tests/plugin/sw_requests/provider.py b/tests/plugin/sw_requests/provider.py deleted file mode 100644 index 9311b7ce..00000000 --- a/tests/plugin/sw_requests/provider.py +++ /dev/null @@ -1,47 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -import time - -from skywalking import agent, config - -if __name__ == '__main__': - config.service_name = 'provider' - config.logging_level = 'DEBUG' - agent.start() - - import socketserver - from http.server import BaseHTTPRequestHandler - - class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): - - def do_POST(self): - time.sleep(0.5) -<<<<<<< HEAD:tests/plugin/sw_requests/services/provider.py -======= - requests.get("https://github.com/apache/skywalking") ->>>>>>> c31d0991426971eb8f04603eeb9560a25c006d06:tests/plugin/sw_requests/provider.py - self.send_response(200) - self.send_header('Content-Type', 'application/json') - self.end_headers() - self.wfile.write('{"song": "Despacito", "artist": "Luis Fonsi"}'.encode('ascii')) - - PORT = 9091 - Handler = SimpleHTTPRequestHandler - - with socketserver.TCPServer(("", PORT), Handler) as httpd: - httpd.serve_forever() diff --git a/tests/plugin/sw_requests/services/__init__.py b/tests/plugin/sw_requests/services/__init__.py index b1312a09..a9fd83fe 100644 --- a/tests/plugin/sw_requests/services/__init__.py +++ b/tests/plugin/sw_requests/services/__init__.py @@ -13,4 +13,4 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# +# \ No newline at end of file diff --git a/tests/plugin/sw_requests/services/consumer.py b/tests/plugin/sw_requests/services/consumer.py index 4328fc1d..75b1fecc 100644 --- a/tests/plugin/sw_requests/services/consumer.py +++ b/tests/plugin/sw_requests/services/consumer.py @@ -41,4 +41,4 @@ def do_POST(self): with socketserver.TCPServer(("", PORT), Handler) as httpd: print("serving at port", PORT) - httpd.serve_forever() + httpd.serve_forever() \ No newline at end of file diff --git a/tests/plugin/sw_requests/services/provider.py b/tests/plugin/sw_requests/services/provider.py index 9311b7ce..229601a5 100644 --- a/tests/plugin/sw_requests/services/provider.py +++ b/tests/plugin/sw_requests/services/provider.py @@ -31,10 +31,6 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): def do_POST(self): time.sleep(0.5) -<<<<<<< HEAD:tests/plugin/sw_requests/services/provider.py -======= - requests.get("https://github.com/apache/skywalking") ->>>>>>> c31d0991426971eb8f04603eeb9560a25c006d06:tests/plugin/sw_requests/provider.py self.send_response(200) self.send_header('Content-Type', 'application/json') self.end_headers() @@ -44,4 +40,4 @@ def do_POST(self): Handler = SimpleHTTPRequestHandler with socketserver.TCPServer(("", PORT), Handler) as httpd: - httpd.serve_forever() + httpd.serve_forever() \ No newline at end of file From 0562900c244f57ea93c2efb6cffca018364eff65 Mon Sep 17 00:00:00 2001 From: huawei Date: Fri, 26 Jun 2020 11:22:31 +0800 Subject: [PATCH 12/20] fix code style --- tests/plugin/sw_flask/services/provider.py | 2 +- tests/plugin/sw_requests/services/__init__.py | 2 +- tests/plugin/sw_requests/services/consumer.py | 2 +- tests/plugin/sw_requests/services/provider.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/plugin/sw_flask/services/provider.py b/tests/plugin/sw_flask/services/provider.py index e3213bb8..34fa1ff9 100644 --- a/tests/plugin/sw_flask/services/provider.py +++ b/tests/plugin/sw_flask/services/provider.py @@ -28,7 +28,7 @@ app = Flask(__name__) - @app.route("/users", methods=["POST","GET"]) + @app.route("/users", methods=["POST", "GET"]) def application(): time.sleep(0.5) return jsonify('{"song": "Despacito", "artist": "Luis Fonsi"}') diff --git a/tests/plugin/sw_requests/services/__init__.py b/tests/plugin/sw_requests/services/__init__.py index a9fd83fe..b1312a09 100644 --- a/tests/plugin/sw_requests/services/__init__.py +++ b/tests/plugin/sw_requests/services/__init__.py @@ -13,4 +13,4 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# \ No newline at end of file +# diff --git a/tests/plugin/sw_requests/services/consumer.py b/tests/plugin/sw_requests/services/consumer.py index 75b1fecc..4328fc1d 100644 --- a/tests/plugin/sw_requests/services/consumer.py +++ b/tests/plugin/sw_requests/services/consumer.py @@ -41,4 +41,4 @@ def do_POST(self): with socketserver.TCPServer(("", PORT), Handler) as httpd: print("serving at port", PORT) - httpd.serve_forever() \ No newline at end of file + httpd.serve_forever() diff --git a/tests/plugin/sw_requests/services/provider.py b/tests/plugin/sw_requests/services/provider.py index 229601a5..7af884ab 100644 --- a/tests/plugin/sw_requests/services/provider.py +++ b/tests/plugin/sw_requests/services/provider.py @@ -40,4 +40,4 @@ def do_POST(self): Handler = SimpleHTTPRequestHandler with socketserver.TCPServer(("", PORT), Handler) as httpd: - httpd.serve_forever() \ No newline at end of file + httpd.serve_forever() From dc46719bff13443f038cb8dcf1d62e23fcad77d4 Mon Sep 17 00:00:00 2001 From: huawei Date: Fri, 26 Jun 2020 11:23:56 +0800 Subject: [PATCH 13/20] fix code style --- skywalking/plugins/sw_requests/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skywalking/plugins/sw_requests/__init__.py b/skywalking/plugins/sw_requests/__init__.py index f6b90d2e..b1b6d029 100644 --- a/skywalking/plugins/sw_requests/__init__.py +++ b/skywalking/plugins/sw_requests/__init__.py @@ -82,4 +82,4 @@ def _sw_request(this: Session, method, url, Session.request = _sw_request except Exception: logger.warning('failed to install plugin %s', __name__) - traceback.print_exc() \ No newline at end of file + traceback.print_exc() From d03552079dbc217345a9aeac962391539a4b1dc0 Mon Sep 17 00:00:00 2001 From: huawei Date: Fri, 26 Jun 2020 11:39:49 +0800 Subject: [PATCH 14/20] update testCase --- tests/plugin/sw_flask/expected.data.yml | 3 +-- tests/plugin/sw_flask/services/consumer.py | 10 +++------- tests/plugin/sw_flask/services/provider.py | 2 +- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/tests/plugin/sw_flask/expected.data.yml b/tests/plugin/sw_flask/expected.data.yml index 509127e9..e85480f4 100644 --- a/tests/plugin/sw_flask/expected.data.yml +++ b/tests/plugin/sw_flask/expected.data.yml @@ -80,5 +80,4 @@ segmentItems: componentId: 7000 spanType: Entry peer: not null - skipAnalysis: false - + skipAnalysis: false \ No newline at end of file diff --git a/tests/plugin/sw_flask/services/consumer.py b/tests/plugin/sw_flask/services/consumer.py index 43f60bda..4328fc1d 100644 --- a/tests/plugin/sw_flask/services/consumer.py +++ b/tests/plugin/sw_flask/services/consumer.py @@ -15,7 +15,7 @@ # limitations under the License. # -from urllib import request +import requests from skywalking import agent, config @@ -33,12 +33,8 @@ def do_POST(self): self.send_header('Content-Type', 'application/json; charset=utf-8') self.end_headers() - data = '{"name": "whatever"}'.encode('utf8') - req = request.Request('http://provider:9091/users') - req.add_header('Content-Type', 'application/json; charset=utf-8') - req.add_header('Content-Length', str(len(data))) - with request.urlopen(req, data): - self.wfile.write(data) + res = requests.post("http://provider:9091/users") + self.wfile.write(str(res.json()).encode('utf8')) PORT = 9090 Handler = SimpleHTTPRequestHandler diff --git a/tests/plugin/sw_flask/services/provider.py b/tests/plugin/sw_flask/services/provider.py index 34fa1ff9..2507cea0 100644 --- a/tests/plugin/sw_flask/services/provider.py +++ b/tests/plugin/sw_flask/services/provider.py @@ -31,7 +31,7 @@ @app.route("/users", methods=["POST", "GET"]) def application(): time.sleep(0.5) - return jsonify('{"song": "Despacito", "artist": "Luis Fonsi"}') + return jsonify({"song": "Despacito", "artist": "Luis Fonsi"}) PORT = 9091 app.run(port=PORT) From a9f43ea62291247de9ecb6dcd72c033b2bf623b8 Mon Sep 17 00:00:00 2001 From: huawei Date: Fri, 26 Jun 2020 13:51:19 +0800 Subject: [PATCH 15/20] update testcase provider.py --- skywalking/plugins/sw_flask/__init__.py | 18 ++++++++++++++---- tests/plugin/sw_flask/expected.data.yml | 2 +- tests/plugin/sw_flask/services/consumer.py | 21 ++++++++------------- tests/plugin/sw_flask/test_flask.py | 2 +- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/skywalking/plugins/sw_flask/__init__.py b/skywalking/plugins/sw_flask/__init__.py index 74725016..ad937b0d 100644 --- a/skywalking/plugins/sw_flask/__init__.py +++ b/skywalking/plugins/sw_flask/__init__.py @@ -21,6 +21,7 @@ from skywalking.trace import tags from skywalking.trace.carrier import Carrier from skywalking.trace.context import get_context +from skywalking.trace.span import NoopSpan from skywalking.trace.tags import Tag logger = logging.getLogger(__name__) @@ -39,20 +40,30 @@ def _sw_full_dispatch_request(this: Flask): req = flask.request context = get_context() carrier = Carrier() + for item in carrier: - item.val = req.headers[item.key.capitalize()] + if item.key.capitalize() in req.headers: + item.val = req.headers[item.key.capitalize()] with context.new_entry_span(op=req.path, carrier=carrier) as span: span.layer = Layer.Http span.component = Component.Flask span.peer = '%s:%s' % (req.environ["REMOTE_ADDR"], req.environ["REMOTE_PORT"]) span.tag(Tag(key=tags.HttpMethod, val=req.method)) span.tag(Tag(key=tags.HttpUrl, val=req.url)) - return _full_dispatch_request(this) + resp = _full_dispatch_request(this) + + if resp.status_code >= 400: + span.error_occurred = True + + span.tag(Tag(key=tags.HttpStatus, val=resp.status_code)) + return resp def _sw_handle_user_exception(this: Flask, e): if e is not None: entry_span = get_context().active_span() - entry_span.log(e) + if entry_span is not None and type(entry_span) is not NoopSpan: + entry_span.raised() + return _handle_user_exception(this, e) Flask.full_dispatch_request = _sw_full_dispatch_request @@ -60,4 +71,3 @@ def _sw_handle_user_exception(this: Flask, e): except Exception: logger.warning('failed to install plugin %s', __name__) - traceback.print_exc() diff --git a/tests/plugin/sw_flask/expected.data.yml b/tests/plugin/sw_flask/expected.data.yml index e85480f4..1ed97c59 100644 --- a/tests/plugin/sw_flask/expected.data.yml +++ b/tests/plugin/sw_flask/expected.data.yml @@ -67,7 +67,7 @@ segmentItems: spanType: Exit peer: provider:9091 skipAnalysis: false - - operationName: / + - operationName: /users operationId: 0 parentSpanId: -1 spanId: 0 diff --git a/tests/plugin/sw_flask/services/consumer.py b/tests/plugin/sw_flask/services/consumer.py index 4328fc1d..373899ec 100644 --- a/tests/plugin/sw_flask/services/consumer.py +++ b/tests/plugin/sw_flask/services/consumer.py @@ -24,21 +24,16 @@ config.logging_level = 'DEBUG' agent.start() - import socketserver - from http.server import BaseHTTPRequestHandler + from flask import Flask, jsonify - class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): - def do_POST(self): - self.send_response(200) - self.send_header('Content-Type', 'application/json; charset=utf-8') - self.end_headers() + app = Flask(__name__) - res = requests.post("http://provider:9091/users") - self.wfile.write(str(res.json()).encode('utf8')) + @app.route("/users", methods=["POST", "GET"]) + def application(): + + res = requests.post("http://provider:9091/users") + return jsonify(res.json()) PORT = 9090 - Handler = SimpleHTTPRequestHandler + app.run(port=PORT) - with socketserver.TCPServer(("", PORT), Handler) as httpd: - print("serving at port", PORT) - httpd.serve_forever() diff --git a/tests/plugin/sw_flask/test_flask.py b/tests/plugin/sw_flask/test_flask.py index eacaa980..d61e9238 100644 --- a/tests/plugin/sw_flask/test_flask.py +++ b/tests/plugin/sw_flask/test_flask.py @@ -35,7 +35,7 @@ def setUpClass(cls): cls.compose.wait_for(cls.url(cls.collector_address())) def test_request_plugin(self): - print('traffic: ', requests.post(url=self.url(('consumer', '9090')))) + print('traffic: ', requests.post(url=self.url(('consumer', '9090'), "users"))) time.sleep(3) From 64f7face645fa16d7c903153a0bc979a14a55895 Mon Sep 17 00:00:00 2001 From: huawei Date: Fri, 26 Jun 2020 13:55:46 +0800 Subject: [PATCH 16/20] update code style --- skywalking/plugins/sw_flask/__init__.py | 1 - tests/plugin/sw_flask/services/consumer.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/skywalking/plugins/sw_flask/__init__.py b/skywalking/plugins/sw_flask/__init__.py index ad937b0d..b62ceb09 100644 --- a/skywalking/plugins/sw_flask/__init__.py +++ b/skywalking/plugins/sw_flask/__init__.py @@ -15,7 +15,6 @@ # limitations under the License. # import logging -import traceback from skywalking import Layer, Component from skywalking.trace import tags diff --git a/tests/plugin/sw_flask/services/consumer.py b/tests/plugin/sw_flask/services/consumer.py index 373899ec..e4b6cc14 100644 --- a/tests/plugin/sw_flask/services/consumer.py +++ b/tests/plugin/sw_flask/services/consumer.py @@ -36,4 +36,4 @@ def application(): PORT = 9090 app.run(port=PORT) - + \ No newline at end of file From 56611151f2606422db2d5487881d11af68ef5086 Mon Sep 17 00:00:00 2001 From: huawei Date: Fri, 26 Jun 2020 13:57:37 +0800 Subject: [PATCH 17/20] update code style --- tests/plugin/sw_flask/services/consumer.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/plugin/sw_flask/services/consumer.py b/tests/plugin/sw_flask/services/consumer.py index e4b6cc14..58f02a6c 100644 --- a/tests/plugin/sw_flask/services/consumer.py +++ b/tests/plugin/sw_flask/services/consumer.py @@ -36,4 +36,3 @@ def application(): PORT = 9090 app.run(port=PORT) - \ No newline at end of file From d4167fba2c857227f8b43712907c9ebcd224a6f7 Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Thu, 2 Jul 2020 15:04:39 +0800 Subject: [PATCH 18/20] Fix test --- tests/plugin/sw_flask/docker-compose.yml | 40 ++++++---------------- tests/plugin/sw_flask/expected.data.yml | 14 ++++++-- tests/plugin/sw_flask/services/consumer.py | 3 +- tests/plugin/sw_flask/services/provider.py | 2 +- tests/plugin/sw_flask/test_flask.py | 4 +-- 5 files changed, 25 insertions(+), 38 deletions(-) diff --git a/tests/plugin/sw_flask/docker-compose.yml b/tests/plugin/sw_flask/docker-compose.yml index 3f0d3059..d84ab67e 100644 --- a/tests/plugin/sw_flask/docker-compose.yml +++ b/tests/plugin/sw_flask/docker-compose.yml @@ -19,33 +19,19 @@ version: '2.1' services: collector: - build: - context: ../docker - dockerfile: Dockerfile.tool - ports: - - 19876:19876 - - 12800:12800 - networks: - - beyond - healthcheck: - test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/12800"] - interval: 5s - timeout: 60s - retries: 120 + extends: + service: collector + file: ../docker/docker-compose.base.yml provider: - build: - context: ../../../ - dockerfile: tests/plugin/docker/Dockerfile.agent - networks: - - beyond + extends: + service: provider + file: ../docker/docker-compose.base.yml ports: - 9091:9091 volumes: - ./services/provider.py:/app/provider.py - environment: - SW_AGENT_COLLECTOR_BACKEND_SERVICES: collector:19876 - command: ['python3', '/app/provider.py'] + command: ['bash', '-c', 'pip install flask && python3 /app/provider.py'] depends_on: collector: condition: service_healthy @@ -56,18 +42,14 @@ services: retries: 120 consumer: - build: - context: ../../../ - dockerfile: tests/plugin/docker/Dockerfile.agent - networks: - - beyond + extends: + service: consumer + file: ../docker/docker-compose.base.yml ports: - 9090:9090 volumes: - ./services/consumer.py:/app/consumer.py - environment: - SW_AGENT_COLLECTOR_BACKEND_SERVICES: collector:19876 - command: ['python3', '/app/consumer.py'] + command: ['bash', '-c', 'pip install flask && python3 /app/consumer.py'] depends_on: collector: condition: service_healthy diff --git a/tests/plugin/sw_flask/expected.data.yml b/tests/plugin/sw_flask/expected.data.yml index 1ed97c59..aa3d2dcb 100644 --- a/tests/plugin/sw_flask/expected.data.yml +++ b/tests/plugin/sw_flask/expected.data.yml @@ -29,6 +29,10 @@ segmentItems: tags: - key: http.method value: POST + - key: url + value: http://provider:9091/users + - key: status.code + value: '200' refs: - parentEndpoint: /users networkAddress: provider:9091 @@ -40,7 +44,7 @@ segmentItems: traceId: not null startTime: gt 0 endTime: gt 0 - componentId: 7000 + componentId: 7001 spanType: Entry peer: not null skipAnalysis: false @@ -74,10 +78,14 @@ segmentItems: spanLayer: Http tags: - key: http.method - value: POST + value: GET + - key: url + value: http://0.0.0.0:9090/users + - key: status.code + value: '200' startTime: gt 0 endTime: gt 0 - componentId: 7000 + componentId: 7001 spanType: Entry peer: not null skipAnalysis: false \ No newline at end of file diff --git a/tests/plugin/sw_flask/services/consumer.py b/tests/plugin/sw_flask/services/consumer.py index 58f02a6c..c942f91c 100644 --- a/tests/plugin/sw_flask/services/consumer.py +++ b/tests/plugin/sw_flask/services/consumer.py @@ -30,9 +30,8 @@ @app.route("/users", methods=["POST", "GET"]) def application(): - res = requests.post("http://provider:9091/users") return jsonify(res.json()) PORT = 9090 - app.run(port=PORT) + app.run(host='0.0.0.0', port=PORT, debug=True) diff --git a/tests/plugin/sw_flask/services/provider.py b/tests/plugin/sw_flask/services/provider.py index 2507cea0..11f2c0be 100644 --- a/tests/plugin/sw_flask/services/provider.py +++ b/tests/plugin/sw_flask/services/provider.py @@ -34,4 +34,4 @@ def application(): return jsonify({"song": "Despacito", "artist": "Luis Fonsi"}) PORT = 9091 - app.run(port=PORT) + app.run(host='0.0.0.0', port=PORT, debug=True) diff --git a/tests/plugin/sw_flask/test_flask.py b/tests/plugin/sw_flask/test_flask.py index d61e9238..21a191ac 100644 --- a/tests/plugin/sw_flask/test_flask.py +++ b/tests/plugin/sw_flask/test_flask.py @@ -32,11 +32,9 @@ def setUpClass(cls): cls.compose = DockerCompose(filepath=dirname(abspath(__file__))) cls.compose.start() - cls.compose.wait_for(cls.url(cls.collector_address())) + cls.compose.wait_for(cls.url(('consumer', '9090'), 'users')) def test_request_plugin(self): - print('traffic: ', requests.post(url=self.url(('consumer', '9090'), "users"))) - time.sleep(3) self.validate(expected_file_name=os.path.join(dirname(abspath(__file__)), 'expected.data.yml')) From b53bd5815af1ad3bd168b2b6cc003855f637228e Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Thu, 2 Jul 2020 21:53:56 +0800 Subject: [PATCH 19/20] Update test_flask.py --- tests/plugin/sw_flask/test_flask.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/plugin/sw_flask/test_flask.py b/tests/plugin/sw_flask/test_flask.py index 21a191ac..ab7354fd 100644 --- a/tests/plugin/sw_flask/test_flask.py +++ b/tests/plugin/sw_flask/test_flask.py @@ -20,7 +20,6 @@ import unittest from os.path import abspath, dirname -import requests from testcontainers.compose import DockerCompose from tests.plugin import BasePluginTest From 3a952b222b001fb49c073e3cf2193b08ad4a88e3 Mon Sep 17 00:00:00 2001 From: kezhenxu94 Date: Thu, 2 Jul 2020 22:47:48 +0800 Subject: [PATCH 20/20] Fix test --- tests/plugin/sw_flask/docker-compose.yml | 4 ++-- tests/plugin/sw_flask/test_flask.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/plugin/sw_flask/docker-compose.yml b/tests/plugin/sw_flask/docker-compose.yml index d84ab67e..61f3be7d 100644 --- a/tests/plugin/sw_flask/docker-compose.yml +++ b/tests/plugin/sw_flask/docker-compose.yml @@ -25,7 +25,7 @@ services: provider: extends: - service: provider + service: agent file: ../docker/docker-compose.base.yml ports: - 9091:9091 @@ -43,7 +43,7 @@ services: consumer: extends: - service: consumer + service: agent file: ../docker/docker-compose.base.yml ports: - 9090:9090 diff --git a/tests/plugin/sw_flask/test_flask.py b/tests/plugin/sw_flask/test_flask.py index ab7354fd..dfeaaa6c 100644 --- a/tests/plugin/sw_flask/test_flask.py +++ b/tests/plugin/sw_flask/test_flask.py @@ -25,7 +25,7 @@ from tests.plugin import BasePluginTest -class TestRequestPlugin(BasePluginTest): +class TestPlugin(BasePluginTest): @classmethod def setUpClass(cls): cls.compose = DockerCompose(filepath=dirname(abspath(__file__)))