You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by al...@apache.org on 2020/08/17 13:30:41 UTC

[skywalking-python] branch process-propagation created (now dd9dbb6)

This is an automated email from the ASF dual-hosted git repository.

alonelaval pushed a change to branch process-propagation
in repository https://gitbox.apache.org/repos/asf/skywalking-python.git.


      at dd9dbb6  update test

This branch includes the following new commits:

     new 7f414fe  test
     new 8a637a0  test
     new 01e2014  fix style
     new dd9dbb6  update test

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[skywalking-python] 03/04: fix style

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

alonelaval pushed a commit to branch process-propagation
in repository https://gitbox.apache.org/repos/asf/skywalking-python.git

commit 01e2014982e031a2d46d311221e30a8d46b493ab
Author: huawei <hu...@bit-s.cn>
AuthorDate: Mon Aug 17 21:28:51 2020 +0800

    fix style
---
 skywalking/agent/__init__.py                 | 20 --------------------
 skywalking/trace/ipc/process.py              |  5 -----
 tests/plugin/sw_process/services/consumer.py |  4 ++--
 3 files changed, 2 insertions(+), 27 deletions(-)

diff --git a/skywalking/agent/__init__.py b/skywalking/agent/__init__.py
index 8200f4c..b2b82a7 100644
--- a/skywalking/agent/__init__.py
+++ b/skywalking/agent/__init__.py
@@ -80,26 +80,6 @@ def start():
     __report_thread.start()
 
 
-# def restart():
-#     global __heartbeat_thread
-#     __heartbeat_thread = Thread(name='HeartbeatThread', target=__heartbeat, daemon=True)
-#     global __report_thread
-#     __report_thread = Thread(name='ReportThread', target=__report, daemon=True)
-#     global __queue
-#     __queue = Queue(maxsize=10000)
-#     global __finished
-#     __finished = Event()
-#     global __protocol
-#     __protocol = Protocol()  # type: Protocol
-#     global __started
-#     from skywalking import loggings
-#     loggings.init()
-#     __started = True
-#     __init()
-#     __heartbeat_thread.start()
-#     __report_thread.start()
-
-
 def stop():
     __finished.set()
 
diff --git a/skywalking/trace/ipc/process.py b/skywalking/trace/ipc/process.py
index b682ba5..6799e0e 100644
--- a/skywalking/trace/ipc/process.py
+++ b/skywalking/trace/ipc/process.py
@@ -28,12 +28,7 @@ class SwProcess(Process):
         self._sw_config = config.serialize()
 
     def run(self):
-        print(config.trace_ignore)
-        print(config.service_name)
-        print(config.collector_address)
         if agent.started() is False:
-            print("startttt-----------------")
             config.deserialize(self._sw_config)
             agent.start()
-        print(self._sw_config)
         super(SwProcess, self).run()
diff --git a/tests/plugin/sw_process/services/consumer.py b/tests/plugin/sw_process/services/consumer.py
index 725aaf9..cf30740 100644
--- a/tests/plugin/sw_process/services/consumer.py
+++ b/tests/plugin/sw_process/services/consumer.py
@@ -22,7 +22,7 @@ import multiprocessing
 
 
 def post():
-    requests.post("http://provider:9091/users")
+    requests.post("http://127.0.0.1:9091/users")
 
 
 if __name__ == '__main__':
@@ -46,7 +46,7 @@ if __name__ == '__main__':
         p1.start()
         p1.join()
 
-        res = requests.post("http://provider:9091/users")
+        res = requests.post("http://127.0.0.1:9091/users")
 
         return jsonify(res.json())
 


[skywalking-python] 04/04: update test

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

alonelaval pushed a commit to branch process-propagation
in repository https://gitbox.apache.org/repos/asf/skywalking-python.git

commit dd9dbb678212f21c8bbd1cb42a71091a34b8c0b0
Author: huawei <hu...@bit-s.cn>
AuthorDate: Mon Aug 17 21:29:56 2020 +0800

    update test
---
 tests/test_gunicorn.py |  25 +++++++++
 tests/test_process.py  | 142 -------------------------------------------------
 tests/test_uwsgi.py    |  18 -------
 3 files changed, 25 insertions(+), 160 deletions(-)

