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/23 04:52:36 UTC
[skywalking-python] branch kubernetes created (now 92678e9)
This is an automated email from the ASF dual-hosted git repository.
alonelaval pushed a change to branch kubernetes
in repository https://gitbox.apache.org/repos/asf/skywalking-python.git.
at 92678e9 add github k3s action
This branch includes the following new commits:
new d0d5c91 Add kubernetes plugin
new 0f69e54 merge master
new 6e00ee5 update test case
new f256f59 Merge branch 'master' into kubenates
new 92678e9 add github k3s action
The 5 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/05: update test case
Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
alonelaval pushed a commit to branch kubernetes
in repository https://gitbox.apache.org/repos/asf/skywalking-python.git
commit 6e00ee575ec95af448bb4df3a1ad5c1cde776f50
Author: huawei <hu...@bit-s.cn>
AuthorDate: Sun Aug 23 12:40:54 2020 +0800
update test case
---
docs/Plugins.md | 1 +
setup.py | 2 +-
tests/plugin/sw_kubernates/docker-compose.yml | 22 +---
tests/plugin/sw_kubernates/expected.data.yml | 148 ++++++++----------------
tests/plugin/sw_kubernates/services/consumer.py | 16 +--
5 files changed, 63 insertions(+), 126 deletions(-)
diff --git a/docs/Plugins.md b/docs/Plugins.md
index b55ba24..7a579c0 100644
--- a/docs/Plugins.md
+++ b/docs/Plugins.md
@@ -31,6 +31,7 @@ Library | Versions | Plugin Name
| [pika](https://pika.readthedocs.io/en/stable/) | 1.1.0 | `sw_rabbitmq` |
| [pymongo](https://pymongo.readthedocs.io/en/stable/) | 3.11.0 | `sw_pymongo` |
| [elasticsearch](https://github.com/elastic/elasticsearch-py) | 7.9.0 | `sw_elasticsearch` |
+| [kubernetes](https://github.com/kubernetes-client/python) | 11.0.0 | `sw_kubernetes` |
The column `Versions` only indicates that the versions are tested, if you found the newer versions are also supported, welcome to add the newer version into the table.
>>>>>>> master
diff --git a/setup.py b/setup.py
index 8555b53..98a00c2 100644
--- a/setup.py
+++ b/setup.py
@@ -54,7 +54,7 @@ setup(
"pika",
"pymongo",
"elasticsearch",
- "kubernetes"
+ "kubernetes",
"pytest",
],
},
diff --git a/tests/plugin/sw_kubernates/docker-compose.yml b/tests/plugin/sw_kubernates/docker-compose.yml
index 61f3be7..4d2bb8d 100644
--- a/tests/plugin/sw_kubernates/docker-compose.yml
+++ b/tests/plugin/sw_kubernates/docker-compose.yml
@@ -23,24 +23,6 @@ services:
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
@@ -49,12 +31,10 @@ services:
- 9090:9090
volumes:
- ./services/consumer.py:/app/consumer.py
- command: ['bash', '-c', 'pip install flask && python3 /app/consumer.py']
+ command: ['bash', '-c', 'pip install flask && pip install kubernetes && python3 /app/consumer.py']
depends_on:
collector:
condition: service_healthy
- provider:
- condition: service_healthy
networks:
beyond:
diff --git a/tests/plugin/sw_kubernates/expected.data.yml b/tests/plugin/sw_kubernates/expected.data.yml
index add2226..8ce92f7 100644
--- a/tests/plugin/sw_kubernates/expected.data.yml
+++ b/tests/plugin/sw_kubernates/expected.data.yml
@@ -16,149 +16,103 @@
#
segmentItems:
- - serviceName: provider
- segmentSize: 2
+ - serviceName: consumer
+ segmentSize: 1
segments:
- segmentId: not null
spans:
- - operationName: /users
+ - operationName: /api/v1/namespaces
operationId: 0
- parentSpanId: -1
- spanId: 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'
- 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
+ componentId: 96
+ isError: false
+ spanType: Exit
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
+ value: GET
- key: url
- value: http://provider:9091/users
+ value: not null
- 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
+ - operationName: /api/v1/pods
operationId: 0
parentSpanId: 0
- spanId: 1
+ spanId: 2
spanLayer: Http
- startTime: gt 0
- endTime: gt 0
- componentId: 7002
+ startTime: gt 0
+ endTime: gt 0
+ componentId: 96
isError: false
spanType: Exit
- peer: provider:9091
+ peer: not null
skipAnalysis: false
tags:
- key: http.method
- value: POST
+ value: GET
- key: url
- value: 'http://provider:9091/users'
+ value: not null
- key: status.code
value: '200'
- - operationName: /test
- operationId: 0
- parentSpanId: -1
- spanId: 0
- spanLayer: Unknown
- startTime: gt 0
- endTime: gt 0
- componentId: 0
- isError: false
- spanType: Local
- peer: ''
- skipAnalysis: false
- refs:
- - parentEndpoint: /users
- networkAddress: ''
- refType: CrossThread
- parentSpanId: 0
- parentTraceSegmentId: not null
- parentServiceInstance: not null
- parentService: consumer
- traceId: not null
- - segmentId: not null
- spans:
- - operationName: /users
+ - operationName: /apis/apps/v1/deployments
operationId: 0
parentSpanId: 0
- spanId: 1
+ spanId: 3
spanLayer: Http
+ startTime: gt 0
+ endTime: gt 0
+ componentId: 96
+ isError: false
+ spanType: Exit
+ peer: not null
+ skipAnalysis: false
tags:
- key: http.method
- value: POST
+ value: GET
- key: url
- value: http://provider:9091/users
+ value: not null
- key: status.code
value: '200'
+ - operationName: /apis/networking.k8s.io/v1beta1/ingresses
+ operationId: 0
+ parentSpanId: 0
+ spanId: 4
+ spanLayer: Http
startTime: gt 0
endTime: gt 0
- componentId: 7002
+ componentId: 96
+ isError: false
spanType: Exit
- peer: provider:9091
+ peer: not null
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]"
+ value: not null
- key: status.code
value: '200'
+ - operationName: /users
+ operationId: 0
+ parentSpanId: -1
+ spanId: 0
+ spanLayer: Http
startTime: gt 0
endTime: gt 0
componentId: 7001
+ isError: false
spanType: Entry
peer: not null
skipAnalysis: false
+ tags:
+ - key: http.method
+ value: GET
+ - key: url
+ value: 'http://0.0.0.0:9090/users'
+ - key: status.code
+ value: '200'
diff --git a/tests/plugin/sw_kubernates/services/consumer.py b/tests/plugin/sw_kubernates/services/consumer.py
index 3a384b8..4b160c0 100644
--- a/tests/plugin/sw_kubernates/services/consumer.py
+++ b/tests/plugin/sw_kubernates/services/consumer.py
@@ -17,7 +17,7 @@
from skywalking import agent, config
-import kubernetes.config as kube_config
+
if __name__ == '__main__':
config.service_name = 'consumer'
@@ -25,18 +25,20 @@ if __name__ == '__main__':
agent.start()
from flask import Flask, jsonify
- from kubernetes import client
- app = Flask(__name__)
- kube_config.load_kube_config()
- core_conn = client.CoreV1Api()
- apps_conn = client.AppsV1Api()
- net_conn = client.NetworkingV1beta1Api()
+ app = Flask(__name__)
@app.route("/users", methods=["POST", "GET"])
def application():
+ from kubernetes import client
+ import kubernetes.config as kube_config
+ kube_config.load_kube_config()
+ core_conn = client.CoreV1Api()
+ apps_conn = client.AppsV1Api()
+ net_conn = client.NetworkingV1beta1Api()
+
core_conn.list_namespace()
core_conn.list_pod_for_all_namespaces()
apps_conn.list_deployment_for_all_namespaces()
[skywalking-python] 04/05: Merge branch 'master' into kubenates
Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
alonelaval pushed a commit to branch kubernetes
in repository https://gitbox.apache.org/repos/asf/skywalking-python.git
commit f256f59e593ee124f459d4335b6e4d63c61f63fe
Merge: 6e00ee5 c733985
Author: huawei <hu...@bit-s.cn>
AuthorDate: Sun Aug 23 12:43:29 2020 +0800
Merge branch 'master' into kubenates
README.md | 9 +-
skywalking/agent/__init__.py | 4 +
skywalking/config.py | 35 ++++-
.../trace/ipc/__init__.py | 28 ----
.../trace/ipc/process.py | 34 ++---
tests/plugin/docker/Dockerfile.tool | 2 +-
.../Dockerfile.tool => sw_process/__init__.py} | 28 ----
tests/plugin/sw_process/docker-compose.yml | 60 +++++++++
tests/plugin/sw_process/expected.data.yml | 143 +++++++++++++++++++++
.../services/__init__.py} | 28 ----
.../services/consumer.py} | 42 +++---
.../services/provider.py} | 35 ++---
.../Dockerfile.tool => sw_process/test_process.py} | 34 ++---
13 files changed, 307 insertions(+), 175 deletions(-)
[skywalking-python] 01/05: Add kubernetes plugin
Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
alonelaval pushed a commit to branch kubernetes
in repository https://gitbox.apache.org/repos/asf/skywalking-python.git
commit d0d5c911cb1e1385c6a9f5b7b4933fc2068eac41
Author: huawei <hu...@bit-s.cn>
AuthorDate: Tue Aug 18 23:31:24 2020 +0800
Add kubernetes plugin
---
docs/Plugins.md | 1 +
requirements.txt | 1 +
setup.py | 1 +
skywalking/__init__.py | 1 +
skywalking/plugins/sw_kubernetes.py | 63 +++++++++
tests/plugin/sw_kubernates/__init__.py | 16 +++
tests/plugin/sw_kubernates/docker-compose.yml | 60 +++++++++
tests/plugin/sw_kubernates/expected.data.yml | 164 ++++++++++++++++++++++++
tests/plugin/sw_kubernates/services/__init__.py | 16 +++
tests/plugin/sw_kubernates/services/consumer.py | 54 ++++++++
tests/plugin/sw_kubernates/test_kubernates.py | 43 +++++++
11 files changed, 420 insertions(+)
diff --git a/docs/Plugins.md b/docs/Plugins.md
index dbe077a..49d3ad8 100644
--- a/docs/Plugins.md
+++ b/docs/Plugins.md
@@ -14,3 +14,4 @@ Library | Plugin Name
| [pika](https://pika.readthedocs.io/en/stable/) | `sw_rabbitmq` |
| [pymongo](https://pymongo.readthedocs.io/en/stable/) | `sw_pymongo` |
| [elasticsearch](https://github.com/elastic/elasticsearch-py) | `sw_elasticsearch` |
+| [kubernetes](https://github.com/kubernetes-client/python) | `sw_kubernetes` |
\ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
index 6bbffba..fe7081e 100755
--- a/requirements.txt
+++ b/requirements.txt
@@ -35,3 +35,4 @@ websocket-client==0.57.0
Werkzeug==1.0.1
wrapt==1.12.1
elasticsearch==7.8.0
+kubernetes==11.0.0
\ No newline at end of file
diff --git a/setup.py b/setup.py
index 27c1089..67f41ca 100644
--- a/setup.py
+++ b/setup.py
@@ -54,6 +54,7 @@ setup(
"pika",
"pymongo",
"elasticsearch",
+ "kubernetes"
],
},
classifiers=[
diff --git a/skywalking/__init__.py b/skywalking/__init__.py
index 3616a32..005e93a 100644
--- a/skywalking/__init__.py
+++ b/skywalking/__init__.py
@@ -36,6 +36,7 @@ class Component(Enum):
RabbitmqProducer = 52
RabbitmqConsumer = 53
Elasticsearch = 47
+ Kubernetes = 96
class Layer(Enum):
diff --git a/skywalking/plugins/sw_kubernetes.py b/skywalking/plugins/sw_kubernetes.py
new file mode 100644
index 0000000..f6af33a
--- /dev/null
+++ b/skywalking/plugins/sw_kubernetes.py
@@ -0,0 +1,63 @@
+#
+# 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 logging
+
+from skywalking import Layer, Component
+from skywalking.trace import tags
+from skywalking.trace.context import get_context
+from skywalking.trace.tags import Tag
+
+logger = logging.getLogger(__name__)
+
+
+def install():
+ # noinspection PyBroadException
+ try:
+ from kubernetes.client.rest import RESTClientObject
+
+ _request = RESTClientObject.request
+
+ def _sw_request(this: RESTClientObject, method, url, query_params=None, headers=None,
+ body=None, post_params=None, _preload_content=True,
+ _request_timeout=None):
+
+ from urllib.parse import urlparse
+ url_param = urlparse(url)
+
+ context = get_context()
+ with context.new_exit_span(op=url_param.path or "/", peer=url_param.netloc) as span:
+ span.layer = Layer.Http
+ span.component = Component.Kubernetes
+ try:
+ res = _request(this, method, url, query_params=query_params, headers=headers,
+ post_params=post_params, body=body, _preload_content=_preload_content,
+ _request_timeout=_request_timeout)
+
+ 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))
+ if res.status >= 400:
+ span.error_occurred = True
+ except BaseException as e:
+ span.raised()
+ raise e
+ return res
+
+ RESTClientObject.request = _sw_request
+ except Exception:
+ logger.warning('failed to install plugin %s', __name__)
diff --git a/tests/plugin/sw_kubernates/__init__.py b/tests/plugin/sw_kubernates/__init__.py
new file mode 100644
index 0000000..b1312a0
--- /dev/null
+++ b/tests/plugin/sw_kubernates/__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_kubernates/docker-compose.yml b/tests/plugin/sw_kubernates/docker-compose.yml
new file mode 100644
index 0000000..61f3be7
--- /dev/null
+++ b/tests/plugin/sw_kubernates/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_kubernates/expected.data.yml b/tests/plugin/sw_kubernates/expected.data.yml
new file mode 100644
index 0000000..add2226
--- /dev/null
+++ b/tests/plugin/sw_kubernates/expected.data.yml
@@ -0,0 +1,164 @@
+#
+# 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: 0
+ spanId: 1
+ 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'
+ - operationName: /test
+ operationId: 0
+ parentSpanId: -1
+ spanId: 0
+ spanLayer: Unknown
+ startTime: gt 0
+ endTime: gt 0
+ componentId: 0
+ isError: false
+ spanType: Local
+ peer: ''
+ skipAnalysis: false
+ refs:
+ - parentEndpoint: /users
+ networkAddress: ''
+ refType: CrossThread
+ parentSpanId: 0
+ parentTraceSegmentId: not null
+ parentServiceInstance: not null
+ parentService: consumer
+ traceId: not null
+ - 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_kubernates/services/__init__.py b/tests/plugin/sw_kubernates/services/__init__.py
new file mode 100644
index 0000000..b1312a0
--- /dev/null
+++ b/tests/plugin/sw_kubernates/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_kubernates/services/consumer.py b/tests/plugin/sw_kubernates/services/consumer.py
new file mode 100644
index 0000000..7a5afba
--- /dev/null
+++ b/tests/plugin/sw_kubernates/services/consumer.py
@@ -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.
+#
+
+
+from skywalking import agent, config
+
+if __name__ == '__main__':
+ config.service_name = 'consumer'
+ config.logging_level = 'DEBUG'
+ agent.start()
+
+ from flask import Flask, jsonify
+ from kubernetes import client
+
+ app = Flask(__name__)
+
+ k8s_server = ""
+ k8s_token = ""
+
+ configuration = client.Configuration()
+ configuration.host = k8s_server
+ configuration.verify_ssl = False
+ configuration.api_key = {"authorization": "Bearer " + k8s_token}
+ connection = client.api_client.ApiClient(configuration=configuration)
+ core_conn = client.CoreV1Api(connection)
+ apps_conn = client.AppsV1Api(connection)
+ net_conn = client.NetworkingV1beta1Api(connection)
+
+
+ @app.route("/users", methods=["POST", "GET"])
+ def application():
+ core_conn.list_namespace()
+ core_conn.list_pod_for_all_namespaces()
+ apps_conn.list_deployment_for_all_namespaces()
+ net_conn.list_ingress_for_all_namespaces()
+ return jsonify({"song": "Despacito", "artist": "Luis Fonsi"})
+
+
+ PORT = 9090
+ app.run(host='0.0.0.0', port=PORT, debug=True)
diff --git a/tests/plugin/sw_kubernates/test_kubernates.py b/tests/plugin/sw_kubernates/test_kubernates.py
new file mode 100644
index 0000000..4fb10ae
--- /dev/null
+++ b/tests/plugin/sw_kubernates/test_kubernates.py
@@ -0,0 +1,43 @@
+#
+# 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'))
+
+ def test_plugin(self):
+ time.sleep(10)
+
+ self.validate()
+
+
+
+if __name__ == '__main__':
+ unittest.main()
[skywalking-python] 02/05: merge master
Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
alonelaval pushed a commit to branch kubernetes
in repository https://gitbox.apache.org/repos/asf/skywalking-python.git
commit 0f69e54b3cb1c4e0aa556fac6d9c0869f172280e
Merge: d0d5c91 21011a9
Author: huawei <hu...@bit-s.cn>
AuthorDate: Sat Aug 22 21:46:38 2020 +0800
merge master
.github/PULL_REQUEST_TEMPLATE | 1 -
.github/workflows/build.yaml | 2 +-
.gitignore | 3 +-
Makefile | 2 +-
docs/Plugins.md | 21 ++++-
requirements.txt | 18 ++++-
setup.py | 1 +
tests/plugin/__init__.py | 91 ----------------------
tests/plugin/{__init__.py => base.py} | 56 ++-----------
tests/plugin/conftest.py | 72 +++++++++++++++++
tests/plugin/{sw_http/test_http.py => pytest.ini} | 23 +-----
tests/plugin/sw_django/docker-compose.yml | 8 +-
tests/plugin/sw_django/test_django.py | 35 ++++-----
tests/plugin/sw_elasticsearch/docker-compose.yml | 4 +-
.../plugin/sw_elasticsearch/test_elasticsearch.py | 31 ++++----
tests/plugin/sw_flask/docker-compose.yml | 8 +-
tests/plugin/sw_flask/test_flask.py | 36 ++++-----
tests/plugin/sw_http/test_http.py | 22 +++---
tests/plugin/sw_http_wsgi/docker-compose.yml | 6 +-
tests/plugin/sw_http_wsgi/test_http_wsgi.py | 25 +++---
tests/plugin/sw_kafka/docker-compose.yml | 10 +--
tests/plugin/sw_kafka/test_kafka.py | 35 ++++-----
tests/plugin/sw_kubernates/services/consumer.py | 16 ++--
tests/plugin/sw_kubernates/test_kubernates.py | 31 +++-----
tests/plugin/sw_pymongo/docker-compose.yml | 8 +-
tests/plugin/sw_pymongo/test_pymongo.py | 32 ++++----
tests/plugin/sw_pymysql/docker-compose.yml | 8 +-
tests/plugin/sw_pymysql/test_pymysql.py | 35 ++++-----
tests/plugin/sw_rabbitmq/docker-compose.yml | 10 +--
tests/plugin/sw_rabbitmq/test_kafka.py | 43 ----------
.../test_rabbitmq.py} | 25 +++---
tests/plugin/sw_redis/docker-compose.yml | 8 +-
tests/plugin/sw_redis/test_redis.py | 35 ++++-----
tests/plugin/sw_requests/docker-compose.yml | 9 ++-
tests/plugin/sw_requests/test_request.py | 32 ++++----
tests/plugin/sw_tornado/docker-compose.yml | 8 +-
tests/plugin/sw_tornado/test_tornado.py | 32 ++++----
37 files changed, 352 insertions(+), 490 deletions(-)
diff --cc docs/Plugins.md
index 49d3ad8,a660d88..b55ba24
--- a/docs/Plugins.md
+++ b/docs/Plugins.md
@@@ -1,17 -1,18 +1,36 @@@
# Supported Libraries
++<<<<<<< HEAD
+Library | Plugin Name
+| :--- | :--- |
+| [http.server](https://docs.python.org/3/library/http.server.html) | `sw_http_server` |
+| [urllib.request](https://docs.python.org/3/library/urllib.request.html) | `sw_urllib_request` |
+| [requests](https://requests.readthedocs.io/en/master/) | `sw_requests` |
+| [Flask](https://flask.palletsprojects.com/en/1.1.x/) | `sw_flask` |
+| [PyMySQL](https://pymysql.readthedocs.io/en/latest/) | `sw_pymysql` |
+| [Django](https://www.djangoproject.com/) | `sw_django` |
+| [redis-py](https://github.com/andymccurdy/redis-py/) | `sw_redis` |
+| [kafka-python](https://kafka-python.readthedocs.io/en/master/) | `sw_kafka` |
+| [tornado](https://www.tornadoweb.org/en/stable/) | `sw_tornado` |
+| [pika](https://pika.readthedocs.io/en/stable/) | `sw_rabbitmq` |
+| [pymongo](https://pymongo.readthedocs.io/en/stable/) | `sw_pymongo` |
+| [elasticsearch](https://github.com/elastic/elasticsearch-py) | `sw_elasticsearch` |
- | [kubernetes](https://github.com/kubernetes-client/python) | `sw_kubernetes` |
++| [kubernetes](https://github.com/kubernetes-client/python) | `sw_kubernetes` |
++=======
+ Library | Versions | Plugin Name
+ | :--- | :--- | :--- |
+ | [http.server](https://docs.python.org/3/library/http.server.html) | Python 3.5 ~ 3.8 | `sw_http_server` |
+ | [urllib.request](https://docs.python.org/3/library/urllib.request.html) | Python 3.5 ~ 3.8 | `sw_urllib_request` |
+ | [requests](https://requests.readthedocs.io/en/master/) | >= 2.9.0 < 2.15.0, >= 2.17.0 <= 2.24.0 | `sw_requests` |
+ | [Flask](https://flask.palletsprojects.com/en/1.1.x/) | >=1.0.4 <= 1.1.2 | `sw_flask` |
+ | [PyMySQL](https://pymysql.readthedocs.io/en/latest/) | 0.10.0 | `sw_pymysql` |
+ | [Django](https://www.djangoproject.com/) | >=2.0 <= 3.1 | `sw_django` |
+ | [redis-py](https://github.com/andymccurdy/redis-py/) | 3.5.3 | `sw_redis` |
+ | [kafka-python](https://kafka-python.readthedocs.io/en/master/) | 2.0.1 | `sw_kafka` |
+ | [tornado](https://www.tornadoweb.org/en/stable/) | 6.0.4 | `sw_tornado` |
+ | [pika](https://pika.readthedocs.io/en/stable/) | 1.1.0 | `sw_rabbitmq` |
+ | [pymongo](https://pymongo.readthedocs.io/en/stable/) | 3.11.0 | `sw_pymongo` |
+ | [elasticsearch](https://github.com/elastic/elasticsearch-py) | 7.9.0 | `sw_elasticsearch` |
+
+ The column `Versions` only indicates that the versions are tested, if you found the newer versions are also supported, welcome to add the newer version into the table.
++>>>>>>> master
diff --cc requirements.txt
index fe7081e,1c3889f..7fb382b
--- a/requirements.txt
+++ b/requirements.txt
@@@ -34,5 -46,6 +46,7 @@@ urllib3==1.25.1
websocket-client==0.57.0
Werkzeug==1.0.1
wrapt==1.12.1
- elasticsearch==7.8.0
- kubernetes==11.0.0
++kubernetes==11.0.0
+ zipp==3.1.0
+ zope.event==4.4
+ zope.interface==5.1.0
diff --cc setup.py
index 67f41ca,9d34faf..8555b53
--- a/setup.py
+++ b/setup.py
@@@ -44,17 -44,7 +44,18 @@@ setup
"test": [
"testcontainers",
"pyyaml",
+ "django",
+ "flask",
+ "Werkzeug",
+ "pymysql",
+ "redis",
+ "kafka-python",
+ "tornado",
+ "pika",
+ "pymongo",
+ "elasticsearch",
+ "kubernetes"
+ "pytest",
],
},
classifiers=[
diff --cc tests/plugin/sw_kubernates/services/consumer.py
index 7a5afba,0000000..3a384b8
mode 100644,000000..100644
--- a/tests/plugin/sw_kubernates/services/consumer.py
+++ b/tests/plugin/sw_kubernates/services/consumer.py
@@@ -1,54 -1,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.
+#
+
+
+from skywalking import agent, config
++import kubernetes.config as kube_config
+
+if __name__ == '__main__':
+ config.service_name = 'consumer'
+ config.logging_level = 'DEBUG'
+ agent.start()
+
+ from flask import Flask, jsonify
+ from kubernetes import client
+
+ app = Flask(__name__)
+
- k8s_server = ""
- k8s_token = ""
-
- configuration = client.Configuration()
- configuration.host = k8s_server
- configuration.verify_ssl = False
- configuration.api_key = {"authorization": "Bearer " + k8s_token}
- connection = client.api_client.ApiClient(configuration=configuration)
- core_conn = client.CoreV1Api(connection)
- apps_conn = client.AppsV1Api(connection)
- net_conn = client.NetworkingV1beta1Api(connection)
++ kube_config.load_kube_config()
++ core_conn = client.CoreV1Api()
++ apps_conn = client.AppsV1Api()
++ net_conn = client.NetworkingV1beta1Api()
+
+
+ @app.route("/users", methods=["POST", "GET"])
+ def application():
+ core_conn.list_namespace()
+ core_conn.list_pod_for_all_namespaces()
+ apps_conn.list_deployment_for_all_namespaces()
+ net_conn.list_ingress_for_all_namespaces()
+ return jsonify({"song": "Despacito", "artist": "Luis Fonsi"})
+
+
+ PORT = 9090
+ app.run(host='0.0.0.0', port=PORT, debug=True)
diff --cc tests/plugin/sw_kubernates/test_kubernates.py
index 4fb10ae,0000000..d1f2f17
mode 100644,000000..100644
--- a/tests/plugin/sw_kubernates/test_kubernates.py
+++ b/tests/plugin/sw_kubernates/test_kubernates.py
@@@ -1,43 -1,0 +1,36 @@@
+#
+# 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
++from typing import Callable
+
++import pytest
+import requests
- from testcontainers.compose import DockerCompose
+
- from tests.plugin import BasePluginTest
++from tests.plugin.base import TestPluginBase
+
+
- 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'))
++@pytest.fixture
++def prepare():
++ # type: () -> Callable
++ return lambda *_: requests.get('http://0.0.0.0:9090/users')
+
- def test_plugin(self):
- time.sleep(10)
+
++class TestPlugin(TestPluginBase):
++ @pytest.mark.parametrize('version', [
++ 'kubernetes==11.0.0',
++ ])
++ def test_plugin(self, docker_compose, version):
+ self.validate()
-
-
-
- if __name__ == '__main__':
- unittest.main()
[skywalking-python] 05/05: add github k3s action
Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
alonelaval pushed a commit to branch kubernetes
in repository https://gitbox.apache.org/repos/asf/skywalking-python.git
commit 92678e960a4b6c88d4ba1e6ce4f67456df56be42
Author: huawei <hu...@bit-s.cn>
AuthorDate: Sun Aug 23 12:51:09 2020 +0800
add github k3s action
---
.github/workflows/build.yaml | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml
index 69d871c..bbec008 100644
--- a/.github/workflows/build.yaml
+++ b/.github/workflows/build.yaml
@@ -39,6 +39,12 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
+ - name: Setup k3s
+ run: curl -sfL https://get.k3s.io | sh -
+ - name: set kubeconfig
+ env:
+ KUBECONFIG: /etc/rancher/k3s/k3s.yaml
+ run: sudo mkdir ~/.kube && sudo cp ${KUBECONFIG} ~/.kube/config
- name: Set up dependencies
run: make setup install
- name: Lint codes