Skip to content

Commit 79eff3a

Browse files
authored
Add namespace suffix to service name (#275)
1 parent 2efddcf commit 79eff3a

File tree

10 files changed

+42
-18
lines changed

10 files changed

+42
-18
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
- Fix sw_logging (log reporter) potentially throw exception leading to traceback confusion (#267)
3939
- Avoid reporting meaningless tracecontext with logs when there's no active span, UI will now show empty traceID (#272)
4040
- Fix exception handler in profile_context (#273)
41-
41+
- Add namespace suffix to service name (#275)
42+
4243
- Docs:
4344
- New documentation on how to test locally (#222)
4445
- New documentation on the newly added meter reporter feature (#240)

Makefile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ else
2525
OS := $(shell sh -c 'uname 2>/dev/null || echo Unknown')
2626
endif
2727

28+
.PHONY: env
29+
env: poetry gen
30+
poetry install
31+
poetry run pip install --upgrade pip
32+
2833
.PHONY: poetry poetry-fallback
2934
# poetry installer may not work on macOS's default python
3035
# falls back to pipx installer
@@ -58,12 +63,6 @@ install: gen-basic
5863
python3 -m pip install --upgrade pip
5964
python3 -m pip install .[all]
6065

61-
.PHONY: env
62-
env: poetry gen
63-
poetry install
64-
poetry run pip install --upgrade pip
65-
66-
6766
.PHONY: lint
6867
# flake8 configurations should go to the file setup.cfg
6968
lint: clean

docs/en/setup/Configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export SW_AGENT_YourConfiguration=YourValue
2121
| protocol | SW_AGENT_PROTOCOL | <class 'str'> | grpc | The protocol to communicate with the backend OAP, `http`, `grpc` or `kafka`, **we highly suggest using `grpc` in production as it's well optimized than `http`**. The `kafka` protocol provides an alternative way to submit data to the backend. |
2222
| service_name | SW_AGENT_SERVICE_NAME | <class 'str'> | Python Service Name | The name of your awesome Python service |
2323
| service_instance | SW_AGENT_SERVICE_INSTANCE | <class 'str'> | str(uuid.uuid1()).replace('-', '') | The name of this particular awesome Python service instance |
24-
| namespace | SW_AGENT_NAMESPACE | <class 'str'> | | The agent namespace of the Python service (available as tag) |
24+
| namespace | SW_AGENT_NAMESPACE | <class 'str'> | | The agent namespace of the Python service (available as tag and the suffix of service name) |
2525
| kafka_bootstrap_servers | SW_AGENT_KAFKA_BOOTSTRAP_SERVERS | <class 'str'> | localhost:9092 | A list of host/port pairs to use for establishing the initial connection to your Kafka cluster. It is in the form of host1:port1,host2:port2,... (used for Kafka reporter protocol) |
2626
| kafka_topic_management | SW_AGENT_KAFKA_TOPIC_MANAGEMENT | <class 'str'> | skywalking-managements | Specifying Kafka topic name for service instance reporting and registering, this should be in sync with OAP |
2727
| kafka_topic_segment | SW_AGENT_KAFKA_TOPIC_SEGMENT | <class 'str'> | skywalking-segments | Specifying Kafka topic name for Tracing data, this should be in sync with OAP |

skywalking/config.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
service_name: str = os.getenv('SW_AGENT_SERVICE_NAME', 'Python Service Name')
5555
# The name of this particular awesome Python service instance
5656
service_instance: str = os.getenv('SW_AGENT_SERVICE_INSTANCE', str(uuid.uuid1()).replace('-', ''))
57-
# The agent namespace of the Python service (available as tag)
57+
# The agent namespace of the Python service (available as tag and the suffix of service name)
5858
namespace: str = os.getenv('SW_AGENT_NAMESPACE', '')
5959
# A list of host/port pairs to use for establishing the initial connection to your Kafka cluster.
6060
# It is in the form of host1:port1,host2:port2,... (used for Kafka reporter protocol)
@@ -218,7 +218,22 @@ def init(**kwargs) -> None:
218218
glob[key] = val
219219

220220

221-
def finalize():
221+
def finalize_name() -> None:
222+
"""
223+
This function concatenates the serviceName according to
224+
Java agent's implementation.
225+
TODO: add kafka namespace prefix and cluster concept
226+
Ref https://github.com/apache/skywalking-java/pull/123
227+
"""
228+
global service_name
229+
if namespace:
230+
service_name = f'{service_name}|{namespace}'
231+
232+
233+
def finalize_regex() -> None:
234+
"""
235+
Build path matchers based on user provided regex expressions
236+
"""
222237
reesc = re.compile(r'([.*+?^=!:${}()|\[\]\\])')
223238
suffix = r'^.+(?:' + '|'.join(reesc.sub(r'\\\1', s.strip()) for s in ignore_suffix.split(',')) + ')$'
224239
method = r'^' + '|'.join(s.strip() for s in http_ignore_method.split(',')) + '$'
@@ -242,3 +257,11 @@ def finalize():
242257

243258
def ignore_http_method_check(method: str):
244259
return RE_HTTP_IGNORE_METHOD.match(method)
260+
261+
262+
def finalize() -> None:
263+
"""
264+
invokes finalizers
265+
"""
266+
finalize_regex()
267+
finalize_name()

tests/e2e/base/docker-compose.base.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ services:
6565
environment:
6666
SW_AGENT_SERVICE_NAME: e2e-service-consumer
6767
SW_AGENT_SERVICE_INSTANCE: consumer1
68+
SW_AGENT_NAMESPACE: namespace
6869
SW_AGENT_LOGGING_LEVEL: DEBUG
6970
healthcheck:
7071
test: [ "CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/9090" ]

tests/e2e/case/expected/service.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
layers:
2121
- GENERAL
2222
group: ""
23-
- id: {{ b64enc "e2e-service-consumer" }}.1
24-
name: e2e-service-consumer
25-
shortname: e2e-service-consumer
23+
- id: {{ b64enc "e2e-service-consumer|namespace" }}.1
24+
name: "e2e-service-consumer|namespace"
25+
shortname: "e2e-service-consumer|namespace"
2626
normal: true
2727
layers:
2828
- GENERAL

tests/e2e/case/expected/trace-artist-detail.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ spans:
2020
spanid: {{ .spanid }}
2121
parentspanid: {{ .parentspanid }}
2222
refs: []
23-
servicecode: e2e-service-consumer
23+
servicecode: "e2e-service-consumer|namespace"
2424
serviceinstancename: consumer1
2525
starttime: {{ gt .starttime 0 }}
2626
endtime: {{ gt .endtime 0 }}
@@ -46,7 +46,7 @@ spans:
4646
spanid: {{ .spanid }}
4747
parentspanid: {{ .parentspanid }}
4848
refs: []
49-
servicecode: e2e-service-consumer
49+
servicecode: "e2e-service-consumer|namespace"
5050
serviceinstancename: consumer1
5151
starttime: {{ gt .starttime 0 }}
5252
endtime: {{ gt .endtime 0 }}

tests/e2e/case/grpc/e2e.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ verify:
7272
# trace detail
7373
- query: |
7474
swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql trace $( \
75-
swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql trace ls --service-name=e2e-service-consumer\
75+
swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql trace ls --service-name="e2e-service-consumer|namespace" \
7676
| yq e '.traces | select(.[].endpointnames[0]=="/artist") | .[0].traceids[0]' -
7777
)
7878
expected: ../expected/trace-artist-detail.yml

tests/e2e/case/http/e2e.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ verify:
7272
# trace detail
7373
- query: |
7474
swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql trace $( \
75-
swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql trace ls --service-name=e2e-service-consumer\
75+
swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql trace ls --service-name="e2e-service-consumer|namespace"\
7676
| yq e '.traces | select(.[].endpointnames[0]=="/artist") | .[0].traceids[0]' -
7777
)
7878
expected: ../expected/trace-artist-detail.yml

tests/e2e/case/kafka/e2e.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ verify:
7272
# trace detail
7373
- query: |
7474
swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql trace $( \
75-
swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql trace ls --service-name=e2e-service-consumer\
75+
swctl --display yaml --base-url=http://${oap_host}:${oap_12800}/graphql trace ls --service-name="e2e-service-consumer|namespace"\
7676
| yq e '.traces | select(.[].endpointnames[0]=="/artist") | .[0].traceids[0]' -
7777
)
7878
expected: ../expected/trace-artist-detail.yml

0 commit comments

Comments
 (0)