diff --git a/tests/test_gunicorn.py b/tests/test_gunicorn.py
new file mode 100644
index 0000000..525dbf0
--- /dev/null
+++ b/tests/test_gunicorn.py
@@ -0,0 +1,25 @@
+# -*- coding:utf-8 -*-
+# author:huawei
+import requests
+
+from skywalking import config, agent
+
+
+config.service_name = 'consumer'
+config.logging_level = 'DEBUG'
+config.flask_collect_http_params = True
+agent.start()
+
+from flask import Flask, jsonify
+
+app = Flask(__name__)
+
+
+@app.route("/users", methods=["POST", "GET"])
+def application():
+    requests.post("http://github.com")
+
+    return jsonify({"test": "hello world"})
+
+# PORT = 9090
+# app.run(host='0.0.0.0', port=PORT, debug=True)
diff --git a/tests/test_process.py b/tests/test_process.py
deleted file mode 100644
index 48044f1..0000000
--- a/tests/test_process.py
+++ /dev/null
@@ -1,142 +0,0 @@
-# # -*- coding:utf-8 -*-
-# # author:huawei
-#
-# import os
-# import time
-# from functools import wraps
-# from multiprocessing import Process
-# from multiprocessing.process import BaseProcess
-#
-# import requests
-#
-# from skywalking.trace.context import get_context
-#
-# from skywalking import agent, config
-# from skywalking.trace.tags import Tag
-#
-# origin__init__ = BaseProcess.__init__
-# origin_start = BaseProcess.start
-# origin_bootstrap = BaseProcess._bootstrap
-# origin_run = BaseProcess.run
-#
-#
-# def sw__init__(this: BaseProcess, group=None, target=None, name=None, args=(), kwargs={}, *,
-#                daemon=None):
-#     print(config.trace_ignore)
-#     if target is not None:
-#         if kwargs:
-#             kwargs["sw_config"] = config.serialize()
-#         else:
-#             kwargs = {"sw_config": config.serialize()}
-#     print("_init_ %s is running" % os.getpid())
-#     origin__init__(this, group=group, target=target, name=name, args=args, kwargs=kwargs, daemon=daemon)
-#
-#
-# def sw_start(this: BaseProcess):
-#     origin_start(this)
-#     print("start %s is running" % os.getpid())
-#
-#
-# def sw_run(this: BaseProcess):
-#     print("run %s is running" % os.getpid())
-#     origin_run(this)
-#
-#
-# def sw_bootstrap(this: BaseProcess, parent_sentinel=None):
-#     print("bootstrap %s is running" % os.getpid())
-#     origin_bootstrap(this, parent_sentinel=parent_sentinel)
-#
-#
-# def test_decorator():
-#     def decorator(func):
-#         @wraps(func)
-#         def wrapper(*args, **kwargs):
-#             if kwargs is not None and "sw_config" in kwargs:
-#                 print(kwargs.pop('sw_config', None))
-#                 print(agent.started())
-#                 if agent.started() is False:
-#                     agent.start()
-#             func(*args, **kwargs)
-#
-#         return wrapper
-#
-#     return decorator
-#
-#
-# # @test_decorator()
-# def test(name):
-#     # agent.start()
-#     print(name)
-#     print("test %s is running" % os.getpid())
-#     print(get_context())
-#     print(get_context().active_span())
-#     requests.post("http://www.baidu.com")
-#
-#
-# def test2(name):
-#     # agent.start()
-#     print(name)
-#     print("test %s is running" % os.getpid())
-#     print(get_context())
-#     print(get_context().active_span())
-#     with get_context().new_local_span("/test") as span:
-#         span.tag(Tag(key="huawei", val="test"))
-#         requests.post("http://www.baidu.com")
-#
-#
-# # 定义一个要共享实例化对象的类
-# class TestClass():
-#     def __init__(self):
-#         self.test_list = ["start flag"]
-#
-#     def test_function(self, arg):
-#         self.test_list.append(arg)
-#
-#     def print_test_list(self):
-#         for item in self.test_list:
-#             print(f"{item}")
-#
-#
-# class SwProcess(Process):
-#
-#     def __init__(self, group=None, target=None, name=None, args=(), kwargs={}, *,
-#                  daemon=None):
-#         super(SwProcess, self).__init__(group=group, target=target, name=name, args=args, kwargs=kwargs, daemon=daemon)
-#         self._sw_config = config.serialize()
-#
-#     def run(self):
-#         if agent.started() is False:
-#             config.deserialize(self._sw_config)
-#             agent.start()
-#
-#         super(SwProcess, self).run()
-#
-#
-# if __name__ == '__main__':
-#     # manager = BaseManager()
-#     # # 一定要在start前注册,不然就注册无效
-#     # manager.register('Test', TestClass)
-#     # manager.start()
-#     # obj = manager.Test()
-#
-#     # config.service_name = 'consumer'
-#     # config.logging_level = 'DEBUG'
-#     # config.trace_ignore = True
-#     # agent.start()
-#     #
-#     # # BaseProcess.__init__ = sw__init__
-#     # # BaseProcess.start = sw_start
-#     # # BaseProcess._bootstrap = sw_bootstrap
-#     # # BaseProcess.run = sw_run
-#     #
-#     # print("main %s is running" % os.getpid())
-#     #
-#     # # @runnable
-#     #
-#     # p1 = SwProcess(target=test, args=('anni',))
-#     # p1.start()
-#     # p2 = SwProcess(target=test2, args=('anni',))
-#     # p2.start()
-#     #
-#     # time.sleep(50)
-#     pass
diff --git a/tests/test_uwsgi.py b/tests/test_uwsgi.py
deleted file mode 100644
index 1e7e567..0000000
--- a/tests/test_uwsgi.py
+++ /dev/null
@@ -1,18 +0,0 @@
-# from flask import Flask
-#
-# from skywalking import config, agent
-#
-# config.service_name = 'consumer'
-# config.logging_level = 'DEBUG'
-# agent.start()
-#
-# app = Flask(__name__)
-#
-# @app.route('/')
-# def index():
-#     return "<span style='color:red'>I am app 1</span>"
-#
-#
-# # app.run()
-# if __name__ == "__main__":
-#     app.run(host='0.0.0.0')


