You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ke...@apache.org on 2020/05/05 13:38:47 UTC

[skywalking-python] branch master updated (04eb96e -> e06b221)

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

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


 discard 04eb96e  Support passing configurations via env vars and simplify the APIs
     new e06b221  Support passing configurations via env vars and simplify the APIs

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (04eb96e)
            \
             N -- N -- N   refs/heads/master (e06b221)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 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.


Summary of changes:
 skywalking/loggings/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


[skywalking-python] 01/01: Support passing configurations via env vars and simplify the APIs

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

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

commit e06b221fcdd288207904b56ca1effa78862dc63c
Author: kezhenxu94 <ke...@163.com>
AuthorDate: Tue May 5 21:37:11 2020 +0800

    Support passing configurations via env vars and simplify the APIs
---
 README.md                       | 13 ++++++++++++-
 skywalking/agent/__init__.py    |  8 +++++++-
 skywalking/config/__init__.py   |  9 +++++----
 skywalking/loggings/__init__.py |  5 ++++-
 tests/main.py                   |  2 --
 tests/test_http_plugin.py       |  4 +---
 6 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/README.md b/README.md
index b591da5..7a67e72 100644
--- a/README.md
+++ b/README.md
@@ -19,10 +19,21 @@ microservices, cloud native and container-based (Docker, Kubernetes, Mesos) arch
 from skywalking import agent, config
 
 config.init(collector='127.0.0.1:11800', service='your awesome service')
-agent.init()
 agent.start()
 ```
 
+Alternatively, you can also pass the configurations via environment variables and you don't need to call `config.init`.
+
+The supported environment variables are as follows:
+
+Environment Variable | Description | Default
+| :--- | :--- | :--- |
+| `SW_AGENT_NAME` | The name of the Python service | `Python Service Name` 
+| `SW_AGENT_INSTANCE` | The name of the Python service instance | Randomly generated
+| `SW_AGENT_COLLECTOR_BACKEND_SERVICES` | The backend OAP server address | `127.0.0.1:11800`
+| `SW_AGENT_PROTOCOL` | The protocol to communicate with the backend OAP, currently only `grpc` is supported | `grpc`
+| `SW_LOGGING_LEVEL` | The logging level | `INFO` |
+
 ## Supported Libraries
 
 There're some built-in plugins that support automatic instrumentation of Python libraries, the complete lists are as follow:
diff --git a/skywalking/agent/__init__.py b/skywalking/agent/__init__.py
index 4ef744e..ce410ad 100644
--- a/skywalking/agent/__init__.py
+++ b/skywalking/agent/__init__.py
@@ -51,9 +51,10 @@ __report_thread = Thread(name='ReportThread', target=__report, daemon=True)
 __queue = Queue(maxsize=10000)
 __finished = Event()
 __protocol = Protocol()  # type: Protocol
+__started = False
 
 
-def init():
+def __init():
     if config.protocol == 'grpc':
         from skywalking.agent.protocol.grpc import GrpcProtocol
         global __protocol
@@ -65,6 +66,11 @@ def init():
 
 
 def start():
+    global __started
+    if __started:
+        raise RuntimeError('the agent can only be started once')
+    __started = True
+    __init()
     __heartbeat_thread.start()
     __report_thread.start()
 
diff --git a/skywalking/config/__init__.py b/skywalking/config/__init__.py
index 20f7994..9910da7 100644
--- a/skywalking/config/__init__.py
+++ b/skywalking/config/__init__.py
@@ -15,12 +15,13 @@
 # limitations under the License.
 #
 
+import os
 import uuid
 
-service_name = 'Python Service Name'  # type: str
-service_instance = str(uuid.uuid1()).replace('-', '')  # type: str
-collector_address = 'localhost:11800'  # type: str
-protocol = 'grpc'  # type: str
+service_name = os.getenv('SW_AGENT_NAME') or 'Python Service Name'  # type: str
+service_instance = os.getenv('SW_AGENT_INSTANCE') or str(uuid.uuid1()).replace('-', '')  # type: str
+collector_address = os.getenv('SW_AGENT_COLLECTOR_BACKEND_SERVICES') or '127.0.0.1:11800'  # type: str
+protocol = os.getenv('SW_AGENT_PROTOCOL') or 'grpc'  # type: str
 
 
 def init(
diff --git a/skywalking/loggings/__init__.py b/skywalking/loggings/__init__.py
index afff6c3..1ba3646 100644
--- a/skywalking/loggings/__init__.py
+++ b/skywalking/loggings/__init__.py
@@ -16,10 +16,13 @@
 #
 
 import logging
+import os
+
+__logging_lever = (os.getenv('SW_LOGGING_LEVEL') or 'INFO').upper()
 
 
 def init():
     logging.basicConfig(
-        level=logging.DEBUG,
+        level=logging.getLevelName(__logging_lever),
         format='%(name)-32s [%(threadName)-15s] [%(levelname)-8s] %(message)s',
     )
diff --git a/tests/main.py b/tests/main.py
index 1ec9afe..a4735e3 100644
--- a/tests/main.py
+++ b/tests/main.py
@@ -22,8 +22,6 @@ from skywalking.decorators import trace
 from skywalking.trace.context import SpanContext, get_context
 
 if __name__ == '__main__':
-    config.init(collector='127.0.0.1:11800', service='Python Service 1')
-    agent.init()
     agent.start()
     sleep(3)
 
diff --git a/tests/test_http_plugin.py b/tests/test_http_plugin.py
index b24b15b..21abea4 100644
--- a/tests/test_http_plugin.py
+++ b/tests/test_http_plugin.py
@@ -17,11 +17,9 @@
 
 from urllib import request
 
-from skywalking import agent, config
+from skywalking import agent
 
 if __name__ == '__main__':
-    config.init(collector="127.0.0.1:11800", service='Python Service 1')
-    agent.init()
     agent.start()
 
     import socketserver