Skip to content

Commit a5566de

Browse files
committed
feat: report connector version info
1 parent 93d8af2 commit a5566de

File tree

6 files changed

+146
-35
lines changed

6 files changed

+146
-35
lines changed

taos-ws-py/Cargo.lock

Lines changed: 70 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

taos-ws-py/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ version = "0.17.3"
2727
features = ["extension-module", "anyhow", "chrono", "abi3-py37"]
2828

2929
[target.'cfg(windows)'.dependencies]
30-
taos = { git = "https://github.com/taosdata/taos-connector-rust.git", branch = "main", default-features = false, features = [
30+
taos = { git = "https://github.com/taosdata/taos-connector-rust.git", branch = "feat/30/TD-36924", default-features = false, features = [
3131
"optin",
3232
"ws-rustls",
3333
"ws-rustls-aws-lc-crypto-provider",
3434
] }
3535
[target.'cfg(unix)'.dependencies]
36-
taos = { git = "https://github.com/taosdata/taos-connector-rust.git", branch = "main", default-features = false, features = [
36+
taos = { git = "https://github.com/taosdata/taos-connector-rust.git", branch = "feat/30/TD-36924", default-features = false, features = [
3737
"optin",
3838
"ws-rustls",
3939
"ws-rustls-ring-crypto-provider",

taos-ws-py/src/consumer.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ impl Consumer {
150150
builder.set(key_str, value.extract::<String>()?);
151151
}
152152
}
153+
154+
builder.set("connector_info", crate::CONNECTOR_INFO);
153155
let builder = TmqBuilder::from_dsn(builder)
154156
.map_err(|err| ConsumerException::new_err(err.to_string()))?;
155157
Ok(Consumer(Some(builder.build().map_err(|err| {

taos-ws-py/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ mod consumer;
7575
mod cursor;
7676
mod field;
7777

78+
const CONNECTOR_INFO: &str = concat!("PythonWS-", env!("CARGO_PKG_VERSION"));
79+
7880
#[pyclass]
7981
struct Connection {
8082
_builder: Option<TaosBuilder>,
@@ -298,6 +300,7 @@ fn connect(dsn: Option<&str>, args: Option<&PyDict>) -> PyResult<Connection> {
298300
let dsn = dsn.unwrap_or("taosws://");
299301

300302
let mut dsn = Dsn::from_str(dsn).map_err(|err| ConnectionError::new_err(err.to_string()))?;
303+
dsn.set("connector_info", CONNECTOR_INFO);
301304

302305
if let Some(args) = args {
303306
const NONE_TAOS_CFG: &[&str] = &[

taos-ws-py/tests/test_conn.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import taosws
2+
import time
23

34

45
def test_ws_connect():
@@ -39,6 +40,36 @@ def test_connect_invalid_user():
3940
print("-" * 40)
4041

4142

43+
def test_report_connector_info():
44+
conn1 = taosws.connect()
45+
time.sleep(2)
46+
res = conn1.query("show connections")
47+
found = False
48+
for row in res:
49+
if any(isinstance(col, str) and "PythonWS" in col for col in row):
50+
found = True
51+
break
52+
assert found is True
53+
54+
conn2 = taosws.connect(
55+
user="root",
56+
password="taosdata",
57+
host="localhost",
58+
port=6041,
59+
)
60+
time.sleep(2)
61+
res = conn2.query("show connections")
62+
cnt = 0
63+
for row in res:
64+
for col in row:
65+
if isinstance(col, str) and "PythonWS" in col:
66+
cnt += 1
67+
assert cnt == 2
68+
69+
conn1.close()
70+
conn2.close()
71+
72+
4273
def show_env():
4374
import os
4475

@@ -52,7 +83,8 @@ def show_env():
5283

5384

5485
if __name__ == "__main__":
55-
show_env()
56-
test_ws_connect()
57-
test_default_connect()
58-
test_connect_invalid_user()
86+
# show_env()
87+
# test_ws_connect()
88+
# test_default_connect()
89+
# test_connect_invalid_user()
90+
test_report_connector_info()

taos-ws-py/tests/test_consumer.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from taosws import Consumer
22
import taosws
3+
import time
4+
import pytest
35

46

57
def init_topic():
@@ -60,3 +62,34 @@ def test_comsumer():
6062

6163
consumer.unsubscribe()
6264
consumer.close()
65+
66+
67+
@pytest.mark.skip
68+
def test_report_connector_info():
69+
init_topic()
70+
conn = taosws.connect()
71+
72+
def count_connections():
73+
res = conn.query("show connections")
74+
return sum(1 for row in res for col in row if isinstance(col, str) and "PythonWS" in col)
75+
76+
conf = {
77+
"group.id": "10",
78+
}
79+
consumer1 = Consumer(conf)
80+
consumer1.subscribe(["test_topic_1"])
81+
time.sleep(2)
82+
assert count_connections() == 2
83+
84+
consumer2 = Consumer(dsn="ws://localhost:6041?group.id=10")
85+
consumer2.subscribe(["test_topic_1"])
86+
time.sleep(2)
87+
assert count_connections() == 3
88+
89+
time.sleep(2)
90+
91+
consumer1.unsubscribe()
92+
consumer2.unsubscribe()
93+
consumer1.close()
94+
consumer2.close()
95+
conn.close()

0 commit comments

Comments
 (0)