[skywalking-python] 01/04: test

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

alonelaval pushed a commit to branch process-propagation
in repository https://gitbox.apache.org/repos/asf/skywalking-python.git

commit 7f414fe5fa793368919df55a536a05b73775cc54
Author: huawei <hu...@bit-s.cn>
AuthorDate: Mon Aug 10 21:29:53 2020 +0800

    test
---
 skywalking/trace/ipc/__init__.py             |   2 +
 skywalking/trace/ipc/process.py              |  30 ++++++
 tests/plugin/sw_process/__init__.py          |  16 +++
 tests/plugin/sw_process/docker-compose.yml   |  60 +++++++++++
 tests/plugin/sw_process/expected.data.yml    | 143 +++++++++++++++++++++++++++
 tests/plugin/sw_process/services/__init__.py |  16 +++
 tests/plugin/sw_process/services/consumer.py |  55 +++++++++++
 tests/plugin/sw_process/services/provider.py |  38 +++++++
 tests/plugin/sw_process/test_process.py      |  45 +++++++++
 tests/test_process.py                        |   2 +
 tests/test_uwsgi.py                          |   2 +
 11 files changed, 409 insertions(+)

diff --git a/skywalking/trace/ipc/__init__.py b/skywalking/trace/ipc/__init__.py
new file mode 100644
index 0000000..61749c8
--- /dev/null
+++ b/skywalking/trace/ipc/__init__.py
@@ -0,0 +1,2 @@
+# -*- coding:utf-8 -*-
+# author:huawei
\ No newline at end of file
diff --git a/skywalking/trace/ipc/process.py b/skywalking/trace/ipc/process.py
new file mode 100644
index 0000000..46911a3
--- /dev/null
+++ b/skywalking/trace/ipc/process.py
@@ -0,0 +1,30 @@
+#
+# 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.
+#
+
+class SwProcess(Process):
+
+    def __init__(self, group=None, target=None, name=None, args=(), kwargs={}, *,
+                 daemon=None):
+        super(SwProcess, self).__init__(group=group, target=target, name=name, args=args, kwargs=kwargs, daemon=daemon)
+        self._sw_config = config.serialize()
+
+    def run(self):
+        if agent.started() is False:
+            config.deserialize(self._sw_config)
+            agent.start()
+
+        super(SwProcess, self).run()
diff --git a/tests/plugin/sw_process/__init__.py b/tests/plugin/sw_process/__init__.py
new file mode 100644
index 0000000..b1312a0
--- /dev/null
+++ b/tests/plugin/sw_process/__init__.py
@@ -0,0 +1,16 @@
+#
+# 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/sw_process/docker-compose.yml b/tests/plugin/sw_process/docker-compose.yml
new file mode 100644
index 0000000..61f3be7
--- /dev/null
+++ b/tests/plugin/sw_process/docker-compose.yml
@@ -0,0 +1,60 @@
+#
+# 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:
+    extends:
+      service: collector
+      file: ../docker/docker-compose.base.yml
+
+  provider:
+    extends:
+      service: agent
+      file: ../docker/docker-compose.base.yml
+    ports:
+      - 9091:9091
+    volumes:
+      - ./services/provider.py:/app/provider.py
+    command: ['bash', '-c', 'pip install flask && python3 /app/provider.py']
+    depends_on:
+      collector:
+        condition: service_healthy
+    healthcheck:
+      test: ["CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/9091"]
+      interval: 5s
+      timeout: 60s
+      retries: 120
+
+  consumer:
+    extends:
+      service: agent
+      file: ../docker/docker-compose.base.yml
+    ports:
+      - 9090:9090
+    volumes:
+      - ./services/consumer.py:/app/consumer.py
+    command: ['bash', '-c', 'pip install flask && python3 /app/consumer.py']
+    depends_on:
+      collector:
+        condition: service_healthy
+      provider:
+        condition: service_healthy
+
+networks:
+  beyond:
diff --git a/tests/plugin/sw_process/expected.data.yml b/tests/plugin/sw_process/expected.data.yml
new file mode 100644
index 0000000..7eebf83
--- /dev/null
+++ b/tests/plugin/sw_process/expected.data.yml
@@ -0,0 +1,143 @@
+#
+# 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: 2
+    segments:
+      - segmentId: not null
+        spans:
+          - operationName: /users
+            operationId: 0
+            parentSpanId: -1
+            spanId: 0
+            spanLayer: Http
+            tags:
+              - key: http.method
+                value: POST
+              - key: url
+                value: http://provider:9091/users
+              - key: status.code
+                value: '200'
+            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: 7001
+            spanType: Entry
+            peer: not null
+            skipAnalysis: false
+      - segmentId: not null
+        spans:
+          - operationName: /users
+            operationId: 0
+            parentSpanId: -1
+            spanId: 0
+            spanLayer: Http
+            tags:
+              - key: http.method
+                value: POST
+              - key: url
+                value: http://provider:9091/users
+              - key: status.code
+                value: '200'
+            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: 7001
+            spanType: Entry
+            peer: not null
+            skipAnalysis: false
+  - serviceName: consumer
+    segmentSize: 2
+    segments:
+      - segmentId: not null
+        spans:
+          - operationName: /users
+            operationId: 0
+            parentSpanId: -1
+            spanId: 0
+            spanLayer: Http
+            startTime:  gt 0
+            endTime:  gt 0
+            componentId: 7002
+            isError: false
+            spanType: Exit
+            peer: provider:9091
+            skipAnalysis: false
+            tags:
+              - key: http.method
+                value: POST
+              - key: url
+                value: 'http://provider:9091/users'
+              - key: status.code
+                value: '200'
+      - 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: 7002
+            spanType: Exit
+            peer: provider:9091
+            skipAnalysis: false
+          - operationName: /users
+            operationId: 0
+            parentSpanId: -1
+            spanId: 0
+            spanLayer: Http
+            tags:
+              - key: http.method
+                value: GET
+              - key: url
+                value: http://0.0.0.0:9090/users
+              - key: http.params
+                value: "test=[test1,test2]\ntest2=[test2]"
+              - key: status.code
+                value: '200'
+            startTime: gt 0
+            endTime: gt 0
+            componentId: 7001
+            spanType: Entry
+            peer: not null
+            skipAnalysis: false
diff --git a/tests/plugin/sw_process/services/__init__.py b/tests/plugin/sw_process/services/__init__.py
new file mode 100644
index 0000000..b1312a0
--- /dev/null
+++ b/tests/plugin/sw_process/services/__init__.py
@@ -0,0 +1,16 @@
+#
+# 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/sw_process/services/consumer.py b/tests/plugin/sw_process/services/consumer.py
new file mode 100644
index 0000000..725aaf9
--- /dev/null
+++ b/tests/plugin/sw_process/services/consumer.py
@@ -0,0 +1,55 @@
+#
+# 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 requests
+
+from skywalking import agent, config
+from skywalking.trace.ipc.process import SwProcess
+import multiprocessing
+
+
+def post():
+    requests.post("http://provider:9091/users")
+
+
+if __name__ == '__main__':
+    multiprocessing.set_start_method('spawn')
+    config.service_name = 'consumer'
+    config.logging_level = 'DEBUG'
+    config.flask_collect_http_params = True
+    agent.start()
+
+    from flask import Flask, jsonify
+
+    app = Flask(__name__)
+
+
+    @app.route("/users", methods=["POST", "GET"])
+    def application():
+        from skywalking.trace.context import get_context
+        get_context().put_correlation("correlation", "correlation")
+
+        p1 = SwProcess(target=post)
+        p1.start()
+        p1.join()
+
+        res = requests.post("http://provider:9091/users")
+
+        return jsonify(res.json())
+
+
+    PORT = 9090
+    app.run(host='0.0.0.0', port=PORT, debug=False)
diff --git a/tests/plugin/sw_process/services/provider.py b/tests/plugin/sw_process/services/provider.py
new file mode 100644
index 0000000..6c2a04d
--- /dev/null
+++ b/tests/plugin/sw_process/services/provider.py
@@ -0,0 +1,38 @@
+#
+# 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()
+
+    from flask import Flask, jsonify
+
+    app = Flask(__name__)
+
+    @app.route("/users", methods=["POST", "GET"])
+    def application():
+        from skywalking.trace.context import get_context
+        time.sleep(0.5)
+        return jsonify({"correlation": get_context().get_correlation("correlation")})
+
+    PORT = 9091
+    app.run(host='0.0.0.0', port=PORT, debug=False)
diff --git a/tests/plugin/sw_process/test_process.py b/tests/plugin/sw_process/test_process.py
new file mode 100644
index 0000000..d9ca543
--- /dev/null
+++ b/tests/plugin/sw_process/test_process.py
@@ -0,0 +1,45 @@
+#
+# 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 inspect
+import time
+import unittest
+from os.path import dirname
+
+import requests
+from testcontainers.compose import DockerCompose
+
+from tests.plugin import BasePluginTest
+
+
+class TestPlugin(BasePluginTest):
+    @classmethod
+    def setUpClass(cls):
+        cls.compose = DockerCompose(filepath=dirname(inspect.getfile(cls)))
+        cls.compose.start()
+        cls.compose.wait_for(cls.url(('consumer', '9090'), 'users?test=test1&test=test2&test2=test2'))
+
+    def test_plugin(self):
+        time.sleep(20)
+
+        self.validate()
+        response = requests.get(TestPlugin.url(('consumer', '9090'), 'users'))
+        self.assertEqual(response.status_code, 200)
+        self.assertEqual(response.json()["correlation"], "correlation")
+
+
+if __name__ == '__main__':
+    unittest.main()
diff --git a/tests/test_process.py b/tests/test_process.py
new file mode 100644
index 0000000..61749c8
--- /dev/null
+++ b/tests/test_process.py
@@ -0,0 +1,2 @@
+# -*- coding:utf-8 -*-
+# author:huawei
\ No newline at end of file
diff --git a/tests/test_uwsgi.py b/tests/test_uwsgi.py
new file mode 100644
index 0000000..61749c8
--- /dev/null
+++ b/tests/test_uwsgi.py
@@ -0,0 +1,2 @@
+# -*- coding:utf-8 -*-
+# author:huawei
\ No newline at end of file


