Skip to content

Commit 86b9aaf

Browse files
authored
feat: report connector version information (#102)
Add connector version reporting to TDengine Node.js WebSocket connector. Key changes: - Added ConnectorInfo constant with version format: nodejs-ws-v{version}-ncid000 - Integrated version reporting in SQL and TMQ connection paths - Added tests to verify connector info in 'show connections' output - Version bump to 3.2.3 - Enabled resolveJsonModule in TypeScript config The connector version is now visible when querying 'show connections', improving observability and debugging capabilities.
1 parent 460837f commit 86b9aaf

13 files changed

Lines changed: 64 additions & 7 deletions

File tree

.github/workflows/compatibility.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ jobs:
5151
TDENGINE_CLOUD_TOKEN: ${{ secrets.TDENGINE_CLOUD_TOKEN }}
5252
TDENGINE_TEST_USERNAME: ${{ secrets.TDENGINE_TEST_USERNAME }}
5353
TDENGINE_TEST_PASSWORD: ${{ secrets.TDENGINE_TEST_PASSWORD }}
54+
TEST_3360: true
5455
run: |
5556
npm install
5657
npm list

nodejs/package-lock.json

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

nodejs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tdengine/websocket",
3-
"version": "3.2.2",
3+
"version": "3.2.3",
44
"description": "The websocket Node.js connector for TDengine. TDengine versions 3.3.2.0 and above are recommended to use this connector.",
55
"source": "index.ts",
66
"main": "lib/index.js",

nodejs/prepare.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const path = require("path");
44
const { resolve, parse } = path;
55

66
const tsFile = /\/src\/.*.ts$/;
7+
78
async function dir(folder, ts = []) {
89
let files = await readdir(folder);
910
for (let f of files) {

nodejs/src/client/wsClient.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { ReqId } from "../common/reqid";
1212
import logger from "../common/log";
1313
import { safeDecodeURIComponent, compareVersions, maskSensitiveForLog, maskUrlForLog } from "../common/utils";
1414
import { w3cwebsocket } from "websocket";
15-
import { TSDB_OPTION_CONNECTION } from "../common/constant";
15+
import { ConnectorInfo, TSDB_OPTION_CONNECTION } from "../common/constant";
1616

1717
export class WsClient {
1818
private _wsConnector?: WebSocketConnector;
@@ -44,6 +44,7 @@ export class WsClient {
4444
user: safeDecodeURIComponent(this._url.username),
4545
password: safeDecodeURIComponent(this._url.password),
4646
db: database,
47+
connector: ConnectorInfo,
4748
...(this._timezone && { tz: this._timezone }),
4849
...(this._bearerToken && { bearer_token: this._bearerToken }),
4950
},

nodejs/src/common/constant.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import pkg from "../../package.json";
2+
13
export interface IndexableString {
24
[index: number]: string;
35
}
@@ -10,6 +12,7 @@ export interface NumberIndexable {
1012
[index: number]: number;
1113
}
1214

15+
export const ConnectorInfo = `nodejs-ws-v${pkg.version}-ncid000`;
1316
export const BinaryQueryMessage: bigint = BigInt(6);
1417
export const FetchRawBlockMessage: bigint = BigInt(7);
1518
export const MinStmt2Version: string = "3.3.6.0";

nodejs/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ let setLogLevel = (level: string) => {
2929
let destroy = () => {
3030
WebSocketConnectionPool.instance().destroyed();
3131
};
32+
3233
export { sqlConnect, tmqConnect, setLogLevel, destroy };

nodejs/src/tmq/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export class TmqConfig {
6161
} else {
6262
this.user = this.url.username;
6363
}
64+
6465
if (this.password) {
6566
this.url.password = this.password;
6667
} else {

nodejs/src/tmq/wsTmq.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { ReqId } from "../common/reqid";
2323
import logger from "../common/log";
2424
import { WSFetchBlockResponse } from "../client/wsResponse";
2525
import { maskTmqConfigForLog, maskUrlForLog } from "../common/utils";
26+
import { ConnectorInfo } from "../common/constant";
2627

2728
export class WsConsumer {
2829
private _wsClient: WsClient;
@@ -109,6 +110,7 @@ export class WsConsumer {
109110
auto_commit: String(this._wsConfig.auto_commit),
110111
auto_commit_interval_ms: String(this._wsConfig.auto_commit_interval_ms),
111112
config: Object.fromEntries(this._wsConfig.otherConfigs),
113+
connector: ConnectorInfo,
112114
},
113115
};
114116
this._topics = topics;

nodejs/test/bulkPulling/sql.test.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { WebSocketConnectionPool } from "../../src/client/wsConnectorPool";
22
import { WSConfig } from "../../src/common/config";
33
import { WsSql } from "../../src/sql/wsSql";
4-
import { Sleep, testPassword, testUsername, testEnterprise } from "../utils";
4+
import { Sleep, testPassword, testUsername, testEnterprise, testNon3360 } from "../utils";
55
import { setLevel } from "../../src/common/log";
66

77
let dsn = "ws://localhost:6041";
@@ -326,6 +326,26 @@ describe("TDWebSocket.WsSql()", () => {
326326
message: expect.stringMatching(/invalid url/i),
327327
});
328328
});
329+
330+
testNon3360("connector version info", async () => {
331+
const conf = new WSConfig(dsn);
332+
conf.setUser(testUsername());
333+
conf.setPwd(testPassword());
334+
const wsSql = await WsSql.open(conf);
335+
await Sleep(2000);
336+
const wsRows = await wsSql.query("show connections");
337+
let hasNodejsWs = false;
338+
while (await wsRows.next()) {
339+
const data = wsRows.getData();
340+
if (Array.isArray(data) && data.some(v => typeof v === "string" && v.includes("nodejs-ws"))) {
341+
hasNodejsWs = true;
342+
break;
343+
}
344+
}
345+
expect(hasNodejsWs).toBe(true);
346+
await wsRows.close();
347+
await wsSql.close();
348+
});
329349
});
330350

331351
afterAll(async () => {

0 commit comments

Comments
 (0)