Skip to content

Commit e0c97ba

Browse files
authored
Add kafka prefix to kakfa topic names (#277)
1 parent 79eff3a commit e0c97ba

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- Add Greenlet profiler (#246)
1818
- Add test and support for Python Slim base images (#249)
1919
- Add support for the tags of Virtual Cache for Redis (#263)
20+
- Add a new configuration `kafka_namespace` to prefix the kafka topic names (#277)
2021

2122
- Plugins:
2223
- Add aioredis, aiormq, amqp, asyncpg, aio-pika, kombu RMQ plugins (#230 Missing test coverage)

docs/en/setup/Configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export SW_AGENT_YourConfiguration=YourValue
2323
| service_instance | SW_AGENT_SERVICE_INSTANCE | <class 'str'> | str(uuid.uuid1()).replace('-', '') | The name of this particular awesome Python service instance |
2424
| 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) |
26+
| kafka_namespace | SW_AGENT_KAFKA_NAMESPACE | <class 'str'> | | The kafka namespace specified by OAP side SW_NAMESPACE, prepends the following kafka topic names with a `-`. |
2627
| 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 |
2728
| 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 |
2829
| kafka_topic_log | SW_AGENT_KAFKA_TOPIC_LOG | <class 'str'> | skywalking-logs | Specifying Kafka topic name for Log data, this should be in sync with OAP |

skywalking/config.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
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)
6161
kafka_bootstrap_servers: str = os.getenv('SW_AGENT_KAFKA_BOOTSTRAP_SERVERS', 'localhost:9092')
62+
# The kafka namespace specified by OAP side SW_NAMESPACE, prepends the following kafka topic names with a `-`.
63+
kafka_namespace: str = os.getenv('SW_AGENT_KAFKA_NAMESPACE', '')
6264
# Specifying Kafka topic name for service instance reporting and registering, this should be in sync with OAP
6365
kafka_topic_management: str = os.getenv('SW_AGENT_KAFKA_TOPIC_MANAGEMENT', 'skywalking-managements')
6466
# Specifying Kafka topic name for Tracing data, this should be in sync with OAP
@@ -222,13 +224,20 @@ def finalize_name() -> None:
222224
"""
223225
This function concatenates the serviceName according to
224226
Java agent's implementation.
225-
TODO: add kafka namespace prefix and cluster concept
227+
TODO: add cluster concept
226228
Ref https://github.com/apache/skywalking-java/pull/123
227229
"""
228230
global service_name
229231
if namespace:
230232
service_name = f'{service_name}|{namespace}'
231233

234+
global kafka_topic_management, kafka_topic_meter, kafka_topic_log, kafka_topic_segment
235+
if kafka_namespace:
236+
kafka_topic_management = f'{kafka_namespace}-{kafka_topic_management}'
237+
kafka_topic_meter = f'{kafka_namespace}-{kafka_topic_meter}'
238+
kafka_topic_log = f'{kafka_namespace}-{kafka_topic_log}'
239+
kafka_topic_segment = f'{kafka_namespace}-{kafka_topic_segment}'
240+
232241

233242
def finalize_regex() -> None:
234243
"""

tests/e2e/case/kafka/docker-compose.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ services:
8181
SW_KAFKA_FETCHER_SERVERS: broker-a:9092,broker-b:9092
8282
SW_KAFKA_FETCHER_PARTITIONS: 2
8383
SW_KAFKA_FETCHER_PARTITIONS_FACTOR: 1
84+
SW_NAMESPACE: 'e2e'
8485
depends_on:
8586
broker-a:
8687
condition: service_healthy
@@ -99,7 +100,7 @@ services:
99100
SW_AGENT_COLLECTOR_ADDRESS: oap:11800
100101
SW_AGENT_PROTOCOL: kafka
101102
SW_AGENT_KAFKA_BOOTSTRAP_SERVERS: broker-a:9092,broker-b:9092
102-
103+
SW_AGENT_KAFKA_NAMESPACE: 'e2e'
103104
depends_on:
104105
oap:
105106
condition: service_healthy
@@ -112,6 +113,7 @@ services:
112113
SW_AGENT_COLLECTOR_ADDRESS: oap:11800
113114
SW_AGENT_PROTOCOL: kafka
114115
SW_AGENT_KAFKA_BOOTSTRAP_SERVERS: broker-a:9092,broker-b:9092
116+
SW_AGENT_KAFKA_NAMESPACE: 'e2e'
115117
ports:
116118
- "9090"
117119
depends_on:

0 commit comments

Comments
 (0)