[skywalking-python] 02/04: test

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

alonelaval pushed a commit to branch process-propagation
in repository https://gitbox.apache.org/repos/asf/skywalking-python.git

commit 8a637a054f84ddcb58cde75e0b2a583d365f612d
Author: huawei <hu...@bit-s.cn>
AuthorDate: Mon Aug 10 21:30:53 2020 +0800

    test
---
 browser/__init__.py              |   0
 common/__init__.py               |   0
 language_agent/__init__.py       |   0
 management/__init__.py           |   0
 profile/__init__.py              |   0
 service_mesh_probe/__init__.py   |   0
 skywalking/agent/__init__.py     |  30 +++++++-
 skywalking/config.py             |  68 +++++++++++++++++-
 skywalking/trace/ipc/__init__.py |  18 ++++-
 skywalking/trace/ipc/process.py  |  11 ++-
 tests/plugin/__init__.py         |   4 +-
 tests/test_process.py            | 144 ++++++++++++++++++++++++++++++++++++++-
 tests/test_uwsgi.py              |  20 +++++-
 13 files changed, 281 insertions(+), 14 deletions(-)

diff --git a/browser/__init__.py b/browser/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/common/__init__.py b/common/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/language_agent/__init__.py b/language_agent/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/management/__init__.py b/management/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/profile/__init__.py b/profile/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/service_mesh_probe/__init__.py b/service_mesh_probe/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/skywalking/agent/__init__.py b/skywalking/agent/__init__.py
index fe181a5..8200f4c 100644
--- a/skywalking/agent/__init__.py
+++ b/skywalking/agent/__init__.py
@@ -32,8 +32,10 @@ logger = logging.getLogger(__name__)
 def __heartbeat():
     while not __finished.is_set():
         if connected():
