Skip to content

Commit

Permalink
feat: add sw_grpc plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
tsonglew committed Nov 16, 2024
1 parent 7dd9a30 commit 3d1b57e
Show file tree
Hide file tree
Showing 20 changed files with 1,531 additions and 187 deletions.
1 change: 1 addition & 0 deletions docs/en/setup/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export SW_AGENT_YourConfiguration=YourValue
| plugin_fastapi_collect_http_params | SW_PLUGIN_FASTAPI_COLLECT_HTTP_PARAMS | <class 'bool'> | False | This config item controls that whether the FastAPI plugin should collect the parameters of the request. |
| plugin_bottle_collect_http_params | SW_PLUGIN_BOTTLE_COLLECT_HTTP_PARAMS | <class 'bool'> | False | This config item controls that whether the Bottle plugin should collect the parameters of the request. |
| plugin_celery_parameters_length | SW_PLUGIN_CELERY_PARAMETERS_LENGTH | <class 'int'> | 512 | The maximum length of `celery` functions parameters, longer than this will be truncated, 0 turns off |
| plugin_grpc_ignore_method | SW_PLUGIN_GRPC_IGNORE_METHOD | <class 'str'> | | Comma-delimited list of grpc methods to ignore |
### Sampling Configurations
| Configuration | Environment Variable | Type | Default Value | Description |
| :------------ | :------------ | :------------ | :------------ | :------------ |
Expand Down
1 change: 1 addition & 0 deletions docs/en/setup/Plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ or a limitation of SkyWalking auto-instrumentation (welcome to contribute!)
| [hug](https://falcon.readthedocs.io/en/stable/) | Python >=3.11 - NOT SUPPORTED YET; Python >=3.10 - ['2.5', '2.6']; Python >=3.7 - ['2.4.1', '2.5', '2.6']; | `sw_falcon` |
| [fastapi](https://fastapi.tiangolo.com) | Python >=3.7 - ['0.89.*', '0.88.*']; | `sw_fastapi` |
| [flask](https://flask.palletsprojects.com) | Python >=3.7 - ['2.0']; | `sw_flask` |
| [grpcio](https://grpc.io/docs/languages/python) | Python >=3.8 - ['1.*']; | `sw_grpc` |
| [happybase](https://happybase.readthedocs.io) | Python >=3.7 - ['1.2.0']; | `sw_happybase` |
| [http_server](https://docs.python.org/3/library/http.server.html) | Python >=3.7 - ['*']; | `sw_http_server` |
| [werkzeug](https://werkzeug.palletsprojects.com/) | Python >=3.7 - ['1.0.1', '2.0']; | `sw_http_server` |
Expand Down
366 changes: 183 additions & 183 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ httpx = "^0.23.3"
confluent-kafka = "^2.0.2"
neo4j = "^5.9.0"
pulsar-client = "3.3.0"
grpcio = "^1.49.1"

[tool.poetry.group.lint.dependencies]
pylint = '2.13.9'
Expand Down
3 changes: 2 additions & 1 deletion skywalking/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class Component(Enum):
AIORedis = 7017
Websockets = 7018
HTTPX = 7019
Grpc = 23


class Layer(Enum):
Expand Down Expand Up @@ -89,6 +90,6 @@ def is_exit(self):

class Log(object):

def __init__(self, timestamp: time = time.time(), items: List[LogItem] = None): # noqa
def __init__(self, timestamp: time = time.time(), items: List[LogItem] = None): # noqa
self.timestamp = timestamp
self.items = items or []
11 changes: 10 additions & 1 deletion skywalking/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

RE_IGNORE_PATH: Pattern = re.compile('^$')
RE_HTTP_IGNORE_METHOD: Pattern = RE_IGNORE_PATH
RE_GRPC_IGNORE_METHOD: Pattern = RE_IGNORE_PATH

options = None # here to include 'options' in globals
options = globals().copy()
Expand Down Expand Up @@ -212,6 +213,8 @@
plugin_bottle_collect_http_params: bool = os.getenv('SW_PLUGIN_BOTTLE_COLLECT_HTTP_PARAMS', '').lower() == 'true'
# The maximum length of `celery` functions parameters, longer than this will be truncated, 0 turns off
plugin_celery_parameters_length: int = int(os.getenv('SW_PLUGIN_CELERY_PARAMETERS_LENGTH', '512'))
# Comma-delimited list of grpc methods to ignore
plugin_grpc_ignore_method: str = os.getenv('SW_PLUGIN_GRPC_IGNORE_METHOD', '').upper()

# BEGIN: Sampling Configurations
# The number of samples to take in every 3 seconds, 0 turns off
Expand Down Expand Up @@ -284,6 +287,7 @@ def finalize_regex() -> None:
reesc = re.compile(r'([.*+?^=!:${}()|\[\]\\])')
suffix = r'^.+(?:' + '|'.join(reesc.sub(r'\\\1', s.strip()) for s in agent_ignore_suffix.split(',')) + ')$'
method = r'^' + '|'.join(s.strip() for s in plugin_http_ignore_method.split(',')) + '$'
grpc_method = r'^' + '|'.join(s.strip() for s in plugin_grpc_ignore_method.split(',')) + '$'
path = '^(?:' + \
'|'.join( # replaces ","
'/(?:[^/]*/)*'.join( # replaces "/**/"
Expand All @@ -297,15 +301,20 @@ def finalize_regex() -> None:
) for p0 in agent_trace_ignore_path.split(',')
) + ')$'

global RE_IGNORE_PATH, RE_HTTP_IGNORE_METHOD
global RE_IGNORE_PATH, RE_HTTP_IGNORE_METHOD, RE_GRPC_IGNORE_METHOD
RE_IGNORE_PATH = re.compile(f'{suffix}|{path}')
RE_HTTP_IGNORE_METHOD = re.compile(method, re.IGNORECASE)
RE_GRPC_IGNORE_METHOD = re.compile(grpc_method, re.IGNORECASE)


def ignore_http_method_check(method: str):
return RE_HTTP_IGNORE_METHOD.match(method)


def ignore_grpc_method_check(method: str):
return RE_GRPC_IGNORE_METHOD.match(method)


def finalize() -> None:
"""
invokes finalizers
Expand Down
2 changes: 1 addition & 1 deletion skywalking/meter/pvm/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ def register(self):
for name in dir(self):
if name.endswith('generator'):
generator = getattr(self, name)()
Gauge.Builder('instance_pvm_' + name[:-10], generator).build()
Gauge.Builder(f'instance_pvm_{name[:-10]}', generator).build()
Loading

0 comments on commit 3d1b57e

Please sign in to comment.