Skip to content

Commit ffa4197

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

File tree

7 files changed

+144
-31
lines changed

7 files changed

+144
-31
lines changed

.github/workflows/taos-ws-py-compatibility.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ jobs:
103103
TDENGINE_URL: localhost:6041
104104
WS_CLOUD_URL: ${{ secrets.WS_CLOUD_URL }}
105105
WS_CLOUD_TOKEN: ${{ secrets.WS_CLOUD_TOKEN }}
106+
TEST_TD_3360: "true"
106107
run: |
107108
pip3 install pytest
108109
pytest ./taos-ws-py/tests/

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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import taosws
2+
import time
3+
import os
24

35

46
def test_ws_connect():
@@ -39,6 +41,31 @@ def test_connect_invalid_user():
3941
print("-" * 40)
4042

4143

44+
def test_report_connector_info():
45+
test = os.getenv("TEST_TD_3360")
46+
if test is not None:
47+
return
48+
49+
conn1 = taosws.connect()
50+
time.sleep(2)
51+
res = conn1.query("show connections")
52+
assert any(isinstance(col, str) and "PythonWS" in col for row in res for col in row)
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 = sum(1 for row in res for col in row if isinstance(col, str) and "PythonWS" in col)
63+
assert cnt == 2
64+
65+
conn1.close()
66+
conn2.close()
67+
68+
4269
def show_env():
4370
import os
4471

@@ -56,3 +83,4 @@ def show_env():
5683
test_ws_connect()
5784
test_default_connect()
5885
test_connect_invalid_user()
86+
test_report_connector_info()

taos-ws-py/tests/test_consumer.py

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

47

58
def init_topic():
@@ -60,3 +63,38 @@ def test_comsumer():
6063

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

0 commit comments

Comments
 (0)