-            __protocol.heartbeat()
-
+            try:
+                __protocol.heartbeat()
+            except:
+                pass
         __finished.wait(30 if connected() else 3)
 
 
@@ -78,10 +80,34 @@ def start():
     __report_thread.start()
 
 
+# def restart():
+#     global __heartbeat_thread
+#     __heartbeat_thread = Thread(name='HeartbeatThread', target=__heartbeat, daemon=True)
+#     global __report_thread
+#     __report_thread = Thread(name='ReportThread', target=__report, daemon=True)
+#     global __queue
+#     __queue = Queue(maxsize=10000)
+#     global __finished
+#     __finished = Event()
+#     global __protocol
+#     __protocol = Protocol()  # type: Protocol
+#     global __started
+#     from skywalking import loggings
+#     loggings.init()
+#     __started = True
+#     __init()
+#     __heartbeat_thread.start()
+#     __report_thread.start()
+
+
 def stop():
     __finished.set()
 
 
+def started():
+    return __started
+
+
 def connected():
     return __protocol.connected()
 
diff --git a/skywalking/config.py b/skywalking/config.py
index fb89ba8..4b21912 100644
--- a/skywalking/config.py
+++ b/skywalking/config.py
@@ -35,14 +35,14 @@ pymongo_parameters_max_length = int(os.getenv('SW_PYMONGO_PARAMETERS_MAX_LENGTH'
 ignore_suffix = os.getenv('SW_IGNORE_SUFFIX') or '.jpg,.jpeg,.js,.css,.png,.bmp,.gif,.ico,.mp3,' \
                                                  '.mp4,.html,.svg '  # type: str
 flask_collect_http_params = True if os.getenv('SW_FLASK_COLLECT_HTTP_PARAMS') and \
-                                    os.getenv('SW_FLASK_COLLECT_HTTP_PARAMS') == 'True' else False   # type: bool
+                                    os.getenv('SW_FLASK_COLLECT_HTTP_PARAMS') == 'True' else False  # type: bool
 http_params_length_threshold = int(os.getenv('SW_HTTP_PARAMS_LENGTH_THRESHOLD') or '1024')  # type: int
 django_collect_http_params = True if os.getenv('SW_DJANGO_COLLECT_HTTP_PARAMS') and \
-                                    os.getenv('SW_DJANGO_COLLECT_HTTP_PARAMS') == 'True' else False   # type: bool
+                                     os.getenv('SW_DJANGO_COLLECT_HTTP_PARAMS') == 'True' else False  # type: bool
 correlation_element_max_number = int(os.getenv('SW_CORRELATION_ELEMENT_MAX_NUMBER') or '3')  # type: int
 correlation_value_max_length = int(os.getenv('SW_CORRELATION_VALUE_MAX_LENGTH') or '128')  # type: int
 trace_ignore = True if os.getenv('SW_TRACE_IGNORE') and \
-                       os.getenv('SW_TRACE_IGNORE') == 'True' else False   # type: bool
+                       os.getenv('SW_TRACE_IGNORE') == 'True' else False  # type: bool
 trace_ignore_path = (os.getenv('SW_TRACE_IGNORE_PATH') or '').split(',')  # type: List[str]
 
 
@@ -67,3 +67,65 @@ def init(
 
     global authentication
     authentication = token or authentication
+
+
+def serialize():
+    return {
+        "service_name": service_name,
+        "collector_address": collector_address,
+        "protocol": protocol,
+        "authentication": authentication,
+        "logging_level": logging_level,
+        "disable_plugins": disable_plugins,
+        "mysql_trace_sql_parameters": mysql_trace_sql_parameters,
+        "mysql_sql_parameters_max_length": mysql_sql_parameters_max_length,
+        "pymongo_trace_parameters": pymongo_trace_parameters,
+        "pymongo_parameters_max_length": pymongo_parameters_max_length,
+        "ignore_suffix": ignore_suffix,
+        "flask_collect_http_params": flask_collect_http_params,
+        "http_params_length_threshold": http_params_length_threshold,
+        "django_collect_http_params": django_collect_http_params,
+        "correlation_element_max_number": correlation_element_max_number,
+        "correlation_value_max_length": correlation_value_max_length,
+        "trace_ignore": trace_ignore,
+        "trace_ignore_path": trace_ignore_path
+    }
+
+
+def deserialize(data):
+    global service_name
+    service_name = data["service_name"]
+    global collector_address
+    collector_address = data["collector_address"]
+    global protocol
+    protocol = data["protocol"]
+    global authentication
+    authentication = data["authentication"]
+    global logging_level
+    logging_level = data["logging_level"]
+    global disable_plugins
+    disable_plugins = data["disable_plugins"]
+    global mysql_trace_sql_parameters
+    mysql_trace_sql_parameters = data["mysql_trace_sql_parameters"]
+    global mysql_sql_parameters_max_length
+    mysql_sql_parameters_max_length = data["mysql_sql_parameters_max_length"]
+    global pymongo_trace_parameters
+    pymongo_trace_parameters = data["pymongo_trace_parameters"]
+    global pymongo_parameters_max_length
+    pymongo_parameters_max_length = data["pymongo_parameters_max_length"]
+    global ignore_suffix
+    ignore_suffix = data["ignore_suffix"]
+    global flask_collect_http_params
+    flask_collect_http_params = data["flask_collect_http_params"]
+    global http_params_length_threshold
+    http_params_length_threshold = data["http_params_length_threshold"]
+    global django_collect_http_params
+    django_collect_http_params = data["django_collect_http_params"]
+    global correlation_element_max_number
+    correlation_element_max_number = data["correlation_element_max_number"]
+    global correlation_value_max_length
+    correlation_value_max_length = data["correlation_value_max_length"]
+    global trace_ignore
+    trace_ignore = data["trace_ignore"]
+    global trace_ignore_path
+    trace_ignore_path = data["trace_ignore_path"]
diff --git a/skywalking/trace/ipc/__init__.py b/skywalking/trace/ipc/__init__.py
index 61749c8..b1312a0 100644
--- a/skywalking/trace/ipc/__init__.py
+++ b/skywalking/trace/ipc/__init__.py
@@ -1,2 +1,16 @@
-# -*- coding:utf-8 -*-
-# author:huawei
\ No newline at end of file
+#
+# 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/skywalking/trace/ipc/process.py b/skywalking/trace/ipc/process.py
index 46911a3..b682ba5 100644
--- a/skywalking/trace/ipc/process.py
+++ b/skywalking/trace/ipc/process.py
@@ -15,6 +15,11 @@
 # limitations under the License.
 #
 
+from multiprocessing import Process
+
+from skywalking import config, agent
+
+
 class SwProcess(Process):
 
     def __init__(self, group=None, target=None, name=None, args=(), kwargs={}, *,
@@ -23,8 +28,12 @@ class SwProcess(Process):
         self._sw_config = config.serialize()
 
     def run(self):
+        print(config.trace_ignore)
+        print(config.service_name)
+        print(config.collector_address)
         if agent.started() is False:
+            print("startttt-----------------")
             config.deserialize(self._sw_config)
             agent.start()
-
+        print(self._sw_config)
         super(SwProcess, self).run()
diff --git a/tests/plugin/__init__.py b/tests/plugin/__init__.py
index f858a1f..c838308 100644
--- a/tests/plugin/__init__.py
+++ b/tests/plugin/__init__.py
@@ -49,8 +49,8 @@ class BasePluginTest(unittest.TestCase, ABC):
 
     @classmethod
     def tearDownClass(cls):
-        cls.compose.stop()
-
+        # cls.compose.stop()
+        pass
     @classmethod
     def host(cls, service_port):
         # type: (ServicePort) -> str
diff --git a/tests/test_process.py b/tests/test_process.py
index 61749c8..48044f1 100644
--- a/tests/test_process.py
+++ b/tests/test_process.py
@@ -1,2 +1,142 @@
-# -*- coding:utf-8 -*-
-# author:huawei
\ No newline at end of file
+# # -*- coding:utf-8 -*-
+# # author:huawei
+#
+# import os
+# import time
+# from functools import wraps
+# from multiprocessing import Process
+# from multiprocessing.process import BaseProcess
+#
+# import requests
+#
+# from skywalking.trace.context import get_context
+#
+# from skywalking import agent, config
+# from skywalking.trace.tags import Tag
+#
+# origin__init__ = BaseProcess.__init__
+# origin_start = BaseProcess.start
+# origin_bootstrap = BaseProcess._bootstrap
+# origin_run = BaseProcess.run
+#
+#
+# def sw__init__(this: BaseProcess, group=None, target=None, name=None, args=(), kwargs={}, *,
+#                daemon=None):
+#     print(config.trace_ignore)
+#     if target is not None:
+#         if kwargs:
+#             kwargs["sw_config"] = config.serialize()
+#         else:
+#             kwargs = {"sw_config": config.serialize()}
+#     print("_init_ %s is running" % os.getpid())
+#     origin__init__(this, group=group, target=target, name=name, args=args, kwargs=kwargs, daemon=daemon)
+#
+#
+# def sw_start(this: BaseProcess):
+#     origin_start(this)
+#     print("start %s is running" % os.getpid())
+#
+#
+# def sw_run(this: BaseProcess):
+#     print("run %s is running" % os.getpid())
+#     origin_run(this)
+#
+#
+# def sw_bootstrap(this: BaseProcess, parent_sentinel=None):
+#     print("bootstrap %s is running" % os.getpid())
+#     origin_bootstrap(this, parent_sentinel=parent_sentinel)
+#
+#
+# def test_decorator():
+#     def decorator(func):
+#         @wraps(func)
+#         def wrapper(*args, **kwargs):
+#             if kwargs is not None and "sw_config" in kwargs:
+#                 print(kwargs.pop('sw_config', None))
+#                 print(agent.started())
+#                 if agent.started() is False:
+#                     agent.start()
+#             func(*args, **kwargs)
+#
+#         return wrapper
+#
+#     return decorator
+#
+#
+# # @test_decorator()
+# def test(name):
+#     # agent.start()
+#     print(name)
+#     print("test %s is running" % os.getpid())
+#     print(get_context())
+#     print(get_context().active_span())
+#     requests.post("http://www.baidu.com")
+#
+#
+# def test2(name):
+#     # agent.start()
+#     print(name)
+#     print("test %s is running" % os.getpid())
+#     print(get_context())
+#     print(get_context().active_span())
+#     with get_context().new_local_span("/test") as span:
+#         span.tag(Tag(key="huawei", val="test"))
+#         requests.post("http://www.baidu.com")
+#
+#
+# # 定义一个要共享实例化对象的类
+# class TestClass():
+#     def __init__(self):
+#         self.test_list = ["start flag"]
+#
+#     def test_function(self, arg):
+#         self.test_list.append(arg)
+#
+#     def print_test_list(self):
+#         for item in self.test_list:
+#             print(f"{item}")
+#
+#
+# class SwProcess(Process):
+#
+#     def __init__(self, group=None, target=None, name=None, args=(), kwargs={}, *,
+#                  daemon=None):
+#         super(SwProcess, self).__init__(group=group, target=target, name=name, args=args, kwargs=kwargs, daemon=daemon)
+#         self._sw_config = config.serialize()
+#
+#     def run(self):
+#         if agent.started() is False:
+#             config.deserialize(self._sw_config)
+#             agent.start()
+#
+#         super(SwProcess, self).run()
+#
+#
+# if __name__ == '__main__':
+#     # manager = BaseManager()
+#     # # 一定要在start前注册,不然就注册无效
+#     # manager.register('Test', TestClass)
+#     # manager.start()
+#     # obj = manager.Test()
+#
+#     # config.service_name = 'consumer'
+#     # config.logging_level = 'DEBUG'
+#     # config.trace_ignore = True
+#     # agent.start()
+#     #
+#     # # BaseProcess.__init__ = sw__init__
+#     # # BaseProcess.start = sw_start
+#     # # BaseProcess._bootstrap = sw_bootstrap
+#     # # BaseProcess.run = sw_run
+#     #
+#     # print("main %s is running" % os.getpid())
+#     #
+#     # # @runnable
+#     #
+#     # p1 = SwProcess(target=test, args=('anni',))
+#     # p1.start()
+#     # p2 = SwProcess(target=test2, args=('anni',))
+#     # p2.start()
+#     #
+#     # time.sleep(50)
+#     pass
diff --git a/tests/test_uwsgi.py b/tests/test_uwsgi.py
index 61749c8..1e7e567 100644
--- a/tests/test_uwsgi.py
+++ b/tests/test_uwsgi.py
@@ -1,2 +1,18 @@
-# -*- coding:utf-8 -*-
-# author:huawei
\ No newline at end of file
+# from flask import Flask
+#
+# from skywalking import config, agent
+#
+# config.service_name = 'consumer'
+# config.logging_level = 'DEBUG'
+# agent.start()
+#
+# app = Flask(__name__)
+#
+# @app.route('/')
+# def index():
+#     return "<span style='color:red'>I am app 1</span>"
+#
+#
+# # app.run()
+# if __name__ == "__main__":
+#     app.run(host='0.0.0.0')